diff --git a/scripts/Diffraction/isis_powder/gem_routines/gem_advanced_config.py b/scripts/Diffraction/isis_powder/gem_routines/gem_advanced_config.py index a37298079e2e85eebc10e99525a80cceea9e8063..0f1d6e7f40ee08f7519216cf6e1a9a2e21718642 100644 --- a/scripts/Diffraction/isis_powder/gem_routines/gem_advanced_config.py +++ b/scripts/Diffraction/isis_powder/gem_routines/gem_advanced_config.py @@ -14,7 +14,6 @@ absorption_correction_params = { gem_adv_config_params = { "raw_tof_cropping_values": (500, 20000), "spline_coefficient": 30 - } focused_cropping_values = [(550, 19900), # Bank 1 diff --git a/scripts/Diffraction/isis_powder/gem_routines/gem_algs.py b/scripts/Diffraction/isis_powder/gem_routines/gem_algs.py index 3e4bba06b542c30dd095951e8c2cd5723e549d00..0cca76da2c26d307fbe2c4461982b940ca34530e 100644 --- a/scripts/Diffraction/isis_powder/gem_routines/gem_algs.py +++ b/scripts/Diffraction/isis_powder/gem_routines/gem_algs.py @@ -27,6 +27,7 @@ def get_run_details(run_number_string, inst_settings): label = common.cal_map_dictionary_key_helper(cycle_map, "label") offset_file_name = common.cal_map_dictionary_key_helper(cycle_map, "offset_file_name") empty_runs = common.cal_map_dictionary_key_helper(cycle_map, "empty_run_numbers") + empty_containers_runs = common.cal_map_dictionary_key_helper(cycle_map, "empty_container_run_numbers") vanadium_runs = common.cal_map_dictionary_key_helper(cycle_map, "vanadium_run_numbers") # For GEM the grouping and offset file are identical @@ -38,8 +39,6 @@ def get_run_details(run_number_string, inst_settings): offset_file_path = os.path.join(label_calibration_folder, offset_file_name) splined_file_path = os.path.join(label_calibration_folder, splined_vanadium_name) - # TODO generate splined vanadium name from common - run_details = RunDetails.RunDetails(run_number=run_number) run_details.empty_runs = empty_runs run_details.user_input_run_number = run_number_string diff --git a/scripts/Diffraction/isis_powder/routines/RunDetails.py b/scripts/Diffraction/isis_powder/routines/RunDetails.py index b03e87ba945cb334eba7da417341362b99f84748..3b761192da5f721115999e0230ddc51a33e865f6 100644 --- a/scripts/Diffraction/isis_powder/routines/RunDetails.py +++ b/scripts/Diffraction/isis_powder/routines/RunDetails.py @@ -11,6 +11,7 @@ class RunDetails(object): self.run_number = run_number self.user_input_run_number = None + self.empty_container_runs = None self.empty_runs = None self.label = None diff --git a/scripts/Diffraction/isis_powder/routines/absorb_corrections.py b/scripts/Diffraction/isis_powder/routines/absorb_corrections.py index 4a9933e04827a45333acec99920026d0b78fa1f5..7f4dfbd8d4a0f6b44842e2ec1c65f82746d7abf5 100644 --- a/scripts/Diffraction/isis_powder/routines/absorb_corrections.py +++ b/scripts/Diffraction/isis_powder/routines/absorb_corrections.py @@ -23,6 +23,7 @@ def run_cylinder_absorb_corrections(ws_to_correct, multiple_scattering, config_d radius_key = "cylinder_sample_radius" pos_key = "cylinder_position" formula_key = "chemical_formula" + chemical_key = "chemical_properties" e_msg = "The following key was not found in the advanced configuration for sample correction:\n" @@ -31,16 +32,23 @@ def run_cylinder_absorb_corrections(ws_to_correct, multiple_scattering, config_d pos = common.dictionary_key_helper(dictionary=config_dict, key=pos_key, exception_msg=e_msg + pos_key) formula = common.dictionary_key_helper(dictionary=config_dict, key=formula_key, exception_msg=e_msg + formula_key) + chemical_properties = common.dictionary_key_helper(dictionary=config_dict, key=chemical_key, throws=False) + + position_dict = { + "cylinder_height": height, + "cylinder_radius": radius, + "cylinder_pos": pos + } ws_to_correct = _calculate__cylinder_absorb_corrections( ws_to_correct=ws_to_correct, multiple_scattering=multiple_scattering, - c_height=height, c_radius=radius, c_pos=pos, chemical_formula=formula) + position_dict=position_dict, chemical_formula=formula, material_properties=chemical_properties) return ws_to_correct def _calculate__cylinder_absorb_corrections(ws_to_correct, multiple_scattering, - c_height, c_radius, c_pos, chemical_formula): + position_dict, chemical_formula, material_properties): """ Calculates vanadium absorption corrections for the specified workspace. The workspace should have any monitor spectra masked before being passed into this method. Additionally @@ -54,9 +62,9 @@ def _calculate__cylinder_absorb_corrections(ws_to_correct, multiple_scattering, :param chemical_formula: The chemical formula of the container - usually set to 'V' for Vanadium :return: The workspace with corrections applied """ - geometry_json = {'Shape': 'Cylinder', 'Height': c_height, - 'Radius': c_radius, 'Center': c_pos} - material_json = {'ChemicalFormula': chemical_formula} + geometry_json = {'Shape': 'Cylinder', 'Height': position_dict["cylinder_height"], + 'Radius': position_dict["cylinder_radius"], 'Center': position_dict["cylinder_pos"]} + material_json = _get_material_json(chemical_formula=chemical_formula, material_properties=material_properties) mantid.SetSample(InputWorkspace=ws_to_correct, Geometry=geometry_json, Material=material_json) @@ -66,3 +74,45 @@ def _calculate__cylinder_absorb_corrections(ws_to_correct, multiple_scattering, ws_to_correct = mantid.ConvertUnits(InputWorkspace=ws_to_correct, OutputWorkspace=ws_to_correct, Target="dSpacing") return ws_to_correct + + +def _get_material_json(chemical_formula, material_properties): + """ + Returns a material JSON with either a chemical formula when using elemental chemicals + or uses user set chemical properties when required or the user has set them to generate + the required input for SetMaterial + :param chemical_formula: The formula of the chemical to use + :param material_properties: The materials properties dictionary as set by the user + :return: The material JSON for setSample with appropriate settings. + """ + material_json = {'ChemicalFormula': chemical_formula} + + is_elemental_vanadium = True if chemical_formula.lower() == 'v' else False + + # Test if we can just use built in Mantid properties + if is_elemental_vanadium and not material_properties: + return material_json + + # Else we have to parse the chemical formula specified below + err_message = "Custom properties was detected for the material but the required key was not set:\n" + + attenuation_key = "attenuation_cross_section" + scattering_key = "scattering_cross_section" + sample_density_key = "sample_number_density" + + attenuation_x_section = common.dictionary_key_helper(material_properties, attenuation_key, + exception_msg=err_message + attenuation_key) + scattering_x_section = common.dictionary_key_helper(material_properties, scattering_key, + exception_msg=err_message + scattering_key) + sample_density = common.dictionary_key_helper(material_properties, sample_density_key, + exception_msg=err_message + sample_density_key) + + material_json = {"SampleNumberDensity": sample_density, + "AttenuationXSection": attenuation_x_section, + "ScatteringXSection": scattering_x_section} + + print ("Using custom chemical properties:") + for k, v in material_json.viewitems(): + print (k, v) + + return material_json diff --git a/scripts/Diffraction/isis_powder/routines/calibrate.py b/scripts/Diffraction/isis_powder/routines/calibrate.py index 77077021941fbfd8b32d1db075265dc3076f1c05..eafce174eee6399dff5fb081372efcf480eaf015 100644 --- a/scripts/Diffraction/isis_powder/routines/calibrate.py +++ b/scripts/Diffraction/isis_powder/routines/calibrate.py @@ -21,8 +21,6 @@ def create_van(instrument, run_details, absorb): aligned_ws = mantid.AlignDetectors(InputWorkspace=corrected_van_ws, CalibrationFile=run_details.offset_file_path) - import pydevd - pydevd.settrace('localhost', port=51205, stdoutToServer=True, stderrToServer=True) if absorb: aligned_ws = _apply_absorb_corrections(instrument=instrument, run_details=run_details, van_ws=aligned_ws)