NSLS-II-CSX / csxtools

Useful python tools for CSX (23-ID)
http://nsls-ii-csx.github.io/csxtools
Other
4 stars 13 forks source link

Cannot specify more than one dark image in get_fastccd_images #60

Closed mpmdean closed 5 years ago

mpmdean commented 6 years ago

The current srv1 kernal on CSX cannot specify more than one dark image in get_fastccd_images

` from databroker import DataBroker as db from csxtools.utils import get_fastccd_images

old_scan_no = 85528 slicerator = get_fastccd_images(db[old_scan_no], (db[old_scan_no-1, old_scan_no+1], None, None)) `

Throws an error

AttributeError Traceback (most recent call last) in () 3 4 old_scan_no = 85528 ----> 5 slicerator = get_fastccd_images(db[old_scan_no], (db[old_scan_no-1, old_scan_no+1], None, None))

/opt/conda_envs/analysis-2018-1.0/lib/python3.6/site-packages/csxtools/utils.py in get_fastccd_images(light_header, dark_headers, flat, gain, tag, roi) 85 # Get the images 86 ---> 87 bgnd_events = _get_images(d, tag, roi) 88 89 # We assume that all images are for the background

/opt/conda_envs/analysis-2018-1.0/lib/python3.6/site-packages/csxtools/utils.py in _get_images(header, tag, roi) 179 def _get_images(header, tag, roi=None): 180 t = ttime.time() --> 181 images = header.db.get_images(header, tag) 182 t = ttime.time() - t 183 logger.info("Took %.3f seconds to read data using get_images", t)

AttributeError: 'list' object has no attribute 'db'

I believe this comes from this change:

-def _get_images(header, tag, roi=None, handler_override=None): +def _get_images(header, tag, roi=None): t = ttime.time()

stuartcampbell commented 6 years ago

@licode Can you have a look into this ?

licode commented 6 years ago

sure, I am on this.

licode commented 6 years ago

I think this should work

slicerator = get_fastccd_images(db[old_scan_no], (db[old_scan_no-1,old_scan_no+1]))

(db[old_scan_no-1,old_scan_no+1], None, None) is not 1d tuple.

mpmdean commented 6 years ago

Since the notebook server is down, I can't check, but from inspecting the code isn't the problem that the code assumes that the first element of the tuple is a header object?

When called in either of our examples it tried to access {1st element of tuple}.table()

db[old_scan_no-1,old_scan_no+1] returns a list and the code fails because it tries to access the .table() method on this list?

licode commented 6 years ago

yep. This is exactly what error complains about.

AttributeError: 'list' object has no attribute 'db'
mpmdean commented 6 years ago

I think we're in agreement. The code was changed from using the get_table function imported at the start of the module to access the same functionality via the .table() attribute of the input object.

Maybe there are some speed or other reasons for this? If not, my instinct would be to put it back as it was?

licode commented 6 years ago

This is the feature provided in new databroker. We will use header.db.get_images, header.db.get_table, instead of importing at the beginning. The reason is we will have multiple db later, i.e., different db links to different mongo back end. hdr.db provides an easy way to sort out this requirements.

Here is the new doc. http://nsls-ii.github.io/databroker/tutorial.html

mpmdean commented 6 years ago

That sounds like a reasonable way to do it. So should the CSX tool fix would be some try: except: ArributeError blocks to handle either a single dark image or multiple dark images? This functionality was previously in the imported function.

licode commented 6 years ago

sounds good. hdr.db.get_images should work with multiple headers, because nothing changed in db.get_images, we just linked it back to hdr. We only need a quick fix in csxtools. I am working a PR on this.

licode commented 6 years ago

This should be fixed on https://github.com/NSLS-II-CSX/csxtools/pull/61

ambarb commented 5 years ago

Tested /opt/conda_envs/analysis-2018-2.1) csxtools: '0.1.13'

tested before debian 7 upgrade to 8 and it still seemed problematic.

tested this week after debian upgrade to 8 on all 3 servers and not this functionality appears to work without issue.