Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercise on new db #114

Open
dleshchev opened this issue Aug 4, 2020 · 1 comment
Open

Exercise on new db #114

dleshchev opened this issue Aug 4, 2020 · 1 comment

Comments

@dleshchev
Copy link
Contributor

dleshchev commented Aug 4, 2020

today's exercise:

  • Generate a 'start' document with some metadata about a spectrum, an 'event' document with the spectrum, and the other required documents.
  • Insert them into a development, disposable MongoDB database (mongodb://xf08id-ca1:27017/dev_analyzed_data).
  • Access the saved metadata and data (as xarray.Dataset).
  • Search for the saved spectra based on recency, element metadata, and E0 metadata.

The following needs to be wrapped into an easy-to-use function:

from event_model import compose_run
compose_run()
compose_run?
bundle = compose_run(metadata={'Sample_name': 'Pt', 'compound': 'Pt', 'Element' : 'Pt', 'Edge' : 'L3', 'E0': 11564})
bundle
bundle.start_doc
from suitcase.mongo_normalized import Serializer
ser = Serializer('mongodb://xf08id-ca1:27017/dev_analyzed_data', 'mongodb://xf08id-ca1:27017/dev_analyzed_data')
ser
ser('start', bundle.start_doc)
bundle.compose_descriptor(data_keys={'Energy' : {'dtype' : 'array', 'source' : '', 'shape' : [-1]},''})
bundle.compose_descriptor(data_keys={'Energy' : {'dtype' : 'array', 'source' : '', 'shape' : [-1]}, 'mu_norm' : {'dtype' : 'array', 'source' : '', 'shape' : [-1]}})
bundle2 = bundle.compose_descriptor(data_keys={'Energy' : {'dtype' : 'array', 'source' : '', 'shape' : [-1]}, 'mu_norm' : {'dtype' : 'array', 'source' : '', 'shape' : [-1]}}, name='primary')
bundle2
ser('descriptor', bundle2.descriptor_doc)
bundle2.compose_event(data={'Energy' : [1,2,3], 'mu_norm' : [0.1, 0.2, 0.3]}, timestamps={'Energy':0, 'mu_norm' : 0})
ser('event', _22)
bundle.compose_stop()
ser('stop', _24)
from databroker._drivers.mongo_normalized import BlueskyMongoCatalog
uri = "mongodb://xf08id-ca1:27017/dev_analyzed_data"
catalog = BlueskyMongoCatalog(uri, uri)
catalog
catalog[-1]
catalog[-1].primary
catalog[-1].primary.read()
len(catalog.search({'Element':'Pt'}))
len(catalog.search({'Element':'Co'}))
catalog[-1].metadata
len(catalog.search({'E0':{'$lt' : 10000}}))
len(catalog.search({'E0':{'$gt' : 10000}}))
@danielballan
Copy link
Contributor

danielballan commented Aug 4, 2020

TO DO:

  • Wrap this in high-level API like a save_spectrum function.
  • Include references to upstream UIDs (like parents: [...])
  • Update schemas in Add spectrum schema. #113. We actually need two separate schemas: for the start doc (requiring E0, element, etc.) and the descriptor doc (requiring Energy, mu_norm).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants