예제 #1
0
 def setUp(self):
     global test_file_large
     hdf5file = test_file_large[:-4]+'.hdf5'
     hdf5file = os.path.join('data', hdf5file)
     
     try:
        with open(hdf5file):
            pass
     except IOError:
        daq = Daq()
        daq.read(os.path.join('data', test_file_large))
        daq.write_hd5(hdf5file)
예제 #2
0
 def setUp(self):
     global test_file_large
     hdf5file = test_file_large[:-4]+'.hdf5'
     hdf5file = os.path.join('data', hdf5file)
     
     try:
        with open(hdf5file):
            pass
     except IOError:
        daq = Daq()
        daq.read(os.path.join('data', test_file_large))
        daq.write_hd5(hdf5file)
예제 #3
0
    def test_readwrite_no_data(self):
        global test_file
        hdf5file = os.path.join('tmp', test_file[:-4]+'_5.hdf5')
        
        daq = Daq()
        daq.read(os.path.join('data', test_file))
        daq.write_hd5(hdf5file)

        daq2 = Daq()
        daq2.read_hd5(hdf5file)

        assert_Daqs_equal(self, daq, daq2)
예제 #4
0
    def test_readwrite_with_elemlist_f0fend(self):
        global test_file
        hdf5file = os.path.join('tmp', test_file[:-4]+'_4.hdf5')
        
        daq = Daq()
        daq.load_elemlist_fromfile('elemList2.txt')
        with warnings.catch_warnings(record=True) as w:
            daq.read(os.path.join('data', test_file)) 
                              
        daq.write_hd5(hdf5file)

        daq2 = Daq()
        daq2.read_hd5(hdf5file, fend=8000)

        self.assertEqual(daq2.frame.frame[-1], 8000)
예제 #5
0
    def test_readwrite_with_elemlist(self):
        global test_file
        hdf5file = os.path.join('tmp', test_file[:-4]+'_2.hdf5')
        
        daq = Daq()
        daq.load_elemlist_fromfile('elemList2.txt')
        with warnings.catch_warnings(record=True) as w:
            daq.read(os.path.join('data', test_file)) 
            
                              
        daq.write_hd5(hdf5file)

        daq2 = Daq()
        daq2.read_hd5(hdf5file)

        assert_Daqs_equal(self, daq, daq2)
예제 #6
0
def attach_metadata(hd5_file):
    """
    The Daq files have an 'etc' dict attribute inteaded for users to
    store analysis relevant metadata. The etc dict can be exported to hdf5
    and reloaded from hdf5. We want to go through and build these dicts so
    that the information is at our fingertips when we need it.
    """
    
    global latin_square, wind_speeds

    t0 = time.time()

    tmp_file = hd5_file + '.tmp'

    # load hd5
    daq = Daq()
    daq.read_hd5(hd5_file)
    
    etc = {} # fill and pack in daq
    
    # find the real participant id (pid) from the file path
    etc['pid'] = int(hd5_file.split('\\')[0][4:])
    etc['scen_order'] = latin_square[(etc['pid']-1)%10]
    etc['wind_speeds'] = wind_speeds

    # now to find the epochs
    # epochs is a dictionary. The keys are the enumerated states and the
    # values are FrameSlice objects. The FrameSlice objects can be used
    # to slice the Elements in Daq instances.
    etc['epochs'] = find_epochs(daq['SCC_LogStreams'][0,:])

    daq.etc = etc # doing it this way ensures we know what is in there

    # write to temporary file.
    # once that completes, delete original hd5, and rename temporary file.
    # This protects you from yourself. If you get impatient and kill the
    # kernel there is way less risk of corrupting your hd5.
    daq.write_hd5(tmp_file)
    os.remove(hd5_file)
    os.rename(tmp_file, hd5_file)
    
    del daq

    return time.time() - t0
예제 #7
0
    def test_load_missing(self):
        """test a file with missing frames"""
        missing = 'Left_08_20130426164301.daq'

        try:
            with open(os.path.join('data', missing)):
                pass
        except:
            return
        
        daq = Daq()
        with warnings.catch_warnings(record=True) as w:
            daq.read(os.path.join('data', missing))

        daq.write_hd5(os.path.join('tmp', 'partial.hdf5'))
        
        daq2 = Daq()
        daq2.read_hd5(os.path.join('tmp', 'partial.hdf5'))

        assert_Daqs_equal(self, daq, daq2)        
예제 #8
0
from undaqTools import Daq

if __name__ == '__main__':
    
    for test_file in ['./data/data reduction_20130204125617.daq',
                      './data/Alaska_0_20130301142422.daq']:
        
        hdf5file = test_file[:-4]+'.hdf5'
        
        try:
           with open(hdf5file):
               pass
        except IOError:
           daq = Daq()
           daq.read(test_file)
           daq.write_hd5(hdf5file)
예제 #9
0
 def test_process(self):
     global test_file_large
             
     daq = Daq()
     daq.read(os.path.join('data', test_file_large))
     daq.write_hd5('./tmp/dynobj_process_test.hdf5')