Ejemplo n.º 1
0
def get_corner_geometry(filename):
    """
    This function will read in a geometry file containing the corner angle
    information for DGS instruments.

    @param filename: The name of the geometry file to read.
    @type filename: C{string}


    @return: The angle information for the particular DGS instrument.
    @rtype: C{dict}
    """
    import SOM

    infile = open(hlr_utils.fix_filename(filename), "r")

    angle_info = {}
    counter = 0
    nexus_id = None
    angle_obj = None
    for line in infile:
        if line.startswith("b"):
            nexus_id = SOM.NeXusId.fromString(line.rstrip()).toTuple()
            counter = 0
            angle_obj = Angles()
        else:
            angle_list = line.rstrip().split(' ')
            angles = [float(angle) for angle in angle_list]
            if counter == 1:
                angle_obj.setPolar(angles)
            else:
                angle_obj.setAzimuthal(angles)

        if counter == 2:
            angle_info[str(nexus_id)] = angle_obj

        counter += 1

    return angle_info
Ejemplo n.º 2
0
def get_corner_geometry(filename):
    """
    This function will read in a geometry file containing the corner angle
    information for DGS instruments.

    @param filename: The name of the geometry file to read.
    @type filename: C{string}


    @return: The angle information for the particular DGS instrument.
    @rtype: C{dict}
    """
    import SOM

    infile = open(hlr_utils.fix_filename(filename), "r")

    angle_info = {}
    counter = 0
    nexus_id = None
    angle_obj = None
    for line in infile:
        if line.startswith("b"):
            nexus_id = SOM.NeXusId.fromString(line.rstrip()).toTuple()
            counter = 0
            angle_obj = Angles()
        else:
            angle_list = line.rstrip().split(' ')
            angles = [float(angle) for angle in angle_list]
            if counter == 1:
                angle_obj.setPolar(angles)
            else:
                angle_obj.setAzimuthal(angles)

        if counter == 2:
            angle_info[str(nexus_id)] = angle_obj

        counter += 1

    return angle_info
Ejemplo n.º 3
0
        pass  # use the default name

    dst = DST.getInstance("application/x-NeXus", filename)
    som = dst.getSOM(("/entry/bank1", 1))

    if "ARCS" in filename:
        cgeom = "/SNS/ARCS/2009_2_18_CAL/calibrations/ARCS_cgeom_20090128.txt"
    elif "CNCS" in filename:
        cgeom = "/SNS/CNCS/2009_2_5_CAL/calibrations/CNCS_cgeom_20090224.txt"
    elif "SEQ" in filename or "SEQUOIA" in filename:
        cgeom = "/SNS/SEQ/2009_2_17_CAL/calibrations/SEQ_cgeom_20090302.txt"
    else:
        raise RuntimeError("Cannot get corner geometry file")

    # Get corner geometry
    infile = open(hlr_utils.fix_filename(cgeom), "r")

    angle_info = {}
    counter = 0
    nexus_id = None
    angle_obj = None
    for line in infile:
        if line.startswith("b"):
            nexus_id = SOM.NeXusId.fromString(line.rstrip()).toTuple()
            counter = 0
            angle_obj = hlr_utils.Angles()
        else:
            angle_list = line.rstrip().split(' ')
            angles = [float(angle) for angle in angle_list]
            if counter == 1:
                angle_obj.setPolar(angles)
Ejemplo n.º 4
0
                      +"value is 1.")
    parser.set_defaults(sum_tubes=1)

    (options, args) = parser.parse_args()

    # set up the configuration
    configure = hlr_utils.Configure()
    
    # get the datafile name and check it
    if len(args) == 1:
        configure.data = args[0]
        if not hlr_utils.file_exists(configure.data):
            parser.error("Data file [%s] does not exist" % configure.data)
    else:
        if options.data is not None:
            configure.data = hlr_utils.fix_filename(options.data)
            if not hlr_utils.file_exists(configure.data):
                parser.error("Data file [%s] does not exist" % configure.data)
        else:
            parser.error("Did not specify a datafile")

    # set the verbosity
    configure.verbose = options.verbose

    # set vertical
    configure.vertical = options.vertical

    # set pixel grouping
    configure.pixel_group = options.pixel_group

    # set sum tubes
Ejemplo n.º 5
0
                                   +"file name."

    # Do not need to use config option
    parser.remove_option("--config")

    (options, args) = parser.parse_args()

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

    # Need to set the inst parameter to None to spoof data file finder
    configure.inst = None

    # Quick test on output
    if options.output is not None:
        filename = hlr_utils.fix_filename(options.output)
        import os
        # If this is a directory only, then we want to have the default
        # created filename
        if os.path.isdir(filename) and not os.path.isfile(filename):
            have_output = False
            is_dir = True
        else:
            have_output = True
            is_dir = False
    else:
        have_output = False
        is_dir = False
        
    # Temporarily silence verbosity
    old_verbosity = options.verbose
Ejemplo n.º 6
0
    # set up the configuration
    configure = hlr_utils.Configure()

    # Need to set the inst parameter to None to spoof data file finder
    configure.inst = None

    # Need to set the facility parameter to None to spoof data file finder
    configure.facility = None

    # Need to spoof the data check
    configure.data = [""]
    options.data = None

    # Quick test on output
    if options.output is not None:
        filename = hlr_utils.fix_filename(options.output)
        import os
        # If this is a directory only, then we want to have the default
        # created filename
        if os.path.isdir(filename) and not os.path.isfile(filename):
            have_output = False
            is_dir = True
        else:
            have_output = True
            is_dir = False
    else:
        have_output = False
        is_dir = False

    # Temporarily silence verbosity
    old_verbosity = options.verbose
Ejemplo n.º 7
0
                      +"value is 1.")
    parser.set_defaults(sum_tubes=1)

    (options, args) = parser.parse_args()

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

    # get the datafile name and check it
    if len(args) == 1:
        configure.data = args[0]
        if not hlr_utils.file_exists(configure.data):
            parser.error("Data file [%s] does not exist" % configure.data)
    else:
        if options.data is not None:
            configure.data = hlr_utils.fix_filename(options.data)
            if not hlr_utils.file_exists(configure.data):
                parser.error("Data file [%s] does not exist" % configure.data)
        else:
            parser.error("Did not specify a datafile")

    # set the verbosity
    configure.verbose = options.verbose

    # set vertical
    configure.vertical = options.vertical

    # set pixel grouping
    configure.pixel_group = options.pixel_group

    # set sum tubes
Ejemplo n.º 8
0
                      help="Specify the detector geometry file")


    (options, args) = parser.parse_args()
   
    # set up the configuration
    configure = hlr_utils.Configure()
    
    # get the datafile name and check it
    if len(args) == 1:
        configure.data = args[0]
        if not hlr_utils.file_exists(configure.data):
            parser.error("Data file [%s] does not exist" % configure.data)
    else:
        if options.data is not None:
            configure.data = hlr_utils.fix_filename(options.data)
            if not hlr_utils.file_exists(configure.data):
                parser.error("Data file [%s] does not exist" % configure.data)
        else:
            parser.error("Did not specify a datafile")
    # create the output file name if there isn't one supplied
    if options.output:
        configure.output = hlr_utils.fix_filename(options.output)
        print "Using %s as output file" % configure.output
    else:
        configure.output = None
        outfile = os.path.basename(configure.data)
        path = os.path.join(os.getcwd(), outfile)
        if options.d_bins is not None:
            configure.output_ds = hlr_utils.ext_replace(path, "nxs", "ds1")
            print "Using %s as output file" % configure.output_ds
Ejemplo n.º 9
0
def BasicConfiguration(parser, configure, options, args):
    """
    This function sets the incoming C{Configure} object with all the options
    that have been specified via the C{BasicOptions} object.

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

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

    # Set from a configuration file first
    if options.config is not None:
        import xml.dom.minidom
        conf_doc = xml.dom.minidom.parse(options.config)
        configure = hlr_utils.ConfigFromXml(conf_doc, configure)

    # Now override options provided on command-line

    # Set the verbosity, if present on command-line
    if not configure.verbose:
        configure.verbose = options.verbose
    else:
        # Got the verbosity from the config file, but check CLI
        if hlr_utils.cli_checker("-v", "-q"):
            # Override option
            configure.verbose = options.verbose
        else:
            # No flags present, do nothing
            pass

    # Define instrument short name first as stuff below depends on it
    if hlr_utils.cli_provide_override(configure, "inst", "--inst"):
        configure.inst = options.inst

    # Define facility short name as stuff below depends on it
    if hlr_utils.cli_provide_override(configure, "facility", "--facility"):
        configure.facility = options.facility

    # Define proposal as stuff below depends on it.
    if hlr_utils.cli_provide_override(configure, "proposal", "--proposal"):
        configure.proposal = options.proposal

    # Get the datafile name and check it
    if options.data is not None:
        configure.data = hlr_utils.determine_files(options.data,
                                                   configure.inst,
                                                   configure.facility,
                                                   configure.proposal,
                                                   stop_on_none=True)
    elif len(args) > 0:
        configure.data = hlr_utils.determine_files(args,
                                                   configure.inst,
                                                   configure.facility,
                                                   configure.proposal,
                                                   stop_on_none=True)
    elif configure.data:
        # We have data from the config file, so everything is OK.
        pass
    else:
        parser.error("Did not specify a datafile")

    import os
    # Deal with file or directory from output option
    if options.output:
        filepath = hlr_utils.fix_filename(options.output)
        if os.path.exists(filepath):
            if os.path.isdir(filepath):
                outfile = os.path.basename(configure.data[0])
                path = os.path.join(filepath, outfile)
                configure.output = hlr_utils.ext_replace(path, "nxs", "txt")
                configure.path_replacement = filepath
                configure.ext_replacement = "txt"

            elif os.path.isfile(filepath):
                configure.output = filepath
                configure.path_replacement = os.path.dirname(filepath)
                configure.ext_replacement = filepath.split('.')[-1]

            else:
                parser.error("Cannot handle %s in output option" % filepath)
        else:
            # Assume that this is a file and hope that the directory exists
            directory = os.path.dirname(filepath)
            if directory != "":
                if not os.path.exists(directory):
                    raise RuntimeError("The directory %s must exist!" \
                                       % directory)
                else:
                    pass
            else:
                directory = None
            configure.output = filepath
            configure.path_replacement = directory
            configure.ext_replacement = filepath.split('.')[-1]

    elif configure.output:
        # We have an output file, so no need to do anything else
        try:
            configure.path_replacement
        except AttributeError:
            configure.path_replacement = None
    # Create the output file name if there isn't one supplied
    else:
        outfile = os.path.basename(configure.data[0])
        path = os.path.join(os.getcwd(), outfile)
        configure.output = hlr_utils.ext_replace(path, "nxs", "txt")
        configure.path_replacement = None
        configure.ext_replacement = "txt"

    if configure.verbose and options.output:
        print "Using %s as output file" % configure.output
Ejemplo n.º 10
0
def BasicConfiguration(parser, configure, options, args):
    """
    This function sets the incoming C{Configure} object with all the options
    that have been specified via the C{BasicOptions} object.

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

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

    # Set from a configuration file first
    if options.config is not None:
        import xml.dom.minidom
        conf_doc = xml.dom.minidom.parse(options.config)
        configure = hlr_utils.ConfigFromXml(conf_doc, configure)

    # Now override options provided on command-line

    # Set the verbosity, if present on command-line
    if not configure.verbose:
        configure.verbose = options.verbose 
    else: 
        # Got the verbosity from the config file, but check CLI 
        if hlr_utils.cli_checker("-v", "-q"): 
            # Override option 
            configure.verbose = options.verbose 
        else: 
            # No flags present, do nothing
            pass 

    # Define instrument short name first as stuff below depends on it
    if hlr_utils.cli_provide_override(configure, "inst", "--inst"):
        configure.inst = options.inst

    # Define facility short name as stuff below depends on it
    if hlr_utils.cli_provide_override(configure, "facility", "--facility"):
        configure.facility = options.facility        

    # Define proposal as stuff below depends on it.
    if hlr_utils.cli_provide_override(configure, "proposal", "--proposal"):
        configure.proposal = options.proposal
        
    # Get the datafile name and check it
    if options.data is not None:
        configure.data = hlr_utils.determine_files(options.data,
                                                   configure.inst,
                                                   configure.facility,
                                                   configure.proposal,
                                                   stop_on_none=True)
    elif len(args) > 0:
        configure.data = hlr_utils.determine_files(args, configure.inst,
                                                   configure.facility,
                                                   configure.proposal,
                                                   stop_on_none=True)
    elif configure.data:
        # We have data from the config file, so everything is OK.
        pass
    else:
        parser.error("Did not specify a datafile")

    import os
    # Deal with file or directory from output option
    if options.output:
        filepath = hlr_utils.fix_filename(options.output)
        if os.path.exists(filepath):
            if os.path.isdir(filepath):
                outfile = os.path.basename(configure.data[0])
                path = os.path.join(filepath, outfile)
                configure.output = hlr_utils.ext_replace(path, "nxs", "txt")
                configure.path_replacement = filepath
                configure.ext_replacement = "txt"

            elif os.path.isfile(filepath):
                configure.output = filepath
                configure.path_replacement = os.path.dirname(filepath)
                configure.ext_replacement = filepath.split('.')[-1]

            else:
                parser.error("Cannot handle %s in output option" % filepath)
        else:
            # Assume that this is a file and hope that the directory exists
            directory = os.path.dirname(filepath)
            if directory != "":
                if not os.path.exists(directory):
                    raise RuntimeError("The directory %s must exist!" \
                                       % directory)
                else:
                    pass
            else:
                directory = None
            configure.output = filepath
            configure.path_replacement = directory
            configure.ext_replacement = filepath.split('.')[-1]

    elif configure.output:
        # We have an output file, so no need to do anything else
        try:
            configure.path_replacement
        except AttributeError:
            configure.path_replacement = None
    # Create the output file name if there isn't one supplied
    else:
        outfile = os.path.basename(configure.data[0])
        path = os.path.join(os.getcwd(), outfile)
        configure.output = hlr_utils.ext_replace(path, "nxs", "txt")
        configure.path_replacement = None
        configure.ext_replacement = "txt"

    if configure.verbose and options.output:
        print "Using %s as output file" % configure.output
Ejemplo n.º 11
0
    parser.add_option(
        "-a",
        "--append",
        action="store_true",
        dest="append",
        help="Flag for turning on ability to append to mask " + "file",
    )
    parser.set_defaults(append=False)

    (options, args) = parser.parse_args()

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

    if options.output:
        configure.output = hlr_utils.fix_filename(options.output)
    else:
        configure.output = "pixel_mask.dat"

    # set the list of bank IDs
    if options.bank_ids is not None:
        configure.bank_ids = options.bank_ids.split(",")
    else:
        parser.error("Must provide a list of bank ids via the --bank-ids " + "flag.")

    # set the list of horizontal pixel range pairs
    if options.h_ranges is not None:
        configure.h_ranges = hlr_utils.create_id_pairs(options.h_ranges, options.bank_ids)
    else:
        parser.error("Must provide a list of horizontal pixel ranges via the " + "--h-ranges flag.")
Ejemplo n.º 12
0
                      +"as many pairs as the number of bank IDs provided "\
                      +"via the --bank-ids flag. If not, the last pair will "
                      +"be used for the remaining bank IDs")

    parser.add_option("-a", "--append", action="store_true", dest="append",
                      help="Flag for turning on ability to append to mask "\
                      +"file")
    parser.set_defaults(append=False)

    (options, args) = parser.parse_args()

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

    if options.output:
        configure.output = hlr_utils.fix_filename(options.output)
    else:
        configure.output = "pixel_mask.dat"

    # set the list of bank IDs
    if options.bank_ids is not None:
        configure.bank_ids = options.bank_ids.split(',')
    else:
        parser.error("Must provide a list of bank ids via the --bank-ids "\
                     +"flag.")

    # set the list of horizontal pixel range pairs
    if options.h_ranges is not None:
        configure.h_ranges = hlr_utils.create_id_pairs(\
            options.h_ranges,
            options.bank_ids)
Ejemplo n.º 13
0
                      dest="det_geom",
                      help="Specify the detector geometry file")

    (options, args) = parser.parse_args()

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

    # get the datafile name and check it
    if len(args) == 1:
        configure.data = args[0]
        if not hlr_utils.file_exists(configure.data):
            parser.error("Data file [%s] does not exist" % configure.data)
    else:
        if options.data is not None:
            configure.data = hlr_utils.fix_filename(options.data)
            if not hlr_utils.file_exists(configure.data):
                parser.error("Data file [%s] does not exist" % configure.data)
        else:
            parser.error("Did not specify a datafile")
    # create the output file name if there isn't one supplied
    if options.output:
        configure.output = hlr_utils.fix_filename(options.output)
        print "Using %s as output file" % configure.output
    else:
        configure.output = None
        outfile = os.path.basename(configure.data)
        path = os.path.join(os.getcwd(), outfile)
        if options.d_bins is not None:
            configure.output_ds = hlr_utils.ext_replace(path, "nxs", "ds1")
            print "Using %s as output file" % configure.output_ds
Ejemplo n.º 14
0
        pass # use the default name

    dst = DST.getInstance("application/x-NeXus", filename)
    som = dst.getSOM(("/entry/bank1", 1))

    if "ARCS" in filename:
        cgeom = "/SNS/ARCS/2009_2_18_CAL/calibrations/ARCS_cgeom_20090128.txt"
    elif "CNCS" in filename:
        cgeom="/SNS/CNCS/2009_2_5_CAL/calibrations/CNCS_cgeom_20090224.txt"
    elif "SEQ" in filename or "SEQUOIA" in filename:
        cgeom="/SNS/SEQ/2009_2_17_CAL/calibrations/SEQ_cgeom_20090302.txt"
    else:
        raise RuntimeError("Cannot get corner geometry file")

    # Get corner geometry
    infile = open(hlr_utils.fix_filename(cgeom), "r")

    angle_info = {}
    counter = 0
    nexus_id = None
    angle_obj = None
    for line in infile:
        if line.startswith("b"):
            nexus_id = SOM.NeXusId.fromString(line.rstrip()).toTuple()
            counter = 0
            angle_obj = hlr_utils.Angles()
        else:
            angle_list = line.rstrip().split(' ')
            angles = [float(angle) for angle in angle_list]
            if counter == 1:
                angle_obj.setPolar(angles)