def save_combined_panel(self, run, panel): panel_combination = {5: 6, 4: 7, 3: 8, 2: 9, 1: 10} input_ws1 = "w{0}-{1}foc".format(run, panel) input_ws2 = "w{0}-{1}foc".format(run, panel_combination.get(panel)) combined = "{0}{1}-{2}_{3}foc{4}".format("{0}", run, panel, panel_combination.get(panel), "{1}") combined_save = combined.format("", "{}") combined_ws = combined.format("w", "") simple.RebinToWorkspace(WorkspaceToRebin=input_ws2, WorkspaceToMatch=input_ws1, OutputWorkspace=input_ws2, PreserveEvents='0') simple.Plus(LHSWorkspace=input_ws1, RHSWorkspace=input_ws2, OutputWorkspace=combined_ws) simple.ConvertUnits(InputWorkspace=combined_ws, OutputWorkspace=combined_ws + "-d", Target="dSpacing", EMode="Elastic") simple.SaveGSS(combined_ws, os.path.join(self.user_directory, combined_save.format("raw.gss")), Append=False, Bank=1) simple.SaveFocusedXYE( combined_ws, os.path.join(self.user_directory, combined_save.format("raw.dat"))) simple.SaveNexusProcessed( combined_ws, os.path.join(self.user_directory, combined_save.format("raw.nxs")))
def save_focused_data(d_spacing_group, tof_group, output_paths): """ Saves out focused data into nxs, GSAS and .dat formats. Requires the grouped workspace in TOF and dSpacing and the dictionary of output paths generated by abstract_inst. :param d_spacing_group: The focused workspace group in dSpacing :param tof_group: The focused workspace group in TOF :param output_paths: A dictionary containing the full paths to save to :return: None """ def ensure_dir_exists(filename): dirname = os.path.dirname(filename) if not os.path.exists(dirname): os.makedirs(dirname) return filename mantid.SaveGSS(InputWorkspace=tof_group, Filename=ensure_dir_exists(output_paths["gss_filename"]), SplitFiles=False, Append=False) mantid.SaveNexusProcessed(InputWorkspace=tof_group, Filename=ensure_dir_exists( output_paths["nxs_filename"]), Append=False) _save_xye(ws_group=d_spacing_group, filename_template=ensure_dir_exists( output_paths["dspacing_xye_filename"])) _save_xye(ws_group=tof_group, filename_template=ensure_dir_exists( output_paths["tof_xye_filename"]))
def save_focused_data(d_spacing_group, tof_group, output_paths, run_number_string, inst_prefix, file_ext): """ Saves out focused data into nxs, GSAS and .dat formats. Requires the grouped workspace in TOF and dSpacing, the a dictionary of output paths generated by abstract_inst, the user inputted run number string and the prefix of the instrument. :param d_spacing_group: The focused workspace group in dSpacing :param tof_group: The focused workspace group in TOF :param output_paths: A dictionary containing the full paths to save to :param run_number_string: The user input run number(s) as a string to generate output name :param inst_prefix: The instrument prefix to generate output name :return: None """ mantid.SaveGSS(InputWorkspace=tof_group, Filename=output_paths["gss_filename"], SplitFiles=False, Append=False) mantid.SaveNexusProcessed(InputWorkspace=tof_group, Filename=output_paths["nxs_filename"], Append=False) dat_folder_name = "dat_files" dat_file_destination = os.path.join(output_paths["output_folder"], dat_folder_name) if not os.path.exists(dat_file_destination): os.makedirs(dat_file_destination) _save_xye(ws_group=d_spacing_group, ws_units="d", run_number=run_number_string, output_folder=dat_file_destination, inst_prefix=inst_prefix, file_ext=file_ext) _save_xye(ws_group=tof_group, ws_units="TOF", run_number=run_number_string, output_folder=dat_file_destination, inst_prefix=inst_prefix, file_ext=file_ext)
# Get fitting parameters fitPar = TubeCalibFitParams(ExpectedPositions, ExpectedHeight, ExpectedWidth) fitPar.setAutomatic(True) print("Created objects needed for calibration.") # == Get the calibration and put results into calibration table == # also put peaks into PeakFile calibrationTable, peakTable = tube.calibrate(CalibInstWS, CalibratedComponent, knownPos, funcForm, fitPar=fitPar, outputPeak=True) print("Got calibration (new positions of detectors) ") # == Apply the Calibation == mantid.ApplyCalibration(Workspace=CalibInstWS, PositionTable=calibrationTable) print("Applied calibration") # == Save workspace == mantid.SaveNexusProcessed(CalibInstWS, 'TubeCalibDemoMapsResult.nxs', "Result of Running TCDemoMaps_B1.py") print( "saved calibrated workspace (CalibInstWS) into Nexus file TubeCalibDemoMapsResult.nxs" ) # == Save Peak File == tube.savePeak(peakTable, 'TubeDemoMaps01.txt')
def process_run(self, number, panel, extension, cycle_vana="09_4", absorb=False, number_density=0.0, scattering=0.0, attenuation=0.0, height=0.0, radius=0.0): ws_to_focus = self.read(number, panel, extension) if absorb: absorption_corrections(attenuation, height, number_density, radius, scattering, ws_to_focus) focused_ws = self.focus(ws_to_focus, panel) panel_crop = { 1: (0.8, 53.3), 2: (0.5, 13.1), 3: (0.5, 7.77), 4: (0.4, 5.86), 5: (0.35, 4.99), 6: (0.35, 4.99), 7: (0.4, 5.86), 8: (0.5, 7.77), 9: (0.5, 13.1), 10: (0.8, 53.3) } d_min, d_max = panel_crop.get(panel) simple.CropWorkspace(InputWorkspace=focused_ws, OutputWorkspace=focused_ws, XMin=d_min, XMax=d_max) save_location = os.path.join(self.user_directory, "{0}-{1}{2}.{3}") if panel == 0: for panel_i in range(Wish.NUM_PANELS): focused_ws = "w{0}-{1}foc".format(number, panel_i) simple.CropWorkspace(InputWorkspace=focused_ws, OutputWorkspace=focused_ws, XMin=d_min, XMax=d_max) logger.notice( "will try to load a vanadium with the name: {}".format( self.get_vanadium(panel_i, cycle_vana))) self.apply_vanadium_corrections(cycle_vana, panel_i, focused_ws) simple.SaveGSS(InputWorkspace=focused_ws, Filename=save_location.format( number, panel_i, extension, "gss"), Append=False, Bank=1) simple.SaveFocusedXYE( focused_ws, save_location.format(number, panel_i, extension, "dat")) simple.SaveNexusProcessed( focused_ws, save_location.format(number, panel_i, extension, "nxs")) else: logger.notice( "will try to load a vanadium with the name: {}".format( self.get_vanadium(panel, cycle_vana))) self.apply_vanadium_corrections(cycle_vana, panel, focused_ws) simple.SaveGSS(InputWorkspace=focused_ws, Filename=save_location.format( number, panel, extension, "gss"), Append=False, Bank=1) simple.SaveFocusedXYE( focused_ws, save_location.format(number, panel, extension, "dat")) simple.SaveNexusProcessed( focused_ws, save_location.format(number, panel, extension, "nxs")) return focused_ws