Esempio n. 1
0
def test_hdf5_runtime_error(db_all, RE):
    RE.subscribe(db_all.insert)
    RE(count([det], 5, delay=0.1), owner="Tom")
    hdr = db_all[-1]
    fname = tempfile.NamedTemporaryFile()
    if hasattr(hdr, 'db'):
        hdf5.export(hdr, fname.name, db=None)
    else:
        with pytest.raises(RuntimeError):
            hdf5.export(hdr, fname.name, db=None)
Esempio n. 2
0
def test_hdf5_export_single():
    """
    Test the hdf5 export with a single header and
    verify the output is correct
    """
    temperature_ramp.run()
    hdr = db[-1]
    fname = tempfile.NamedTemporaryFile()
    hdf5.export(hdr, fname.name)
    shallow_header_verify(fname.name, hdr)
Esempio n. 3
0
def test_hdf5_export_single():
    """
    Test the hdf5 export with a single header and
    verify the output is correct
    """
    temperature_ramp.run()
    hdr = db[-1]
    fname = tempfile.NamedTemporaryFile()
    hdf5.export(hdr, fname.name)
    shallow_header_verify(fname.name, hdr)
Esempio n. 4
0
def test_hdf5_export_single_no_uid(db_all, RE, hw):
    """
    Test the hdf5 export with a single header and
    verify the output is correct. No uid is used.
    """
    RE.subscribe(db_all.insert)
    hw.motor.delay = 0.1
    RE(scan([hw.det], hw.motor, -1, 1, 10), owner="Tom")
    hdr = db_all[-1]
    fname = tempfile.NamedTemporaryFile()
    hdf5.export(hdr, fname.name, use_uid=False, db=db_all)
    shallow_header_verify(fname.name, hdr, db_all, use_uid=False)
Esempio n. 5
0
def test_hdf5_export_with_fields_single(db_all, RE, hw):
    """
    Test the hdf5 export with a single header and
    verify the output is correct; fields kwd is used.
    """
    RE.subscribe(db_all.insert)
    hw.motor.delay = 0.1
    RE(scan([hw.det], hw.motor, -1, 1, 10), owner="Tom")
    hdr = db_all[-1]
    fname = tempfile.NamedTemporaryFile()
    hdf5.export(hdr, fname.name, fields=['point_dev'])  #, db=db_all)
    shallow_header_verify(fname.name, hdr, db_all, fields=['point_dev'])
Esempio n. 6
0
def test_hdf5_export_single_stream_name(mds_all):
    """
    Test the hdf5 export with a single header and
    verify the output is correct. No uid is used.
    """
    mds = mds_all
    temperature_ramp.run(mds)
    db = Broker(mds, fs=None)
    hdr = db[-1]
    fname = tempfile.NamedTemporaryFile()
    hdf5.export(hdr, fname.name, mds, stream_name='primary')
    shallow_header_verify(fname.name, hdr, mds, stream_name='primary')
Esempio n. 7
0
def test_hdf5_export_with_fields_single(mds_all):
    """
    Test the hdf5 export with a single header and
    verify the output is correct; fields kwd is used.
    """
    mds = mds_all
    temperature_ramp.run(mds)
    db = Broker(mds, fs=None)
    hdr = db[-1]
    fname = tempfile.NamedTemporaryFile()
    hdf5.export(hdr, fname.name, mds, fields=['point_dev'])
    shallow_header_verify(fname.name, hdr, mds, fields=['point_dev'])
Esempio n. 8
0
def test_hdf5_export_list():
    """
    Test the hdf5 export with a list of headers and
    verify the output is correct
    """
    temperature_ramp.run()
    temperature_ramp.run()
    hdrs = db[-2:]
    fname = tempfile.NamedTemporaryFile()
    # test exporting a list of headers
    hdf5.export(hdrs, fname.name)
    for hdr in hdrs:
        shallow_header_verify(fname.name, hdr)
Esempio n. 9
0
def test_hdf5_export_list():
    """
    Test the hdf5 export with a list of headers and
    verify the output is correct
    """
    temperature_ramp.run()
    temperature_ramp.run()
    hdrs = db[-2:]
    fname = tempfile.NamedTemporaryFile()
    # test exporting a list of headers
    hdf5.export(hdrs, fname.name)
    for hdr in hdrs:
        shallow_header_verify(fname.name, hdr)
Esempio n. 10
0
def ESM_export(scan_ID, filename):
    '''
        This routine is used to export a data file to an HDF5 file for transfer to other analysis
        software.

        PARAMETERS
        ----------

        scan_ID : list.
            The scan id numbers (as a list) for the data to export, can be -1, -2 to indicate the last
            or second to last scan etc.

        filename : str.
            The filename to use for the output data file.

        filestring : str, output
            The file path, and file name, of the file that was created.

        '''
    #reference the header file for the scan to be saved.
    hdr = db[scan_ID]

    # check if the filename includes the '.h5' extension and add it if not.
    if not filename.endswith('.h5'):
        filename += '.h5'

    # give the filepath of where to store the h5 file
    filepath = '/direct/XF21ID1/hdf5_files/' + datetime.today().strftime(
        '%Y_%m')

    #check if a current month directory exists, if not create it.
    if not os.path.exists(filepath):
        os.makedirs(filepath)

    #create the file path and file name string
    filestring = filepath + '/' + filename

    #check if the file already exists, if so ask user if overwrite is necesary.
    if os.path.isfile(filestring):
        if ask_user_continue(
                'The file already exists, continuing will overwrite it') == 0:
            raise RuntimeError('user quit save')

        else:
            os.remove(filestring)

    # actually write the new file
    hdf5.export(hdr, filestring)

    # return the file path and file name so the user can find it.
    return filestring
Esempio n. 11
0
def test_hdf5_export_list(db_all, RE):
    """
    Test the hdf5 export with a list of headers and
    verify the output is correct
    """
    RE.subscribe(db_all.insert)
    RE(count([det], 5, delay=0.1), owner="Tom")
    RE(count([det], 6, delay=0.1), owner="Ken")
    hdrs = db_all[-2:]
    fname = tempfile.NamedTemporaryFile()
    # test exporting a list of headers
    hdf5.export(hdrs, fname.name, db=db_all)
    for hdr in hdrs:
        shallow_header_verify(fname.name, hdr, db=db_all)
Esempio n. 12
0
def test_hdf5_export_list(mds_all):
    """
    Test the hdf5 export with a list of headers and
    verify the output is correct
    """
    mds = mds_all
    temperature_ramp.run(mds)
    temperature_ramp.run(mds)
    db = Broker(mds, fs=None)
    hdrs = db[-2:]
    fname = tempfile.NamedTemporaryFile()
    # test exporting a list of headers
    hdf5.export(hdrs, fname.name, mds)
    for hdr in hdrs:
        shallow_header_verify(fname.name, hdr, mds)