Пример #1
0
def test_fiducialTracks_Put_Data():
    """The datasetType can put its own data and datasetIDs.
    
    """
    try:
        # Make up some dataset IDs and a dataset
        dsIDs           = {}
        dsIDs['prefix'] = 'test_prefix'
        dsIDs['acqID']  = 1
        ds      = FiducialTracks(datasetIDs = dsIDs)
        ds.data = pd.DataFrame({'A' : [1,2], 'B' : [3,4]})
        
        pathToDB = testDataRoot
        # Remove datastore if it exists
        if exists(str(pathToDB / Path('test_db.h5'))):
            remove(str(pathToDB / Path('test_db.h5')))
        
        myDB = db.HDFDatastore(pathToDB / Path('test_db.h5'))
        myDB.put(ds)
        
        key = 'test_prefix/test_prefix_1/FiducialTracks'
        with h5py.File(str(pathToDB / Path('test_db.h5')), 'r') as hdf:
            assert_equal(hdf[key].attrs['SMLM_datasetType'], 'FiducialTracks')
        
        df = pd.read_hdf(str(pathToDB / Path('test_db.h5')), key = key)
        assert_equal(df.loc[0, 'A'], 1)
        assert_equal(df.loc[1, 'A'], 2)
        assert_equal(df.loc[0, 'B'], 3)
        assert_equal(df.loc[1, 'B'], 4)
    finally:
        # Remove the test datastore
        remove(str(pathToDB / Path('test_db.h5')))
Пример #2
0
def test_fiducialTracks_Put_Data():
    """The datasetType can put its own data and datasetIDs.
    
    """
    try:
        # Make up some dataset IDs and a dataset
        dsIDs = {}
        dsIDs['prefix'] = 'test_prefix'
        dsIDs['acqID'] = 1
        ds = FiducialTracks(datasetIDs=dsIDs)
        ds.data = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})

        pathToDB = testDataRoot
        # Remove datastore if it exists
        if exists(str(pathToDB / Path('test_db.h5'))):
            remove(str(pathToDB / Path('test_db.h5')))

        with db.HDFDatastore(pathToDB / Path('test_db.h5')) as myDB:
            myDB.put(ds)

        key = 'test_prefix/test_prefix_1/FiducialTracks'
        with h5py.File(str(pathToDB / Path('test_db.h5')), 'r') as hdf:
            assert_equal(hdf[key].attrs['SMLM_datasetType'], 'FiducialTracks')

        df = pd.read_hdf(str(pathToDB / Path('test_db.h5')), key=key)
        assert_equal(df.loc[0, 'A'], 1)
        assert_equal(df.loc[1, 'A'], 2)
        assert_equal(df.loc[0, 'B'], 3)
        assert_equal(df.loc[1, 'B'], 4)
    finally:
        # Remove the test datastore
        remove(str(pathToDB / Path('test_db.h5')))
Пример #3
0
def test__repr__():
    """DatasetType generates the correct __repr__ string.
    
    """
    dsIDs           = {}
    dsIDs['prefix'] = 'test_prefix'
    
    ds = FiducialTracks(datasetIDs = dsIDs)
    
    assert_equal(ds.__repr__(), 'FiducialTracks: {\'prefix\': \'test_prefix\'}')
    
    del(ds.datasetIDs['prefix'])
    assert_equal(ds.__repr__(), 'FiducialTracks: {}')
Пример #4
0
def test__repr__():
    """DatasetType generates the correct __repr__ string.
    
    """
    dsIDs = {}
    dsIDs['prefix'] = 'test_prefix'

    ds = FiducialTracks(datasetIDs=dsIDs)

    assert_equal(ds.__repr__(),
                 'FiducialTracks: {\'prefix\': \'test_prefix\'}')

    del (ds.datasetIDs['prefix'])
    assert_equal(ds.__repr__(), 'FiducialTracks: {}')
Пример #5
0
def test_fiducialTracks_Instantiation():
    """The datasetType is properly instantiated.
    
    """
    # Make up some dataset IDs
    dsIDs = {}
    dsIDs['prefix'] = 'test_prefix'
    dsIDs['acqID'] = 1

    FiducialTracks(datasetIDs=dsIDs)
Пример #6
0
def test_fiducialTracks_Get_Data():
    """The datasetType can get its own data and datasetIDs.
    
    """
    try:
        # Make up some dataset IDs and a dataset
        dsIDs = {}
        dsIDs['prefix'] = 'test_prefix'
        dsIDs['acqID'] = 1
        ds = FiducialTracks(datasetIDs=dsIDs)
        ds.data = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})

        pathToDB = testDataRoot
        # Remove datastore if it exists
        if exists(str(pathToDB / Path('test_db.h5'))):
            remove(str(pathToDB / Path('test_db.h5')))

        with db.HDFDatastore(pathToDB / Path('test_db.h5')) as myDB:
            myDB.put(ds)

        # Create a new dataset containing only IDs to test getting of the data
        myNewDSID = db.DatasetID('test_prefix', 1, 'FiducialTracks', None,
                                 None, None, None, None, None)
        myNewDS = myDB.get(myNewDSID)
        ids = myNewDS.datasetIDs
        assert_equal(ids['prefix'], 'test_prefix')
        assert_equal(ids['acqID'], 1)
        assert_equal(myNewDS.datasetType, 'FiducialTracks')
        assert_equal(ids['channelID'], None)
        assert_equal(ids['dateID'], None)
        assert_equal(ids['posID'], None)
        assert_equal(ids['sliceID'], None)
        assert_equal(ids['replicateID'], None)
        assert_equal(myNewDS.data.loc[0, 'A'], 1)
        assert_equal(myNewDS.data.loc[1, 'A'], 2)
        assert_equal(myNewDS.data.loc[0, 'B'], 3)
        assert_equal(myNewDS.data.loc[1, 'B'], 4)
    finally:
        # Remove the test datastore
        remove(str(pathToDB / Path('test_db.h5')))
Пример #7
0
def test_fiducialTracks_Get_Data():
    """The datasetType can get its own data and datasetIDs.
    
    """
    try:
        # Make up some dataset IDs and a dataset
        dsIDs           = {}
        dsIDs['prefix'] = 'test_prefix'
        dsIDs['acqID']  = 1
        ds      = FiducialTracks(datasetIDs = dsIDs)
        ds.data = pd.DataFrame({'A' : [1,2], 'B' : [3,4]})
        
        pathToDB = testDataRoot
        # Remove datastore if it exists
        if exists(str(pathToDB / Path('test_db.h5'))):
            remove(str(pathToDB / Path('test_db.h5')))
        
        myDB = db.HDFDatastore(pathToDB / Path('test_db.h5'))
        myDB.put(ds)
        
        # Create a new dataset containing only IDs to test getting of the data
        myNewDSID = myDB.dsID('test_prefix', 1, 'FiducialTracks', None,
                              None, None, None, None)
        myNewDS = myDB.get(myNewDSID)
        ids     = myNewDS.datasetIDs
        assert_equal(ids['prefix'],              'test_prefix')
        assert_equal(ids['acqID'],                           1)
        assert_equal(myNewDS.datasetType,     'FiducialTracks')
        assert_equal(ids['channelID'],                    None)
        assert_equal(ids['dateID'],                       None)
        assert_equal(ids['posID'],                        None)
        assert_equal(ids['sliceID'],                      None)   
        assert_equal(myNewDS.data.loc[0, 'A'], 1)
        assert_equal(myNewDS.data.loc[1, 'A'], 2)
        assert_equal(myNewDS.data.loc[0, 'B'], 3)
        assert_equal(myNewDS.data.loc[1, 'B'], 4)
    finally:
        # Remove the test datastore
        remove(str(pathToDB / Path('test_db.h5')))