def test_apply_vanadium(project_file, van_project_file, target_project_file): """Test applying vanadium to the raw data in project file Parameters ---------- project_file : str raw HiDRA project file to convert to 2theta pattern van_project_file : str raw HiDra vanadium file target_project_file : str target HiDRA Returns ------- """ # Check files' existence checkFileExists(project_file, feedback='assert') checkFileExists(van_project_file, feedback='assert') # Load data # extract the powder patterns and add them to the project file reducer = ReductionApp() # instrument_file, calibration_file, mask, sub_runs reducer.load_project_file(project_file) reducer.reduce_data(sub_runs=None, instrument_file=None, calibration_file=None, mask=None, van_file=van_project_file, num_bins=950) reducer.save_diffraction_data(target_project_file)
def test_apply_mantid_mask(): """Test auto reduction script with Mantid mask file applied Returns ------- """ # Specify NeXus nexus_file = 'data/HB2B_938.nxs.h5' # Convert the NeXus to file to a project without mask and convert to 2theta diffraction pattern no_mask_project_file = 'HB2B_938_no_mask.h5' if os.path.exists(no_mask_project_file): os.remove(no_mask_project_file) # Convert to NeXust no_mask_hidra_ws = convertNeXusToProject(nexus_file, no_mask_project_file, skippable=False, mask_file_name=None) mask_array = no_mask_hidra_ws.get_detector_mask(is_default=True) assert mask_array is None, 'There shall not be any mask' # Convert the nexus file to a project file and do the "simple" checks no_mask_reducer = ReductionApp() no_mask_reducer.load_project_file(no_mask_project_file) no_mask_reducer.reduce_data(sub_runs=None, instrument_file=None, calibration_file=None, mask=None, van_file=None, num_bins=950) no_mask_reducer.save_diffraction_data(no_mask_project_file) # Convert the NeXus to file to a project with mask and convert to 2theta diffraction pattern project_file = 'HB2B_938_mask.h5' if os.path.exists(project_file): os.remove(project_file) # Convert masked_hidra_ws = convertNeXusToProject(nexus_file, project_file, skippable=False, mask_file_name='data/HB2B_Mask_12-18-19.xml') mask_array = masked_hidra_ws.get_detector_mask(True) # check on Mask: num_masked_pixels = (135602,) assert np.where(mask_array == 0)[0].shape[0] == 135602, 'Mask shall have 135602 pixels masked but not {}' \ ''.format(np.where(mask_array == 0)[0].shape[0]) reducer = ReductionApp() reducer.load_project_file(project_file) # convert to diffraction pattern with mask reducer.reduce_data(sub_runs=None, instrument_file=None, calibration_file=None, mask=mask_array, van_file=None, num_bins=950) reducer.save_diffraction_data(project_file) # Compare range of 2theta no_mask_data_set = no_mask_reducer.get_diffraction_data(sub_run=1) masked_data_set = reducer.get_diffraction_data(sub_run=1) print('[DEBUG...] No mask 2theta range: {}, {}'.format(no_mask_data_set[0].min(), no_mask_data_set[0].max())) print('[DEBUG...] Masked 2theta range: {}, {}'.format(masked_data_set[0].min(), masked_data_set[0].max())) # verify the masked reduced data shall have smaller or at least equal range of 2theta assert no_mask_data_set[0].min() <= masked_data_set[0].min() assert no_mask_data_set[0].max() >= masked_data_set[0].max()
def addPowderToProject(projectfile, calibration_file=None): checkFileExists(projectfile, feedback='assert') # extract the powder patterns and add them to the project file reducer = ReductionApp() # TODO should add versions for testing arguments: instrument_file, calibration_file, mask, sub_runs reducer.load_project_file(projectfile) reducer.reduce_data(sub_runs=None, instrument_file=None, calibration_file=calibration_file, mask=None) reducer.save_diffraction_data(projectfile) # tests for the created file assert os.path.exists(projectfile)