diff --git a/startup/02-data_security.py b/startup/02-data_security.py deleted file mode 100644 index 0e2fd08..0000000 --- a/startup/02-data_security.py +++ /dev/null @@ -1,12 +0,0 @@ -# To be deleted when DS is done - -RE.md.pop('experiment_alias_directory', None) -RE.md.pop('experiment_user', None) -RE.md.pop('experiment_SAF_number', None) -RE.md.pop('experiment_proposal_number', None) -RE.md.pop('experiment_project', None) -RE.md.pop('experiment_group', None) -RE.md.pop('experiment_cycle', None) -RE.md.pop('userpy_alias_directory', None) - -# RE.md["experiment_alias_directory"] = "data_security_test" #NOTE TO SELF: Don't forget to delete this \ No newline at end of file diff --git a/startup/02-tiled-writer.py b/startup/02-tiled-writer.py new file mode 100644 index 0000000..6d056fd --- /dev/null +++ b/startup/02-tiled-writer.py @@ -0,0 +1,105 @@ +import numpy +import os + +from bluesky_tiled_plugins import TiledWriter +from bluesky.callbacks.buffer import BufferingWrapper +from tiled.client import from_uri + + +# Mapping from spec to mimetype for use in TiledWriter +# TODO: Only keep the necessary specs here +MIMETYPE_LOOKUP = { + "AD_TIFF": "multipart/related;type=image/tiff", + + "hdf5": "application/x-hdf5", + "A1_HDF5": "application/x-hdf5", # esm_patches:A1SoftFileHandler(HDF5DatasetSliceHandler) + "AD_CBF": "multipart/related;type=image/tiff", + "AD_EIGER_MX": "application/x-hdf5", + "AD_EIGER2": "application/x-hdf5", + "AD_JPEG": "multipart/related;type=image/jpeg", + "AD_HDF5": "application/x-hdf5", + "AD_HDF5_GERM": "application/x-hdf5", + "AD_HDF5_SWMR_STREAM": "application/x-hdf5", + "AD_HDF5_SWMR_SLICE": "application/x-hdf5", + "AD_HDF5_SWMR": "application/x-hdf5", + "AD_HDF5_TS": "application/x-hdf5", # area_detector_handlers.handlers:AreaDetectorHDF5TimestampHandler + "AD_HDF5_DET_TS": "application/x-hdf5", # csx_transforms.AreaDetectorHDF5NDArrayTimeStampHandler + "APB": "application/x-pizzabox-binary", # columns: timestamp, i0, it, ir, iff, aux1, aux2, aux3, aux4. iss_patches:APBBinFileHandler + "APB_TRIGGER": "application/x-pizzabox-binary", # columns: timestamp, transition, iss_patches:APBTriggerFileHandler + "DEX_HDF5": "application/x-hdf5", + "EIGER2_STREAM": "application/x-hdf5", + "MERLIN_FLY_STREAM_V2": "application/x-hdf5", + "MERLIN_HDF5_BULK": "application/x-hdf5", + "PANDA": "application/x-hdf5", + "PIL100k_HDF5": "application/x-hdf5", # iss_patches:ISSPilatusHDF5Handler + "PILATUS_HDF5": "application/x-hdf5", + "ROI_HDF5_FLY": "application/x-hdf5", + "ROI_HDF51_FLY": "application/x-hdf5", + "SIS_HDF51_FLY_STREAM_V1": "application/x-hdf5", + "TPX_HDF5": "application/x-hdf5", + "NPY_SEQ": "multipart/related;type=application/x-npy", + "SIS_HDF51": "application/x-hdf5", + "SPECS_HDF5_SINGLE_DATAFRAME": "application/x-hdf5", # IOS + "XIA_XMAP_HDF5": "application/x-hdf5;type=xia-xmap", + "XSP3": "application/x-hdf5", # iss_patches:ISSXspress3HDF5Handler, area_detector_handlers.handlers:Xspress3HDF5Handler + "XSP3_BULK": "application/x-hdf5", + "XSP3_FLY": "application/x-hdf5", + "XSP3_STEP": "application/x-hdf5", # databroker.assets.handlers:Xspress3HDF5Handler, area_detector_handlers.handlers:Xspress3HDF5Handler + "XSP3X": "application/x-hdf5", + } + + +# Define document-specific patches to be applied before sending them to TiledWriter +def patch_resource(doc): + + kwargs = doc.get("resource_kwargs", {}) + + # Fix the resource path + root = doc.get("root", "") + if not doc["resource_path"].startswith(root): + doc["resource_path"] = os.path.join(root, doc["resource_path"]) + doc["root"] = "" + doc["resource_path"] = doc["resource_path"].replace("/nsls2/data3/cms", "/nsls2/data/cms") + + if doc.get("spec") in ["AD_TIFF"]: + kwargs["template"] = "/" + kwargs["template"].lstrip("/") # Ensure leading slash + kwargs["join_method"] = "stack" + + return doc + + +def patch_descriptor(doc): + if 'pilatus800_image' in doc['data_keys']: + desc = doc['data_keys']['pilatus800_image'] + desc.setdefault("dtype_str", "