Exemple #1
0
                      dest="timing",
                      help="Flag to turn on timing of code")
    parser.set_defaults(timing=False)

    (options, args) = parser.parse_args()

    # Set up the configuration
    configure = hlr_utils.Configure()

    # Call the configuration setter for SansOptions
    hlr_utils.SansConfiguration(parser, configure, options, args)

    # Set the accelerator down time
    if hlr_utils.cli_provide_override(configure, "acc_down_time",
                                      "--acc-down-time"):
        configure.acc_down_time = hlr_utils.DrParameterFromString(\
            options.acc_down_time, True)

    if configure.lambda_bins is None:
        parser.error("Please specify the final wavelength axis!")

    # Set timer object if timing option is used
    if options.timing:
        import sns_timing
        timer = sns_timing.DiffTime()
    else:
        timer = None

    # Run the program
    run(configure, timer)
Exemple #2
0
def DgsConfiguration(parser, configure, options, args):
    """
    This function sets the incoming C{Configure} object with all the options
    that have been specified via the C{DgsOptions} object.

    @param parser: The parser object
    @type parser: L{hlr_utils.DgsOptions}
    
    @param configure: The configuration object
    @type configure: L{hlr_utils.Configure}
    
    @param options: The parsed options from C{DgsOptions}
    @type options: C{Option}

    @param args: The parsed arguments from C{DgsOptions}
    @type args: C{list}
    """

    # Call the configuration setter for InstOptions
    hlr_options.InstConfiguration(parser, configure, options, args, inst="DGS")

    # Set the upstream monitor path
    if hlr_utils.cli_provide_override(configure, "usmon_path", "--usmon-path"):
        configure.usmon_path = hlr_utils.NxPath(options.usmon_path)

    # Set the downstream monitor path
    if hlr_utils.cli_provide_override(configure, "dsmon_path", "--dsmon-path"):
        configure.dsmon_path = hlr_utils.NxPath(options.dsmon_path)        

    # Set the ROI file
    if hlr_utils.cli_provide_override(configure, "roi_file", "--roi-file"):
        configure.roi_file = hlr_utils.determine_files(options.roi_file,
                                                       one_file=True)

    # Set the minimum TOF channel for spectrum cutting
    if hlr_utils.cli_provide_override(configure, "tof_cut_min",
                                      "--tof-cut-min"):
        configure.tof_cut_min = options.tof_cut_min

    # Set the maximum TOF channel for spectrum cutting
    if hlr_utils.cli_provide_override(configure, "tof_cut_max",
                                      "--tof-cut-max"):
        configure.tof_cut_max = options.tof_cut_max        

    # Set a time-independent background subtraction constant
    if hlr_utils.cli_provide_override(configure, "tib_const", "--tib-const"):
        configure.tib_const = hlr_utils.DrParameterFromString(\
            options.tib_const, True)

    # Set the TOF range for the time-independent background determination
    if hlr_utils.cli_provide_override(configure, "tib_range", "--tib-range"):
        configure.tib_range = options.tib_range

    # Stop is both TIB methods are used
    if configure.tib_const is not None and configure.tib_range is not None:
        parser.error("Please use either --tib-const or --tib-range")

    # Set the chopper phase corrections for sample data
    if hlr_utils.cli_provide_override(configure, "cwp_data", "--cwp-data"):
        if options.cwp_data is not None:
            configure.cwp_data = [float(x) \
                                  for x in options.cwp_data.split(',')]
            if len(configure.data) != len(configure.cwp_data):
                parser.error("Need the same number of chopper phase "\
                             +"corrections as sample data runs!")
        else:
            configure.cwp_data = options.cwp_data

    # Set the chopper phase corrections for empty can data
    if hlr_utils.cli_provide_override(configure, "cwp_ecan", "--cwp-ecan"):
        if options.cwp_ecan is not None:
            configure.cwp_ecan = [float(x) \
                                  for x in options.cwp_ecan.split(',')]
            if len(configure.ecan) != len(configure.cwp_ecan):
                parser.error("Need the same number of chopper phase "\
                             +"corrections as empty can data runs!")
        else:
            configure.cwp_ecan = options.cwp_ecan


    # Set the chopper phase corrections for black can data
    if hlr_utils.cli_provide_override(configure, "cwp_bcan", "--cwp-bcan"):
        if options.cwp_bcan is not None:
            configure.cwp_bcan = [float(x) \
                                  for x in options.cwp_bcan.split(',')]
            if len(configure.bcan) != len(configure.cwp_bcan):
                parser.error("Need the same number of chopper phase "\
                             +"corrections as black can data runs!")
        else:
            configure.cwp_bcan = options.cwp_bcan

    # Set the initial energy
    if hlr_utils.cli_provide_override(configure, "initial_energy",
                                      "--initial-energy"):
        configure.initial_energy = hlr_utils.DrParameterFromString(\
            options.initial_energy, True)

    # Set the time-zero offset
    if hlr_utils.cli_provide_override(configure, "time_zero_offset",
                                      "--time-zero-offset"):    
        configure.time_zero_offset = hlr_utils.DrParameterFromString(\
            options.time_zero_offset, True)

    # Set no_mon_norm flag
    if hlr_utils.cli_provide_override(configure, "no_mon_norm",
                                      "--no-mon-norm"):
        configure.no_mon_norm = options.no_mon_norm

    # Set proton charge normalization flag
    if hlr_utils.cli_provide_override(configure, "pc_norm",
                                      "--pc-norm"):
        configure.pc_norm = options.pc_norm        

    # Set the proton charge scaling parameter
    if hlr_utils.cli_provide_override(configure, "scale_pc", "--scale-pc"):
        configure.scale_pc = options.scale_pc

    # Set the TOF range for the monitor integration
    if hlr_utils.cli_provide_override(configure, "mon_int_range",
                                      "--mon-int-range"):
        configure.mon_int_range = options.mon_int_range

    # Set the detector efficiency. This can be a tuple (one number for all
    # pixels) or a file containing numbers for all pixels.
    if hlr_utils.cli_provide_override(configure, "det_eff", "--det-eff"):
        try:
            configure.det_eff = hlr_utils.DrParameterFromString(\
                options.det_eff, True)
        except RuntimeError:
            configure.det_eff = hlr_utils.determine_files(options.det_eff,
                                                          one_file=True)
            
    # Set the transmission coefficient for the sample data background
    if hlr_utils.cli_provide_override(configure, "data_trans_coeff",
                                      "--data-trans-coeff"):
        configure.data_trans_coeff = hlr_utils.DrParameterFromString(\
            options.data_trans_coeff, True)

    # Set the transmission coefficient for the normalization background
    if hlr_utils.cli_provide_override(configure, "norm_trans_coeff",
                                      "--norm-trans-coeff"):
        configure.norm_trans_coeff = hlr_utils.DrParameterFromString(\
            options.norm_trans_coeff, True)        

    # Set the wavelength range for the vanadium normalization integration
    if hlr_utils.cli_provide_override(configure, "norm_int_range",
                                      "--norm-int-range"):
        configure.norm_int_range = options.norm_int_range

    # Set the wavelength bins
    if hlr_utils.cli_provide_override(configure, "lambda_bins",
                                      "--lambda-bins"):
        configure.lambda_bins = hlr_utils.AxisFromString(options.lambda_bins)

    # Set the ability to dump the combined calibrated TOF information
    if hlr_utils.cli_provide_override(configure, "dump_ctof_comb",
                                      "--dump-ctof-comb"):
        configure.dump_ctof_comb = options.dump_ctof_comb

    # Set the ability to dump the combined final wavelength information
    if hlr_utils.cli_provide_override(configure, "dump_wave_comb",
                                      "--dump-wave-comb"):
        configure.dump_wave_comb = options.dump_wave_comb

    # Set the ability to dump the time-independent background information
    if hlr_utils.cli_provide_override(configure, "dump_tib", "--dump-tib"):
        configure.dump_tib = options.dump_tib
Exemple #3
0
def RefConfiguration(parser, configure, options, args):
    """
    This function sets the incoming C{Configure} object with all the options
    that have been specified via the C{RefOptions} object.

    @param parser: The parser object
    @type parser: L{hlr_utils.RefOptions}
    
    @param configure: The configuration object
    @type configure: L{hlr_utils.Configure}
    
    @param options: The parsed options from C{RefOptions}
    @type options: C{Option}

    @param args: The parsed arguments from C{RefOptions}
    @type args: C{list}
    """

    # Call the configuration setter for InstOptions
    hlr_options.InstConfiguration(parser, configure, options, args, inst="REF")

    # Set the data instrument geometry file
    if hlr_utils.cli_provide_override(configure, "data_inst_geom",
                                      "--data-inst-geom"):
        configure.data_inst_geom = hlr_utils.determine_files(\
            options.data_inst_geom,
            one_file=True)

    # Set the normalization instrument geometry file
    if hlr_utils.cli_provide_override(configure, "norm_inst_geom",
                                      "--norm-inst-geom"):
        configure.norm_inst_geom = hlr_utils.determine_files(\
            options.norm_inst_geom,
            one_file=True)

    # Set the normalization data paths
    if hlr_utils.cli_provide_override(configure, "norm_data_paths",
                                      "--norm-data-paths"):
        try:
            configure.norm_data_paths = hlr_utils.NxPath(\
                options.norm_data_paths)
        except AttributeError:
            configure.norm_data_paths = options.norm_data_paths

    # Get the data path for the sample data ROI file
    if hlr_utils.cli_provide_override(configure, "data_roi_file",
                                      "--data-roi-file"):
        configure.data_roi_file = hlr_utils.determine_files(\
                     options.data_roi_file,
                     one_file=True)

    # Get the data path for the normalization data ROI file
    if hlr_utils.cli_provide_override(configure, "norm_roi_file",
                                      "--norm-roi-file"):
        if options.norm_roi_file is not None:
            configure.norm_roi_file = hlr_utils.determine_files(\
                     options.norm_roi_file,
                     one_file=True)
        else:
            configure.norm_roi_file = configure.data_roi_file

    # Get the data path for the sample data background ROI file
    if hlr_utils.cli_provide_override(configure, "dbkg_roi_file",
                                      "--dbkg-roi-file"):
        configure.dbkg_roi_file = hlr_utils.determine_files(\
                     options.dbkg_roi_file,
                     one_file=True)

    # Get the data path for the normalization background ROI file
    if hlr_utils.cli_provide_override(configure, "nbkg_roi_file",
                                      "--nbkg-roi-file"):
        if options.nbkg_roi_file is not None:
            configure.nbkg_roi_file = hlr_utils.determine_files(\
                     options.nbkg_roi_file,
                     one_file=True)
        else:
            configure.nbkg_roi_file = configure.dbkg_roi_file

    # Get the polar angle offset
    if hlr_utils.cli_provide_override(configure, "angle_offset",
                                      "--angle-offset"):
        configure.angle_offset = hlr_utils.DrParameterFromString(\
            options.angle_offset, True)

    # Set the ability to turn off background estimation and subtraction
    if hlr_utils.cli_provide_override(configure, "no_bkg", "--no-bkg"):
        configure.no_bkg = options.no_bkg

    # Set the ability to turn off normalization background estimation
    # and subtraction
    if hlr_utils.cli_provide_override(configure, "no_norm_bkg",
                                      "--no-norm-bkg"):
        configure.no_norm_bkg = options.no_norm_bkg

    # Set the minimum TOF channel for spectrum cutting
    if hlr_utils.cli_provide_override(configure, "tof_cut_min",
                                      "--tof-cut-min"):
        configure.tof_cut_min = options.tof_cut_min

    # Set the maximum TOF channel for spectrum cutting
    if hlr_utils.cli_provide_override(configure, "tof_cut_max",
                                      "--tof-cut-max"):
        configure.tof_cut_max = options.tof_cut_max

    # Set the TOF bins to zero out from the data and normalization spectra
    if hlr_utils.cli_provide_override(configure, "tof_cuts", "--tof-cuts"):
        if options.tof_cuts is not None:
            configure.tof_cuts = options.tof_cuts.split(',')
        else:
            configure.tof_cuts = options.tof_cuts

    # Set the momentum transfer bins
    if hlr_utils.cli_provide_override(configure, "Q_bins", "--mom-trans-bins"):
        configure.Q_bins = hlr_utils.AxisFromString(options.Q_bins)

    # Set the no bad data filter flag
    if hlr_utils.cli_provide_override(configure, "no_filter", "--no-filter"):
        configure.no_filter = options.no_filter

    # Set the store delta t over t flag
    if hlr_utils.cli_provide_override(configure, "store_dtot", "--store-dtot"):
        configure.store_dtot = options.store_dtot

    # Set the pixel ID range values for peak exclusion from sample data
    if hlr_utils.cli_provide_override(configure, "data_peak_excl",
                                      "--data-peak-excl"):
        configure.data_peak_excl = options.data_peak_excl

    # Set the pixel ID range values for peak exclusion from normalization data
    if hlr_utils.cli_provide_override(configure, "norm_peak_excl",
                                      "--norm-peak-excl"):
        configure.norm_peak_excl = options.norm_peak_excl

    # Set the integration direction
    if hlr_utils.cli_provide_override(configure, "int_dir", "--int-dir"):
        configure.int_dir = options.int_dir

    # Get the scattering (polar) angle for axis TOF to Q conversion
    if hlr_utils.cli_provide_override(configure, "scatt_angle",
                                      "--scatt-angle"):
        configure.scatt_angle = hlr_utils.DrParameterFromString(\
            options.scatt_angle, True)

    # Set the ability to dump the combined specular TOF information
    if hlr_utils.cli_provide_override(configure, "dump_specular",
                                      "--dump-specular"):
        configure.dump_specular = options.dump_specular

    # Set the ability to dump the combined background TOF information
    if hlr_utils.cli_provide_override(configure, "dump_bkg", "--dump-bkg"):
        configure.dump_bkg = options.dump_bkg

    # Set the ability to dump the combined subtracted TOF information
    if hlr_utils.cli_provide_override(configure, "dump_sub", "--dump-sub"):
        configure.dump_sub = options.dump_sub

    # Set the ability to dump the R(TOF) information
    if hlr_utils.cli_provide_override(configure, "dump_rtof", "--dump-rtof"):
        configure.dump_rtof = options.dump_rtof

    # Set the ability to dump the combined R(TOF) information
    if hlr_utils.cli_provide_override(configure, "dump_rtof_comb",
                                      "--dump-rtof-comb"):
        configure.dump_rtof_comb = options.dump_rtof_comb

    # Set the ability to dump the R(Q) information
    if hlr_utils.cli_provide_override(configure, "dump_rq", "--dump-rq"):
        configure.dump_rq = options.dump_rq

    # Set the ability to dump the R(Q) after rebinning information
    if hlr_utils.cli_provide_override(configure, "dump_rqr", "--dump-rqr"):
        configure.dump_rqr = options.dump_rqr

    if hlr_utils.cli_provide_override(configure, "dump_all", "--dump-all"):
        if options.dump_all:
            configure.dump_specular = True
            configure.dump_bkg = True
            configure.dump_sub = True
            configure.dump_rtof = True
            configure.dump_rtof_comb = True
            configure.dump_rq = True
            configure.dump_rqr = True
Exemple #4
0
    error = float(error_node.childNodes[0].nodeValue)

    if sqrerr and not error_square:
        error *= error
        error_square = True
    
    unit_node = node.getElementsByTagName("units")[0]
    units = unit_node.childNodes[0].nodeValue.strip(os.linesep).strip(' ')

    return DrParameter(value, error, units, is_square=error_square)

if __name__ == "__main__":
    import hlr_utils

    par1 = DrParameter(10.0, 1.4, "microseconds")
    par2 = hlr_utils.DrParameterFromString("-3.4,0.42,units=meV")

    import xml.dom.ext
    import xml.dom.minidom

    doc = xml.dom.minidom.Document()
    mainnode = doc.createElement("test_par")
    doc.appendChild(mainnode)
    anode = par2.toXmlConfig(doc, mainnode)

    xml.dom.ext.PrettyPrint(doc, open("test.xml", "w"))

    rdoc = xml.dom.minidom.parse("test.xml")
    tnode = rdoc.getElementsByTagName("test_par")[0]
    par3 = hlr_utils.DrParameterFromXmlConfig(tnode)
Exemple #5
0
    # Set the lambda perpendicular (lambda_T)
    if hlr_utils.cli_provide_override(configure, "lambdap_bins",
                                      "--lambdap-bins"):
        configure.lambdap_bins = hlr_utils.AxisFromString(options.lambdap_bins)

    # Set mon_norm flag
    if hlr_utils.cli_provide_override(configure, "mon_norm", "--mon-norm"):
        configure.mon_norm = options.mon_norm

    # Set the monitor path
    if hlr_utils.cli_provide_override(configure, "mon_path", "--mon-path"):
        configure.mon_path = hlr_utils.NxPath(options.mon_path)

    # Set the override angle for calculating lambda_T
    if hlr_utils.cli_provide_override(configure, "omega", "--omega"):
        configure.omega = hlr_utils.DrParameterFromString(options.omega, True)

    # Set the ability to dump the R(pid, lambda_T) information
    if hlr_utils.cli_provide_override(configure, "dump_twod", "--dump-twod"):
        configure.dump_twod = options.dump_twod

    if hlr_utils.cli_provide_override(configure, "dump_all", "--dump-all"):
        if options.dump_all:
            configure.dump_twod = True

    # Setup the timing object
    if options.timing:
        import sns_timing
        timer = sns_timing.DiffTime()
    else:
        timer = None
def DgsRedConfiguration(parser, configure, options, args):
    """
    This function sets the incoming C{Configure} object with all the options
    that have been specified via the C{DgsRedOptions} object.

    @param parser: The parser object
    @type parser: L{hlr_utils.DgsRedOptions}
    
    @param configure: The configuration object
    @type configure: L{hlr_utils.Configure}
    
    @param options: The parsed options from C{DgsRedOptions}
    @type options: C{Option}

    @param args: The parsed arguments from C{DgsRedOptions}
    @type args: C{list}
    """

    # Call the configuration setter for DgsOptions
    hlr_dgs_options.DgsConfiguration(parser, configure, options, args)

    # Set the mask file
    if hlr_utils.cli_provide_override(configure, "mask_file", "--mask-file"):
        configure.mask_file = hlr_utils.determine_files(options.mask_file)

    # Set the corner geometry information file
    if hlr_utils.cli_provide_override(configure, "corner_geom",
                                      "--corner-geom"):
        configure.corner_geom = options.corner_geom

    if configure.corner_geom is None:
        parser.error("You must provide a corner geometry file via the "\
                     +"corner-geom option!")

    # Set the lambda ratio flag
    if hlr_utils.cli_provide_override(configure, "lambda_ratio",
                                      "--lambda-ratio"):
        configure.lambda_ratio = options.lambda_ratio

    # Set the flag for making the phonon density of states representation
    if hlr_utils.cli_provide_override(configure, "pdos_Q", "--pdos-Q"):
        configure.pdos_Q = options.pdos_Q

    # Set the Debye-Waller constant for the phonon DOS representation
    if hlr_utils.cli_provide_override(configure, "debye_waller",
                                      "--debye-waller"):
        configure.debye_waller = hlr_utils.DrParameterFromString(\
            options.debye_waller)
    else:
        configure.debye_waller = options.debye_waller

    # Set the energy transfer bins
    if hlr_utils.cli_provide_override(configure, "E_bins", "--energy-bins"):
        configure.E_bins = hlr_utils.AxisFromString(options.E_bins)

    if configure.E_bins is None:
        parser.error("You must provide energy transfer binning via the "\
                     +"energy-bins option")

    # Set the momentum transfer bins
    if hlr_utils.cli_provide_override(configure, "Q_bins", "--mom-trans-bins"):
        configure.Q_bins = hlr_utils.AxisFromString(options.Q_bins)

    if configure.Q_bins is None:
        parser.error("You must provide momentum transfer binning via the "\
                     +"mom-trans-bins option")

    # Set the ability to write SPE and PHX files instead of S(Q, E) dist
    if hlr_utils.cli_provide_override(configure, "make_spe", "--make_spe"):
        configure.make_spe = options.make_spe

    # Set the ability to create the Q vector meshes for each energy slice
    if hlr_utils.cli_provide_override(configure, "qmesh", "--qmesh", "-m"):
        configure.qmesh = options.qmesh

    # Set the ability to write out fixed grid mesh files
    if hlr_utils.cli_provide_override(configure, "fixed", "--fixed", "-x"):
        configure.fixed = options.fixed

    # Set the ability to turn off zero suppression for single crystal data
    if hlr_utils.cli_provide_override(configure, "no_zero_supp",
                                      "--no-zero-supp"):
        configure.no_zero_supp = options.no_zero_supp

    # Set the ability to dump the combined energy transfer information
    if hlr_utils.cli_provide_override(configure, "dump_et_comb",
                                      "--dump-et-comb"):
        configure.dump_et_comb = options.dump_et_comb

    if hlr_utils.cli_provide_override(configure, "split", "--split"):
        configure.split = options.split
Exemple #7
0
def SansConfiguration(parser, configure, options, args):
    """
    This function sets the incoming C{Configure} object with all the options
    that have been specified via the C{SansOptions} object.

    @param parser: The parser object
    @type parser: L{hlr_utils.SansOptions}

    @param configure: The configuration object
    @type configure: L{hlr_utils.Configure}

    @param options: The parsed options from C{SansOptions}
    @type options: C{Option}

    @param args: The parsed arguments from C{SansOptions}
    @type args: C{list}
    """

    # Call the configuration setter for InstOptions
    hlr_utils.InstConfiguration(parser, configure, options, args, inst="SAS")

    # Set the beam monitor path
    if hlr_utils.cli_provide_override(configure, "bmon_path", "--bmon-path"):
        configure.bmon_path = hlr_utils.NxPath(options.bmon_path)

    # Set the transmission monitor path
    if hlr_utils.cli_provide_override(configure, "tmon_path", "--tmon-path"):
        configure.tmon_path = hlr_utils.NxPath(options.tmon_path)

    # Set the sample data Transmission spectrum file
    if hlr_utils.cli_provide_override(configure, "data_trans", "--data-trans"):
        configure.data_trans = hlr_utils.determine_files(options.data_trans,
                                                         one_file=True)

    # Set the solvent only Transmission spectrum file
    if hlr_utils.cli_provide_override(configure, "solv_trans", "--solv-trans"):
        configure.solv_trans = hlr_utils.determine_files(options.solv_trans,
                                                         one_file=True)

    # Set the empty can Transmission spectrum file
    if hlr_utils.cli_provide_override(configure, "ecan_trans", "--ecan-trans"):
        configure.ecan_trans = hlr_utils.determine_files(options.ecan_trans,
                                                         one_file=True)

    # Set the beam monitor override file
    if hlr_utils.cli_provide_override(configure, "beammon_over",
                                      "--beammon-over"):
        configure.beammon_over = hlr_utils.determine_files(\
            options.beammon_over,
            configure.inst,
            configure.facility,
            configure.proposal,
            stop_on_none=True)

    # Set no_bmon_norm flag
    if hlr_utils.cli_provide_override(configure, "no_bmon_norm",
                                      "--no-bmon-norm"):
        configure.no_bmon_norm = options.no_bmon_norm

    # Set mon_effc flag
    if hlr_utils.cli_provide_override(configure, "mon_effc", "--mon-effc"):
        configure.mon_effc = options.mon_effc

    # Set the monitor efficiency constant
    if hlr_utils.cli_provide_override(configure, "mon_eff_const",
                                      "--mon-eff-const"):
        configure.mon_eff_const = hlr_utils.DrParameterFromString(\
            options.mon_eff_const, True)

    # Set det_effc flag
    if hlr_utils.cli_provide_override(configure, "det_effc", "--det-effc"):
        configure.det_effc = options.det_effc

    # Set the detector efficiency scaling constant
    if hlr_utils.cli_provide_override(configure, "det_eff_scale_const",
                                      "--det-eff-scale-const"):
        configure.det_eff_scale_const = hlr_utils.DrParameterFromString(\
            options.det_eff_scale_const, True)

    # Set the detector efficiency attenuation constant
    if hlr_utils.cli_provide_override(configure, "det_eff_atten_const",
                                      "--det-eff-atten-const"):
        configure.det_eff_atten_const = hlr_utils.DrParameterFromString(\
            options.det_eff_atten_const, True)

    # Set the ROI file
    if hlr_utils.cli_provide_override(configure, "roi_file", "--roi-file"):
        configure.roi_file = hlr_utils.determine_files(options.roi_file,
                                                       one_file=True)

    # Set the momentum transfer bins
    if hlr_utils.cli_provide_override(configure, "Q_bins", "--mom-trans-bins"):
        configure.Q_bins = hlr_utils.AxisFromString(options.Q_bins)

    # Set the theta bins
    if hlr_utils.cli_provide_override(configure, "theta_bins", "--theta-bins"):
        configure.theta_bins = hlr_utils.AxisFromString(options.theta_bins)

    # Set the radius bins
    if hlr_utils.cli_provide_override(configure, "r_bins", "--r-bins"):
        configure.r_bins = hlr_utils.AxisFromString(options.r_bins)

    # Set the time-zero offset for the detector
    if hlr_utils.cli_provide_override(configure, "time_zero_offset_det",
                                      "--time-zero-offset-det"):
        configure.time_zero_offset_det = hlr_utils.DrParameterFromString(\
            options.time_zero_offset_det, True)

    # Set the time-zero offset for the monitor
    if hlr_utils.cli_provide_override(configure, "time_zero_offset_mon",
                                      "--time-zero-offset-mon"):
        configure.time_zero_offset_mon = hlr_utils.DrParameterFromString(\
            options.time_zero_offset_mon, True)

    # Set the lambda bins for use with dump-bmnorm-wave
    if hlr_utils.cli_provide_override(configure, "lambda_bins",
                                      "--lambda-bins"):
        configure.lambda_bins = hlr_utils.AxisFromString(options.lambda_bins)

    # Set the low-side lambda cut for cutting wavelength spectra
    if hlr_utils.cli_provide_override(configure, "lambda_low_cut",
                                      "--lambda-low-cut"):
        try:
            configure.lambda_low_cut = float(options.lambda_low_cut)
        except TypeError:
            configure.lambda_low_cut = options.lambda_low_cut

    # Set the high-side lambda cut for cutting wavelength spectra
    if hlr_utils.cli_provide_override(configure, "lambda_high_cut",
                                      "--lambda-high-cut"):
        try:
            configure.lambda_high_cut = float(options.lambda_high_cut)
        except TypeError:
            configure.lambda_high_cut = options.lambda_high_cut

    # Set the coefficients for the wavelength dependent background correction
    if hlr_utils.cli_provide_override(configure, "bkg_coeff", "--bkg-coeff"):
        try:
            configure.bkg_coeff = options.bkg_coeff.split(',')
        except AttributeError:
            configure.bkg_coeff = options.bkg_coeff

    # Set the accelerator down time for sample data
    if hlr_utils.cli_provide_override(configure, "data_acc_down_time",
                                      "--data-acc-down-time"):
        configure.data_acc_down_time = hlr_utils.DrParameterFromString(\
            options.data_acc_down_time, True)

    # Set the accelerator down time for sample data
    if hlr_utils.cli_provide_override(configure, "solv_acc_down_time",
                                      "--solv-acc-down-time"):
        configure.solv_acc_down_time = hlr_utils.DrParameterFromString(\
            options.solv_acc_down_time, True)

    # Set the accelerator down time for sample ecan
    if hlr_utils.cli_provide_override(configure, "ecan_acc_down_time",
                                      "--ecan-acc-down-time"):
        configure.ecan_acc_down_time = hlr_utils.DrParameterFromString(\
            options.ecan_acc_down_time, True)

    # Set the accelerator down time for sample data
    if hlr_utils.cli_provide_override(configure, "open_acc_down_time",
                                      "--open-acc-down-time"):
        configure.open_acc_down_time = hlr_utils.DrParameterFromString(\
            options.open_acc_down_time, True)

    # Set the axis dependent background scaling constant
    if hlr_utils.cli_provide_override(configure, "bkg_scale", "--bkg-scale"):
        try:
            configure.bkg_scale = float(options.bkg_scale)
        except TypeError:
            configure.bkg_scale = options.bkg_scale

    # Set the final data rescaling constant
    if hlr_utils.cli_provide_override(configure, "rescale_final",
                                      "--rescale-final"):
        try:
            configure.rescale_final = float(options.rescale_final)
        except TypeError:
            configure.rescale_final = options.rescale_final

    # Set the ability to dump the detector pixel wavelength information
    if hlr_utils.cli_provide_override(configure, "dump_wave", "--dump-wave"):
        configure.dump_wave = options.dump_wave

    # Set the ability to dump the beam monitor wavelength information
    if hlr_utils.cli_provide_override(configure, "dump_bmon_wave",
                                      "--dump-bmon-wave"):
        configure.dump_bmon_wave = options.dump_bmon_wave

    # Set the ability to dump the efficiency corrected beam monitor wavelength
    # information
    if hlr_utils.cli_provide_override(configure, "dump_bmon_effc",
                                      "--dump-bmon-effc"):
        configure.dump_bmon_effc = options.dump_bmon_effc

    # Set the ability to dump the rebinned beam monitor wavelength information
    if hlr_utils.cli_provide_override(configure, "dump_bmon_rebin",
                                      "--dump-bmon-rebin"):
        configure.dump_bmon_rebin = options.dump_bmon_rebin

    # Set the ability to dump the wavelength information after beam monitor
    # normalization
    if hlr_utils.cli_provide_override(configure, "dump_wave_bmnorm",
                                      "--dump-wave-bmnorm"):
        configure.dump_wave_bmnorm = options.dump_wave_bmnorm

    # Set the ability to dump the fractional counts and fractional area
    # separately after rebinning in Q
    if hlr_utils.cli_provide_override(configure, "dump_frac_rebin",
                                      "--dump-frac-rebin"):
        configure.dump_frac_rebin = options.dump_frac_rebin

    # Set the ability to dump a TOF vs radius distribution
    if hlr_utils.cli_provide_override(configure, "dump_tof_r", "--dump-tof-r"):
        configure.dump_tof_r = options.dump_tof_r

    # Set the ability to dump a TOF vs polar angle distribution
    if hlr_utils.cli_provide_override(configure, "dump_tof_theta",
                                      "--dump-tof-theta"):
        configure.dump_tof_theta = options.dump_tof_theta

    # Set the ability to dump a wavelength vs radius distribution
    if hlr_utils.cli_provide_override(configure, "dump_wave_r",
                                      "--dump-wave-r"):
        configure.dump_wave_r = options.dump_wave_r

    # Set the ability to dump a wavelength vs polar angle distribution
    if hlr_utils.cli_provide_override(configure, "dump_wave_theta",
                                      "--dump-wave-theta"):
        configure.dump_wave_theta = options.dump_wave_theta

    # Set the ability to dump a momentum transfer vs radius distribution
    if hlr_utils.cli_provide_override(configure, "dump_Q_r", "--dump-Q-r"):
        configure.dump_Q_r = options.dump_Q_r

    # Set the ability to dump a momentum transfer vs polar angle distribution
    if hlr_utils.cli_provide_override(configure, "dump_Q_theta",
                                      "--dump-Q-theta"):
        configure.dump_Q_theta = options.dump_Q_theta

    if hlr_utils.cli_provide_override(configure, "dump_2d", "--dump-2d"):
        if options.dump_2d:
            configure.dump_tof_r = True
            configure.dump_tof_theta = True
            configure.dump_wave_r = True
            configure.dump_wave_theta = True
            configure.dump_Q_r = True
            configure.dump_Q_theta = True

    if hlr_utils.cli_provide_override(configure, "dump_all", "--dump-all"):
        if options.dump_all:
            configure.dump_wave = True
            configure.dump_bmon_wave = True
            configure.dump_bmon_effc = True
            configure.dump_bmon_rebin = True
            configure.dump_wave_bmnorm = True
            configure.dump_frac_rebin = True
            configure.dump_tof_r = True
            configure.dump_tof_theta = True
            configure.dump_wave_r = True
            configure.dump_wave_theta = True
            configure.dump_Q_r = True
            configure.dump_Q_theta = True

    # Do some cross-checks
    if configure.dump_tof_r or configure.dump_wave_r or configure.dump_Q_r:
        if configure.r_bins is None:
            parser.error("Must specify --r-bins option when using 2D "\
                         +"distribution options --dump-tof-r, "\
                         +"--dump-wave-r or --dump-Q-r.")

    if configure.dump_tof_theta or configure.dump_wave_theta or \
           configure.dump_Q_theta:
        if configure.theta_bins is None:
            parser.error("Must specify --theta-bins option when using 2D "\
                         +"distribution options --dump-tof-theta, "\
                         +"--dump-wave-theta or --dump-Q-theta.")
Exemple #8
0
def AmrConfiguration(parser, configure, options, args):
    """
    This function sets the incoming C{Configure} object with all the options
    that have been specified via the C{AmrOptions} object.

    @param parser: The parser object
    @type parser: L{hlr_utils.AmrOptions}
    
    @param configure: The configuration object
    @type configure: L{hlr_utils.Configure}
    
    @param options: The parsed options from C{AmrOptions}
    @type options: C{Option}

    @param args: The parsed arguments from C{AmrOptions}
    @type args: C{list}
    """

    # Call the configuration setter for IgsOptions
    hlr_igs_options.IgsConfiguration(parser, configure, options, args)
 
    # Set the monitor efficiency (tuple)
    if hlr_utils.cli_provide_override(configure, "mon_eff", "--mon-eff"): 
        configure.mon_eff = hlr_utils.DrParameterFromString(options.mon_eff,
                                                            True)

    # Set the detector efficiency. This can be a tuple (one number for all
    # pixels) or a file containing numbers for all pixels.
    if hlr_utils.cli_provide_override(configure, "det_eff", "--det-eff"):
        try:
            configure.det_eff = hlr_utils.DrParameterFromString(\
                options.det_eff, True)
        except ValueError:
            configure.det_eff = hlr_utils.determine_files(options.det_eff,
                                                          one_file=True)
    # Set the energy transfer bins
    if hlr_utils.cli_provide_override(configure, "E_bins", "--energy-bins"):
        configure.E_bins = hlr_utils.AxisFromString(options.E_bins)

    if configure.E_bins is None:
        parser.error("You must provide energy transfer binning via the "\
                     +"energy-bins option")        

    # Set the momentum transfer bins
    if hlr_utils.cli_provide_override(configure, "Q_bins", "--mom-trans-bins"):
        configure.Q_bins = hlr_utils.AxisFromString(options.Q_bins)

    # Set the negative cosine polar angle bins
    if hlr_utils.cli_provide_override(configure, "ncospol_bins",
                                      "--ncos-polar-bins"):
        configure.ncospol_bins = hlr_utils.AxisFromString(options.ncospol_bins)

    # Make sure only momentum transfer or negative cosine polar binning is set
    if (configure.Q_bins is not None and \
        configure.ncospol_bins is not None) or \
        (configure.Q_bins is None and configure.ncospol_bins is None):
        parser.error("Please specify either --mom-trans-bins or "\
                     +"--ncos-polar-bins")

    # Set the final data rescaling constant
    if hlr_utils.cli_provide_override(configure, "rescale_final",
                                      "--rescale-final"):
        try:
            configure.rescale_final = float(options.rescale_final)
        except TypeError:
            configure.rescale_final = options.rescale_final

    # Set the scaling of the S(Q,E) distribution by the solid angle
    # distribution
    if hlr_utils.cli_provide_override(configure, "scale_sqe", "--scale-sqe"):
        configure.scale_sqe = options.scale_sqe

    # Set the lambda-dependent background constant for data
    if hlr_utils.cli_provide_override(configure, "ldb_const", "--ldb-const"):
        configure.ldb_const = hlr_utils.DrParameterFromString(\
                    options.ldb_const, True)

    # Set the TOF least background channel
    if hlr_utils.cli_provide_override(configure, "tof_least_bkg",
                                      "--tof-least-bkg"):
        configure.tof_least_bkg = hlr_utils.DrParameterFromString(\
                    options.tof_least_bkg, True)

    # Set the Chopper frequency
    if hlr_utils.cli_provide_override(configure, "chopper_freq",
                                      "--chopper-freq"):
        configure.chopper_freq = hlr_utils.DrParameterFromString(\
                    options.chopper_freq, True)

    # Set the wavelength center for the Chopper
    if hlr_utils.cli_provide_override(configure, "chopper_lambda_cent",
                                      "--chopper-lambda-cent"):
        configure.chopper_lambda_cent = hlr_utils.DrParameterFromString(\
                    options.chopper_lambda_cent, True)

    # Set the ability to dump the energy transfer information
    if hlr_utils.cli_provide_override(configure, "dump_dslin",
                                      "--dump-dslin"):
        configure.dump_dslin = options.dump_dslin

    # Set the ability to dump the wavelength information after vanadium norm
    if hlr_utils.cli_provide_override(configure, "dump_norm", "--dump-norm"):
        configure.dump_norm = options.dump_norm
        
    # Set the ability to dump the energy transfer information
    if hlr_utils.cli_provide_override(configure, "dump_energy",
                                      "--dump-energy"):
        configure.dump_energy = options.dump_energy
    
    # Set the ability to dump the initial energy information
    if hlr_utils.cli_provide_override(configure, "dump_initial_energy",
                                      "--dump-initial-energy"):    
        configure.dump_initial_energy = options.dump_initial_energy

    # Set the ability to dump the pixel contribution information
    if hlr_utils.cli_provide_override(configure, "dump_pix_contrib",
                                      "--dump-pix-contrib"):
        configure.dump_pix_contrib = options.dump_pix_contrib

    if hlr_utils.cli_provide_override(configure, "dump_all", "--dump-all"):
        if options.dump_all:
            configure.dump_dslin = True
            configure.dump_norm = True
            configure.dump_energy = True
            configure.dump_initial_energy = True

    if hlr_utils.cli_provide_override(configure, "split", "--split"):
        configure.split = options.split
Exemple #9
0
def IgsConfiguration(parser, configure, options, args):
    """
    This function sets the incoming C{Configure} object with all the options
    that have been specified via the C{IgsOptions} object.

    @param parser: The parser object
    @type parser: L{hlr_utils.IgsOptions}
    
    @param configure: The configuration object
    @type configure: L{hlr_utils.Configure}
    
    @param options: The parsed options from C{IgsOptions}
    @type options: C{Option}

    @param args: The parsed arguments from C{IgsOptions}
    @type args: C{list}
    """

    # Call the configuration setter for InstOptions
    hlr_options.InstConfiguration(parser, configure, options, args, inst="IGS")

    # Set the ROI file
    if hlr_utils.cli_provide_override(configure, "roi_file", "--roi-file"):
        configure.roi_file = hlr_utils.determine_files(options.roi_file,
                                                       one_file=True)

    # Set the monitor path
    if hlr_utils.cli_provide_override(configure, "mon_path", "--mon-path"):
        configure.mon_path = hlr_utils.NxPath(options.mon_path)

    # Set the dead time
    if hlr_utils.cli_provide_override(configure, "dead_time", "--dead-time"):
        configure.dead_time = hlr_utils.DrParameterFromString(\
            options.dead_time)

    # Set the minimum TOF channel for spectrum cutting
    if hlr_utils.cli_provide_override(configure, "tof_cut_min",
                                      "--tof-cut-min"):
        configure.tof_cut_min = options.tof_cut_min

    # Set the maximum TOF channel for spectrum cutting
    if hlr_utils.cli_provide_override(configure, "tof_cut_max",
                                      "--tof-cut-max"):
        configure.tof_cut_max = options.tof_cut_max

    # Set the time-independent background TOFs
    if hlr_utils.cli_provide_override(configure, "tib_tofs", "--tib-tofs"):
        if options.tib_tofs is not None:
            configure.tib_tofs = options.tib_tofs.split(',')
        else:
            configure.tib_tofs = options.tib_tofs

    # Set the time-independent background constant for data
    if hlr_utils.cli_provide_override(configure, "tib_data_const",
                                      "--tib-data-const"):
        configure.tib_data_const = hlr_utils.DrParameterFromString(\
                    options.tib_data_const, True)

    # Set the time-independent background constant for ecan
    if hlr_utils.cli_provide_override(configure, "tib_ecan_const",
                                      "--tib-ecan-const"):
        configure.tib_ecan_const = hlr_utils.DrParameterFromString(\
                    options.tib_ecan_const, True)

    # Set the time-independent background constant for back
    if hlr_utils.cli_provide_override(configure, "tib_back_const",
                                      "--tib-back-const"):
        configure.tib_back_const = hlr_utils.DrParameterFromString(\
                    options.tib_back_const, True)

    # Set the time-independent background constant for norm
    if hlr_utils.cli_provide_override(configure, "tib_norm_const",
                                      "--tib-norm-const"):
        configure.tib_norm_const = hlr_utils.DrParameterFromString(\
                    options.tib_norm_const, True)

    # Set the time-independent background constant for dsback
    if hlr_utils.cli_provide_override(configure, "tib_dsback_const",
                                      "--tib-dsback-const"):
        configure.tib_dsback_const = hlr_utils.DrParameterFromString(\
                    options.tib_dsback_const, True)

    # Set the normalization start wavelength
    if hlr_utils.cli_provide_override(configure, "norm_start", "--norm_start"):
        configure.norm_start = float(options.norm_start)

    # Set the normalization end wavelength
    if hlr_utils.cli_provide_override(configure, "norm_end", "--norm_end"):
        configure.norm_end = float(options.norm_end)

    # Set no_mon_norm flag
    if hlr_utils.cli_provide_override(configure, "no_mon_norm",
                                      "--no-mon-norm"):
        configure.no_mon_norm = options.no_mon_norm

    # Set no_mon_effc flag
    if hlr_utils.cli_provide_override(configure, "no_mon_effc",
                                      "--no-mon-effc"):
        configure.no_mon_effc = options.no_mon_effc

    # Set the final wavelength
    if hlr_utils.cli_provide_override(configure, "wavelength_final",
                                      "--wavelength-final"):
        configure.wavelength_final = hlr_utils.DrParameterFromString(\
            options.wavelength_final, True)

    # Set the time-zero offset
    if hlr_utils.cli_provide_override(configure, "time_zero_offset",
                                      "--time-zero-offset"):
        configure.time_zero_offset = hlr_utils.DrParameterFromString(\
            options.time_zero_offset, True)

    # Set the time-zero slope
    if hlr_utils.cli_provide_override(configure, "time_zero_slope",
                                      "--time-zero-slope"):
        configure.time_zero_slope = hlr_utils.DrParameterFromString(\
            options.time_zero_slope, True)

    # Set the lambda bins for use with dump-mnorm-wave
    if hlr_utils.cli_provide_override(configure, "lambda_bins",
                                      "--lambda-bins"):
        configure.lambda_bins = hlr_utils.AxisFromString(options.lambda_bins)

    # Set the ability to dump the time-independent background information
    if hlr_utils.cli_provide_override(configure, "dump_tib", "--dump-tib"):
        configure.dump_tib = options.dump_tib

    # Set the ability to dump the wavelength information
    if hlr_utils.cli_provide_override(configure, "dump_wave", "--dump-wave"):
        configure.dump_wave = options.dump_wave

    # Set the ability to dump the monitor wavelength information
    if hlr_utils.cli_provide_override(configure, "dump_mon_wave",
                                      "--dump-mon-wave"):
        configure.dump_mon_wave = options.dump_mon_wave

    # Set the ability to dump the rebinned monitor wavelength information
    if hlr_utils.cli_provide_override(configure, "dump_mon_rebin",
                                      "--dump-mon-rebin"):
        configure.dump_mon_rebin = options.dump_mon_rebin

    # Set the ability to dump the efficiency corrected monitor wavelength
    # information
    if hlr_utils.cli_provide_override(configure, "dump_mon_effc",
                                      "--dump-mon-effc"):
        configure.dump_mon_effc = options.dump_mon_effc

    # Set the ability to dump the wavelength information
    if hlr_utils.cli_provide_override(configure, "dump_wave_mnorm",
                                      "--dump-wave-mnorm"):
        configure.dump_wave_mnorm = options.dump_wave_mnorm

    if hlr_utils.cli_provide_override(configure, "dump_all", "--dump-all"):
        if options.dump_all:
            configure.dump_tib = True
            configure.dump_wave = True
            configure.dump_mon_wave = True
            configure.dump_mon_wave = True
            configure.dump_mon_effc = True
            configure.dump_mon_diml = True
            configure.dump_mon_rebin = True
            configure.dump_wave_mnorm = True

    # Set the filter option
    if hlr_utils.cli_provide_override(configure, "filter", "--filter",
                                      "--no-filter"):
        configure.filter = options.filter

    # Set MC option
    if hlr_utils.cli_provide_override(configure, "mc", "--mc"):
        configure.mc = options.mc

    # Set the early background subtraction option
    if hlr_utils.cli_provide_override(configure, "hwfix", "--hwfix"):
        configure.hwfix = options.hwfix

    # Set the constant for scaling the background spectra: sample
    if hlr_utils.cli_provide_override(configure, "scale_bs", "--scale-bs"):
        configure.scale_bs = hlr_utils.DrParameterFromString(
            options.scale_bs, True)

    # Set the constant for scaling the background spectra: normalization
    if hlr_utils.cli_provide_override(configure, "scale_bn", "--scale-bn"):
        configure.scale_bn = hlr_utils.DrParameterFromString(
            options.scale_bn, True)

    # Set the constant for scaling the background spectra: empty container
    # for sample
    if hlr_utils.cli_provide_override(configure, "scale_bcs", "--scale-bcs"):
        configure.scale_bcs = hlr_utils.DrParameterFromString(\
            options.scale_bcs, True)

    # Set the constant for scaling the background spectra: empty container
    # for normalization
    if hlr_utils.cli_provide_override(configure, "scale_bcn", "--scale-bcn"):
        configure.scale_bcn = hlr_utils.DrParameterFromString(\
            options.scale_bcn, True)

    # Set the constant for scaling the empty container spectra: sample
    if hlr_utils.cli_provide_override(configure, "scale_cs", "--scale-cs"):
        configure.scale_cs = hlr_utils.DrParameterFromString(
            options.scale_cs, True)

    # Set the constant for scaling the empty container spectra: normalization
    if hlr_utils.cli_provide_override(configure, "scale_cn", "--scale-cn"):
        configure.scale_cn = hlr_utils.DrParameterFromString(
            options.scale_cn, True)

    # Set the elastic peak range in TOF
    if hlr_utils.cli_provide_override(configure, "tof_elastic",
                                      "--tof-elastic"):
        if options.tof_elastic is not None:
            configure.tof_elastic = options.tof_elastic.split(',')
        else:
            configure.tof_elastic = options.tof_elastic