示例#1
0
 def setUp(self):
     self.d = DetectorData(
         shape=(10, 10),
         pixelsteps_per_buffer=1,
         buffers_per_file=1,
         dirpaths=NETCDF_DIR,
         filepattern=NETCDF_PATTERN,
         mca_bins=2048,
         first_file_n=1,
     )
示例#2
0
def getData(fname):
    """Extract data from mda-ASCII file and distribute into Pixel objects

    Returns: XAS scan data in a detector 'object' (variable "det")
            energy axis, transmission data array and detector filled with fluo data
    (detector object simply full of '0' values if no fluorescence data available)
    Transmission data in "trans" comprises encoder_E, I0/1/2, sample_time, encoder_angle
    !! I0/1/2  are already normalised to t !!

    """
    # get the path to the netCDF files from the mda file
    mda = readMDA.readMDA(fname, verbose=False)
    netcdf_basename = os.path.splitext(os.path.basename(fname))[0]
    netcdf_directory = os.path.join(os.path.dirname(os.path.abspath(fname)),
                                    netcdf_basename)
    netcdf_filepattern = '{}_([0-9]*)\.nc'.format(netcdf_basename)

    scanData = mda[1]
    scanSize = scanData.npts

    # create and set the reader for the fluorescence detector
    detector_data = DetectorData(shape=(6, 6),
                                 pixelsteps_per_buffer=1,
                                 buffers_per_file=1,
                                 dirpaths=netcdf_directory,
                                 filepattern=netcdf_filepattern,
                                 mca_bins=2048,
                                 first_file_n=1)

    detector = Detector(detector_data)

    # set scanSize according to the netCDF data that was available
    scanSize = highest_available_scandata(detector, scanSize)
    detector.steprange = range(scanSize)

    # read transmission data
    # The PVs listed in pvColumnNames all refer to columnar data such as axis values.
    # This is contrasted by thoselisted in pvSingleValues, which are all single values.
    pvColumnNames = [
        'EncEnergy:ActPos', 'scaler1:S2C', 'scaler1:S3C', 'scaler1:S4C',
        'scaler1.T', 'EncAngle:ActPos'
    ]

    trans = np.empty((len(pvColumnNames), scanSize))
    for series in scanData.d:
        try:
            tag = ':'.join(
                series.name.split(':')[1:])  # use the PV part after the IOC id
            if tag in pvColumnNames:
                trans[pvColumnNames.index(tag)] = series.data[:scanSize]
        except Exception as e:
            print e
            print 'missing PV ' + tag

    ts = trans[pvColumnNames.index('scaler1.T')]  # get the sample time
    detector.set_ts(ts)
    e = trans[pvColumnNames.index(
        'EncEnergy:ActPos')] * 1000.0  # Energy axis (in eV !!)

    # normalise I0, I1, I2 to sample_time ts (use string "scaler1:" as identifier)
    for i, name in enumerate(pvColumnNames):
        if name.startswith('scaler1:'):
            trans[i] = trans[i] / ts

    ## call dead time correction later; should be performed only on
    ## good spectra ("goodPixels") as bad spectra can contain zeros which
    ## this function would divide by
    ## call is via function:  detDeadCorr(det, goodPixels)

    return e, trans, detector