コード例 #1
0
ファイル: compare_centers.py プロジェクト: APS-USAXS/livedata
def main():
    fly = reduceFlyData.UsaxsFlyScan(TESTFILE)
    fly.reduce()
    full = fly.reduced["full"]

    print full.keys()
    print "ar[:5]", full['ar'][:5]
    for k in "R_max r_peak ar_r_peak".split():
        print k, full[k]

    cen, ar, R = flyscan_centroid(full, 0.4)
    print "centroid:", cen

    with h5py.File(OUTFILE, "w") as h5:
        h5.attrs["default"] = "entry"
        nxentry = h5.create_group("entry")
        nxentry.attrs["NX_class"] = "NXentry"
        nxentry.attrs["default"] = "data"
        nxdata = nxentry.create_group("data")
        nxdata.attrs["NX_class"] = "NXdata"
        nxdata.attrs["signal"] = "R"
        nxdata.attrs["axes"] = "ar"
        ds = nxdata.create_dataset("ar", data=ar)
        ds.attrs["units"] = "degrees"
        ds = nxdata.create_dataset("R", data=R)
        ds.attrs["units"] = "not applicable"
        ds = nxdata.create_dataset("cen", data=[cen])
        ds.attrs["units"] = "degrees"
コード例 #2
0
ファイル: scanplots.py プロジェクト: APS-USAXS/livedata
def get_USAXS_FlyScan_Data(scan_obj):
    scan = scan_obj.spec_scan
    hdf5_file = get_Hdf5_Data_file_Name(scan)

    try:
        fly = reduceFlyData.UsaxsFlyScan(hdf5_file)  # checks if file exists
        #fly.make_archive()
        fly.reduce()        # open the file in this step
        fly.save(hdf5_file, 'full')
        if 'full' not in fly.reduced:
            return None
        fly.rebin(localConfig.REDUCED_FLY_SCAN_BINS)
        fly.save(hdf5_file, str(localConfig.REDUCED_FLY_SCAN_BINS))
    except IOError:
        return None     # file may not be available yet for reading if fly scan is still going
    except KeyError as exc:
        logger.info('HDF5 file:' + hdf5_file)
        raise KeyError(exc)
    except reduceFlyData.NoFlyScanData as _exc:
        logger.info(str(_exc))
        return None     # HDF5 file exists but length of raw data is zero

    fname = os.path.splitext(os.path.split(hdf5_file)[-1])[0]
    title = 'S%s %s (%s)' % (str(scan.scanNum), fname, 'fly')
    numbins_str = str(localConfig.REDUCED_FLY_SCAN_BINS)
    if numbins_str not in fly.reduced:
        return None
    rebinned = fly.reduced[numbins_str]
    entry = dict(qVec=rebinned['Q'], rVec=rebinned['R'], title=title)
    return entry
コード例 #3
0
def test_flyScan(filename):
    '''test data reduction from a flyScan (in an HDF5 file)'''
    if not os.path.exists(filename):
        raise FileNotFound(filename)

    import reduceFlyData
    fs = reduceFlyData.UsaxsFlyScan(filename)
    # compute the R(Q) profile
    fs.reduce()
    usaxs = fs.reduced
    return usaxs
コード例 #4
0
ファイル: repair_old.py プロジェクト: APS-USAXS/livedata
def main():
    owd = os.getcwd()
    testpath = os.path.join('testdata', '2014-04', '*_fly')
    for path in sorted(glob.glob(testpath)):
        os.chdir(path)
        for hfile in sorted(glob.glob('S*.h5')):
            print path, hfile
            copy_from_archive(ARCHIVE_SUBDIR_NAME, hfile)
            ufs = reduceFlyData.UsaxsFlyScan(hfile)
            #ufs.make_archive()
            #ufs.read_reduced()
            ufs.reduce()
            ufs.rebin(REDUCED_FLY_SCAN_BINS)
            ufs.save(hfile, 'full')
            ufs.save(hfile, REDUCED_FLY_SCAN_BINS)
        os.chdir(owd)
コード例 #5
0
ファイル: specplot.py プロジェクト: APS-USAXS/livedata
def retrieve_flyScanData(scan):
    '''retrieve reduced, rebinned data from USAXS Fly Scans'''
    if hasattr(scan, "MD") and scan.MD.get("hdf5_path") is not None:
        # Bluesky wrote this SPEC data file
        path = scan.MD.get("hdf5_path")
        hdf_file_name = scan.MD.get("hdf5_file")
    else:
        # SPEC wrote this data file
        key_string = 'FlyScan file name = '
        hdf_file_name = ""  # in case key_string is not found
        for comment in scan.comments:
            if key_string in comment:
                index = comment.find(key_string) + len(key_string)
                path = os.path.dirname(scan.header.parent.fileName)
                hdf_file_name = comment[index:-1]
                break
    abs_file = os.path.abspath(os.path.join(path, hdf_file_name))
    if os.path.exists(abs_file):
        s_num_bins = str(localConfig.REDUCED_FLY_SCAN_BINS)
        ufs = reduceFlyData.UsaxsFlyScan(abs_file)
        ufs.read_reduced()

        needs_calc = dict(full=not ufs.has_reduced('full'))
        needs_calc[s_num_bins] = not ufs.has_reduced(s_num_bins)
        if needs_calc['full']:
            #ufs.make_archive()
            ufs.reduce()
            ufs.save(abs_file, 'full')
            needs_calc[s_num_bins] = True
        if needs_calc[s_num_bins]:
            ufs.rebin(localConfig.REDUCED_FLY_SCAN_BINS)
            ufs.save(abs_file, s_num_bins)

        Q = ufs.reduced[s_num_bins]['Q']
        R = ufs.reduced[s_num_bins]['R']
        plotData = (Q, R)
    else:
        plotData = []
    return plotData
コード例 #6
0
ファイル: try_reduce.py プロジェクト: APS-USAXS/livedata
def main():
    #reduction_test()
    testpath = os.path.join('testdata', '2014-04', '04_14_Winans_fly', '*.h5')
    #testpath = os.path.join('testdata', '*.h5')

    # clear the test output files
    for hfile in glob.glob(os.path.join('/tmp', 'reduced_*.h5')):
        os.remove(hfile)

    counter = 0
    for hdf_file_name in sorted(glob.glob(testpath)):
        print hdf_file_name
        ufs = reduceFlyData.UsaxsFlyScan(hdf_file_name)
        counter += 1
        hfile = os.path.join('/tmp', 'reduced_%04d.h5' % counter)

        #ufs.make_archive()
        #ufs.read_reduced()
        ufs.reduce()
        ufs.rebin(REDUCED_FLY_SCAN_BINS)
        ufs.save(hfile, 'full')
        ufs.save(hfile, REDUCED_FLY_SCAN_BINS)