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

Add support for multiple detectors in sinograms #187

Closed
wants to merge 0 commits into from

Conversation

jadball
Copy link
Contributor

@jadball jadball commented Nov 24, 2023

  • Add guess_detector() and guess_motornames() functions to sinograms/datasets.py
    These functions read the masterfile and determine whether we are using frelon3 or eiger, and what our omegamotor and dtymotor attributes should be (based on which motors are present in instrument/positioners).
    They are called just before import_scans() and import_motors_from_master() respectively, to ensure we look for the correct data.
    These functions are also called in the load() function - this is essential for sinograms/lina_segmenter.py:setup()
  • Fixes import_scans() to handle broken softlinks (via a try/except cause to catch the KeyError thrown by h5py)

With these additions and fixes, the NotesGuide notebook from the gold example will complete successfully with my frelon3 data.

Copy link
Member

@jonwright jonwright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!!!

So I have gone through reviewing here - it might be easier to do in person, but maybe it is useful to keep a log here to remember why things are being done.

The overall idea for me would be : try to make it work in the future for some other beamline I have not seen yet. So less hardwiring of ID11 config.

@@ -20,6 +20,8 @@
- indexing and reconstructing grains

"""

POSSIBLE_DETECTOR_NAMES = ("frelon3", "eiger")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just read the name from the dataset. There should be only one entry which has:

/scan/measurement/detector -> attrs[ "interpretation" ] == "image"

# "dty", "rot", "pz", "px", "py", "shtz", "shty", "shtx")
HEADERMOTORS_NSCOPE = ("dty", "rot", "pz", "px", "py", "shtz", "shty", "shtx")
HEADERMOTORS_TDXRD = ("diffty", "diffrz", "samtx", "samty", "samtz", "diffry", "samrx", "samry")
HEADERMOTORS = HEADERMOTORS_NSCOPE + HEADERMOTORS_TDXRD
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention of the single list was to take all potentially interesting names.

# open the masterfile
hname = self.masterfile
detectors_seen = []
scan = "1.1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to import the scans first. Then find the detector for each scan.


with h5py.File( hname, 'r' ) as hin:
# go through the first scan, and see what detectors we can see
for measurement in list(hin[scan]['measurement']):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for item in hin[scan]['measurement']:
if "interpretation" in item.attrs and item.attrs[ "interpretation" ] == "image":
....

if measurement in POSSIBLE_DETECTOR_NAMES:
detectors_seen.append(measurement)

if len(detectors_seen) != 1:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the detector could be an argument to init to decide which one

self.detector = detectors_seen[0]


def guess_motornames(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be seen - I think this should come from nexus style attributes or user input to scale in the future

using_tdxrd = True

if using_nscope and using_tdxrd:
raise ValueError("Found both nscope and tdxrd motors in positioners, not sure which one we were using!")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not scale

# return DataSet().load( h5name, h5group )
# make sure detector and rotation motors are known
ds_obj = DataSet().load( h5name, h5group )
ds_obj.guess_detector()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silently modifying the dataset when loading it from disk seems a bit dodgy. I prefer to have a method like validate or repair or fix that makes clear what is happening.


# it's better to determine the omegamotor, dtymotor and detector from the masterfile itself...
# however, that relies on realistic dataroot, analysisroot, etc values being passed to the init
# the default values for dataroot etc. will always give a broken masterfile path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default was downloading your data and working in the same folder as the dataset.

@@ -47,9 +51,16 @@ def __init__(self,
dset = "dataset"):
""" The things we need to know to process data """


# it's better to determine the omegamotor, dtymotor and detector from the masterfile itself...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then have:
... omegamotor = None, dtymotor=None, detector=None

if thing is None: guess_thing()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the info is supplied - the select the scan which have the motors.

Also handle the case of no dty motor.

Also handle the case of z scans vs y scans (etc, samry, samrx, diffry)

@jadball
Copy link
Contributor Author

jadball commented Nov 24, 2023

Good to discuss in person I think :)

@jonwright
Copy link
Member

Quick thought this morning - it would be good to keep your guess_detector logic in a import_from_blissfile function that is similar to import_from_sparse.

@jadball
Copy link
Contributor Author

jadball commented Nov 30, 2023

new request with changes suggested #189

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

Successfully merging this pull request may close these issues.

2 participants