def test_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 = Localizations(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/Localizations' with h5py.File(str(pathToDB / Path('test_db.h5')), 'r') as hdf: assert_equal(hdf[key].attrs['SMLM_datasetType'], 'Localizations') 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')))
def test_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 = Localizations(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/Localizations' with h5py.File(str(pathToDB / Path('test_db.h5')), 'r') as hdf: assert_equal(hdf[key].attrs['SMLM_datasetType'], 'Localizations') 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')))
def test__repr__(): """DatasetType generates the correct __repr__ string. """ dsIDs = {} dsIDs['prefix'] = 'test_prefix' ds = Localizations(datasetIDs=dsIDs) assert_equal(ds.__repr__(), 'Localizations: {\'prefix\': \'test_prefix\'}') del (ds.datasetIDs['prefix']) assert_equal(ds.__repr__(), 'Localizations: {}')
def test__repr__(): """DatasetType generates the correct __repr__ string. """ dsIDs = {} dsIDs['prefix'] = 'test_prefix' ds = Localizations(datasetIDs = dsIDs) assert_equal(ds.__repr__(), 'Localizations: {\'prefix\': \'test_prefix\'}') del(ds.datasetIDs['prefix']) assert_equal(ds.__repr__(), 'Localizations: {}')
def test_Instantiation(): """The datasetType is properly instantiated. """ # Make up some dataset IDs dsIDs = {} dsIDs['prefix'] = 'test_prefix' dsIDs['acqID'] = 1 Localizations(datasetIDs=dsIDs)
def test_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 = Localizations(datasetIDs=dsIDs) ds.data = pd.DataFrame({"A": [1, 2], "B": [3, 4]}) # Make up the attribute DatasetType dsAttr = LocMetadata(datasetIDs=dsIDs) dsAttr.data = {"A": 2, "B": "hello"} 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) myDB.put(dsAttr) # Test the get() function now. myNewDSID = myDB.dsID("test_prefix", 1, "LocMetadata", "Localizations", None, None, None, None) myNewDS = myDB.get(myNewDSID) ids = myNewDS.datasetIDs assert_equal(ids["prefix"], "test_prefix") assert_equal(ids["acqID"], 1) assert_equal(ids["channelID"], None) assert_equal(ids["dateID"], None) assert_equal(ids["posID"], None) assert_equal(ids["sliceID"], None) assert_equal(myNewDS.datasetType, "LocMetadata") assert_equal(myNewDS.data["A"], 2) assert_equal(myNewDS.data["B"], "hello") finally: # Remove the test datastore # remove(str(pathToDB / Path('test_db.h5'))) pass
def test_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 = Localizations(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, 'Localizations', 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, 'Localizations') 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')))
def test_Put_Data(): """The datasetType can put its own data and datasetIDs. """ mdPrefix = config.__HDF_Metadata_Prefix__ try: # Make up some dataset IDs and a dataset dsIDs = {} dsIDs["prefix"] = "test_prefix" dsIDs["acqID"] = 1 ds = Localizations(datasetIDs=dsIDs) ds.data = pd.DataFrame({"A": [1, 2], "B": [3, 4]}) # Make up the attribute DatasetType dsAttr = LocMetadata(datasetIDs=dsIDs) dsAttr.data = {"A": 2, "B": "hello"} 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) myDB.put(dsAttr) key = "test_prefix/test_prefix_1/Localizations" with h5py.File(str(pathToDB / Path("test_db.h5")), "r") as hdf: assert_equal(hdf[key].attrs["SMLM_datasetType"], "Localizations") assert_equal(hdf[key].attrs[mdPrefix + "A"], "2") assert_equal(hdf[key].attrs[mdPrefix + "B"], '"hello"') 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")))
def test_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 = Localizations(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, 'Localizations', 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, 'Localizations') 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')))