From 486f58a86e38019ac914b928142653e53c106dec Mon Sep 17 00:00:00 2001 From: David Rower Date: Thu, 23 Jan 2020 11:53:07 -0500 Subject: [PATCH] Fixed special case in get_entry_info function, adding metadata to sample in converteR --- CDTools/tools/data.py | 4 ++-- converters/NSLS2_HXN_hdf5_to_CXI.py | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CDTools/tools/data.py b/CDTools/tools/data.py index 4387bdc..0dfe6ed 100644 --- a/CDTools/tools/data.py +++ b/CDTools/tools/data.py @@ -436,9 +436,9 @@ def add_entry_info(cxi_file, metadata): elif isinstance(value, datetime.datetime): cxi_file['entry_1'][key] = np.string_(value.isoformat()) elif isinstance(value, numbers.Number): - si[key] = value + cxi_file['entry_1'][key] = value elif isinstance(value, (np.ndarray,list,tuple)): - s1.create_dataset(key, data=np.asarray(value)) + cxi_file['entry_1'].create_dataset(key, data=np.asarray(value)) elif isinstance(value, t.Tensor): asnumpy = value.detach().cpu().numpy() cxi_file['entry_1'].create_dataset(key, data=asnumpy) diff --git a/converters/NSLS2_HXN_hdf5_to_CXI.py b/converters/NSLS2_HXN_hdf5_to_CXI.py index 3a345c5..b2dca7d 100755 --- a/converters/NSLS2_HXN_hdf5_to_CXI.py +++ b/converters/NSLS2_HXN_hdf5_to_CXI.py @@ -1,4 +1,3 @@ -#!/home/david/.conda/envs/CDToolsEnv/bin/python """ Purpose: Convert NSLSII HXN hdf5 files to CXI files for analysis with CDTools. Author: David Rower @@ -15,7 +14,7 @@ from matplotlib import pyplot as plt from scipy.spatial.transform import Rotation def create_cxi_from_NSLS2_HXN_2DFly(data_dir, save_str, scan_number, - wavelength, theta, ROI_corner_xy): + wavelength, theta, ROI_corner_xy, metadata): """Converts NSLS2 HXN 2D Fly scan data (from pickle and hdf5) to CXI format Assumes scan files will live in data_dir with naming convention @@ -35,6 +34,8 @@ def create_cxi_from_NSLS2_HXN_2DFly(data_dir, save_str, scan_number, Rotation angle of sample in HXN convention, in degrees ROI_corner_xy : np.array 1x2 array containing x, y corner of detector ROI + metadata : dict + Contains metadata relevant to the experiment """ ## Load in pickle and hdf5 files @@ -54,7 +55,6 @@ def create_cxi_from_NSLS2_HXN_2DFly(data_dir, save_str, scan_number, ## Let's attempt to convert this bad boy print(80*'-'+'\nCreating cxi file.') - # We save as .h5 in order to inspect with panalopy GUI utility scan_cxi = cdtdata.create_cxi(save_str) @@ -76,6 +76,10 @@ def create_cxi_from_NSLS2_HXN_2DFly(data_dir, save_str, scan_number, } cdtdata.add_sample_info(scan_cxi, sample_info_dict) + ## Add other metadata for experiment + metadata['time'] = scan_pickle['time'] + cdtdata.add_entry_info(scan_cxi, metadata) + ## Add detector