예제 #1
0
def test_copy_dbase(pstore):
    conn2 = pst.DictConnector("destination")
    pst.util.copy_database(pstore.conn,
                           conn2,
                           overwrite=False,
                           progressbar=True)
    return
예제 #2
0
def prj(request):
    if request.param == "arctic":
        connstr = "mongodb://localhost:27017/"
        name = "test_project"
        arc = arctic.Arctic(connstr)
        if name in [lib.split(".")[0] for lib in arc.list_libraries()]:
            connector = pst.ArcticConnector(name, connstr)
            prj = pst.PastaStore(name, connector)
        else:
            connector = pst.ArcticConnector(name, connstr)
            prj = initialize_project(connector)
    elif request.param == "pystore":
        name = "test_project"
        path = "./tests/data/pystore"
        pystore.set_path(path)
        if name in pystore.list_stores():
            connector = pst.PystoreConnector(name, path)
            prj = pst.PastaStore(name, connector)
        else:
            connector = pst.PystoreConnector(name, path)
            prj = initialize_project(connector)
    elif request.param == "dict":
        name = "test_project"
        connector = pst.DictConnector(name)
        prj = initialize_project(connector)
    prj.type = request.param  # added here for defining test dependencies
    yield prj
예제 #3
0
def test_to_from_zip(pstore):
    zipname = f"test_{pstore.type}.zip"
    pstore.to_zip(zipname, progressbar=False, overwrite=True)
    conn = pst.DictConnector("test")
    try:
        store = pst.PastaStore.from_zip(zipname, conn)
        assert not store.oseries.empty
    finally:
        os.remove(zipname)
    return store
예제 #4
0
def create_pastastore(oc,
                      pstore,
                      pstore_name='',
                      conn=pst.DictConnector("my_conn"),
                      add_metadata=True,
                      obs_column='stand_m_tov_nap',
                      kind='oseries',
                      verbose=False):
    """add observations to a new or existing pastastore

    Parameters
    ----------
    oc : observation.ObsCollection
        collection of observations
    pstore : pastastore.PastasProject, optional
        Existing pastastore, if None a new project is created
    pstore_name : str, optional
        Name of the pastastore only used if pstore is None
    conn : pastastore.connectors
        connector for database
    obs_column : str, optional
        Name of the column in the Obs dataframe to be used
    kind : str, optional
        The kind of series that is added to the pastas project
    add_metadata : boolean, optional
        If True metadata from the observations added to the project.
    verbose : boolean, optional
        Print additional information to the screen (default is False).

    Returns
    -------
    pstore : pastastore.PastasProject
        the pastas project with the series from the ObsCollection
    """
    if pstore is None:
        pstore = pst.PastaStore(pstore_name, connector=conn)

    for o in oc.obs.values:
        if verbose:
            print('add to pastastore -> {}'.format(o.name))

        if add_metadata:
            meta = _get_metadata_from_obs(o, verbose=verbose)
        else:
            meta = dict()

        if kind == 'oseries':
            pstore.conn.add_oseries(o[obs_column], o.name, metadata=meta)
        else:
            pstore.conn.add_stress(o[obs_column], o.name, kind, metadata=meta)

    return pstore
예제 #5
0
def pr(request):
    """Fixture that yields connection object.
    """
    name = f"test_{request.param}"
    # connect to dbase
    if request.param == "arctic":
        connstr = "mongodb://localhost:27017/"
        pr = pst.ArcticConnector(name, connstr)
    elif request.param == "pystore":
        path = "./tests/data/pystore"
        pr = pst.PystoreConnector(name, path)
    elif request.param == "dict":
        pr = pst.DictConnector(name)
    pr.type = request.param  # added here for defining test dependencies
    yield pr
예제 #6
0
def conn(request):
    """Fixture that yields connection object.
    """
    name = f"test_{request.param}"
    # connect to dbase
    if request.param == "arctic":
        connstr = "mongodb://localhost:27017/"
        conn = pst.ArcticConnector(name, connstr)
    elif request.param == "pystore":
        path = "./tests/data/pystore"
        conn = pst.PystoreConnector(name, path)
    elif request.param == "dict":
        conn = pst.DictConnector(name)
    elif request.param == "pas":
        conn = pst.PasConnector(name, "./tests/data/pas")
    else:
        raise ValueError("Unrecognized parameter!")
    conn.type = request.param  # added here for defining test dependencies
    yield conn
예제 #7
0
def pstore(request):
    if request.param == "arctic":
        connstr = "mongodb://localhost:27017/"
        name = "test_project"
        connector = pst.ArcticConnector(name, connstr)
    elif request.param == "pystore":
        name = "test_project"
        path = "./tests/data/pystore"
        pystore.set_path(path)
        connector = pst.PystoreConnector(name, path)
    elif request.param == "dict":
        name = "test_project"
        connector = pst.DictConnector(name)
    elif request.param == "pas":
        name = "test_project"
        connector = pst.PasConnector(name, "./tests/data/pas")
    else:
        raise ValueError("Unrecognized parameter!")
    pstore = initialize_project(connector)
    pstore.type = request.param  # added here for defining test dependencies
    yield pstore