示例#1
0
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
示例#2
0
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")))