Esempio n. 1
0
def test_averageFiducial_Put_Data():
    """averageFiducial 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 = AverageFiducial(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/AverageFiducial'
        with h5py.File(str(pathToDB / Path('test_db.h5')), 'r') as hdf:
            assert_equal(hdf[key].attrs['SMLM_datasetType'], 'AverageFiducial')

        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')))
Esempio n. 2
0
def test_averageFiducial_Put_Data():
    """averageFiducial 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 = AverageFiducial(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/AverageFiducial"
        with h5py.File(str(pathToDB / Path("test_db.h5")), "r") as hdf:
            assert_equal(hdf[key].attrs["SMLM_datasetType"], "AverageFiducial")

        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")))
Esempio n. 3
0
def test__repr__():
    """DatasetType generates the correct __repr__ string.
    
    """
    dsIDs = {}
    dsIDs["prefix"] = "test_prefix"

    ds = AverageFiducial(datasetIDs=dsIDs)

    assert_equal(ds.__repr__(), "AverageFiducial: {'prefix': 'test_prefix'}")

    del (ds.datasetIDs["prefix"])
    assert_equal(ds.__repr__(), "AverageFiducial: {}")
Esempio n. 4
0
def test__repr__():
    """DatasetType generates the correct __repr__ string.
    
    """
    dsIDs = {}
    dsIDs['prefix'] = 'test_prefix'

    ds = AverageFiducial(datasetIDs=dsIDs)

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

    del (ds.datasetIDs['prefix'])
    assert_equal(ds.__repr__(), 'AverageFiducial: {}')
Esempio n. 5
0
def test_averageFiducial_Instantiation():
    """testType is properly instantiated.
    
    """
    # Make up some dataset IDs
    dsIDs = {}
    dsIDs['prefix'] = 'test_prefix'
    dsIDs['acqID'] = 1

    AverageFiducial(datasetIDs=dsIDs)
Esempio n. 6
0
def test_averageFiducial_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 = AverageFiducial(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, 'AverageFiducial', 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, 'AverageFiducial')
        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')))
Esempio n. 7
0
def test_averageFiducial_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 = AverageFiducial(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, "AverageFiducial", 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, "AverageFiducial")
        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")))