Пример #1
0
def load_project(data):
    """Method to load a Pastas project.

    Parameters
    ----------
    data: dict
        Dictionary containing all information to construct the project.

    Returns
    -------
    mls: Pastas.Project class
        Pastas Project class object

    """

    mls = ps.Project(name=data["name"])

    mls.metadata = data["metadata"]
    mls.file_info = data["file_info"]

    oseries = DataFrame(data["oseries"], columns=data["oseries"].keys()).T
    mls.oseries = mls.oseries.append(oseries, sort=False)

    stresses = DataFrame(data=data["stresses"],
                         columns=data["stresses"].keys()).T
    mls.stresses = mls.stresses.append(stresses, sort=False)

    for ml_name, ml in data["models"].items():
        name = str(ml["oseries"]["name"])
        ml_name = str(ml_name)
        ml["oseries"]["series"] = mls.oseries.loc[name, "series"]
        if ml["stressmodels"]:
            for ts in ml["stressmodels"].values():
                for stress in ts["stress"]:
                    if 'series' not in stress:
                        # look up the stress-series in mls.stresses
                        stress_name = stress["name"]
                        if stress_name not in mls.stresses.index:
                            raise (ValueError(
                                '{} not found in stresses'.format(
                                    stress_name)))
                        stress["series"] = mls.stresses.loc[
                            stress_name, "series"]
        try:
            ml = load_model(ml)
            mls.models[ml_name] = ml
        except:
            try:
                mls.del_model(ml_name)
            except:
                pass
            print("model", ml_name, "could not be added")
    return mls
Пример #2
0
def create_pastas_project(oc,
                          pr=None,
                          project_name='',
                          obs_column='stand_m_tov_nap',
                          kind='oseries',
                          add_metadata=True,
                          verbose=False):
    """add observations to a new or existing pastas project

    Parameters
    ----------
    oc : observation.ObsCollection
        collection of observations
    pr : pastas.project, optional
        Existing pastas project, if None a new project is created
    project_name : str, optional
        Name of the pastas project only used if pr is None
    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
    -------
    pr : pastas.project
        the pastas project with the series from the ObsCollection
    """

    if pr is None:
        pr = ps.Project(project_name)

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

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

        series = ps.TimeSeries(o[obs_column], name=o.name, metadata=meta)
        pr.add_series(series, kind=kind)

    return pr
Пример #3
0
def load_project(data):
    """Method to load a Pastas project.

    Parameters
    ----------
    data: dict
        Dictionary containing all information to construct the project.

    Returns
    -------
    mls: Pastas.Project class
        Pastas Project class object

    """

    mls = ps.Project(name=data["name"])

    mls.metadata = data["metadata"]
    mls.file_info = data["file_info"]

    oseries = DataFrame(data["oseries"], columns=data["oseries"].keys()).T
    mls.oseries = mls.oseries.append(oseries)

    stresses = DataFrame(data=data["stresses"],
                         columns=data["stresses"].keys()).T
    mls.stresses = mls.stresses.append(stresses)

    for ml_name, ml in data["models"].items():
        name = str(ml["oseries"]["name"])
        ml_name = str(ml_name)
        ml["oseries"]["series"] = mls.oseries.loc[name, "series"]
        if ml["stressmodels"]:
            for ts in ml["stressmodels"].values():
                for i, stress in enumerate(ts["stress"]):
                    stress_name = stress["name"]
                    ts["stress"][i]["series"] = mls.stresses.loc[stress_name,
                                                                 "series"]
        try:
            ml = load_model(ml)
            mls.models[ml_name] = ml
        except:
            try:
                mls.del_model(ml_name)
            except:
                pass
            print("model", ml_name, "could not be added")
    return mls
Пример #4
0
def test_create_project():
    pr = ps.Project(name="test")
    return pr
Пример #5
0
def load_project(fname, **kwargs):
    """
    Method to load a Pastas project.

    Parameters
    ----------
    fname: str
        string with the name of the file to be imported including the file
        extension.
    kwargs:
        extension specific keyword arguments.

    Returns
    -------
    mls: pastas.project.Project
        Pastas Project class object

    Examples
    --------
    >>> import pastas as ps
    >>> mls = ps.io.load_project("project.pas")

    Warnings
    --------
    All classes and methods dealing with Pastas projects will be moved to a
    separate Python package in the near future (mid-2020).

    """
    # Dynamic import of the export module
    ext = path.splitext(fname)[1]
    load_mod = import_module("pastas.io" + ext)

    # Get dicts for all data sources
    data = load_mod.load(fname, **kwargs)

    mls = ps.Project(name=data["name"])

    mls.metadata = data["metadata"]
    mls.file_info = data["file_info"]

    oseries = DataFrame(data["oseries"], columns=data["oseries"].keys()).T
    mls.oseries = mls.oseries.append(oseries, sort=False)

    stresses = DataFrame(data=data["stresses"],
                         columns=data["stresses"].keys()).T
    mls.stresses = mls.stresses.append(stresses, sort=False)

    for ml_name, ml in data["models"].items():
        name = str(ml["oseries"]["name"])
        ml_name = str(ml_name)
        ml["oseries"]["series"] = mls.oseries.loc[name, "series"]
        if ml["stressmodels"]:
            for ts in ml["stressmodels"].values():
                for stress in ts["stress"]:
                    if 'series' not in stress:
                        # look up the stress-series in mls.stresses
                        stress_name = stress["name"]
                        if stress_name not in mls.stresses.index:
                            raise (ValueError(
                                '{} not found in stresses'.format(stress_name))
                                   )
                        stress["series"] = mls.stresses.loc[stress_name,
                                                            "series"]
        try:
            ml = _load_model(ml)
            mls.models[ml_name] = ml
        except:
            try:
                mls.del_model(ml_name)
            except:
                pass
            print("model", ml_name, "could not be added")

    logger.info("Pastas project from file {} successfully loaded. This file "
                "was created with Pastas {}. Your current version of Pastas "
                "is: {}".format(fname, data["file_info"]["pastas_version"],
                                ps.__version__))

    return mls
Пример #6
0
import pastas as ps

# Create a simple model taken from example.py
obs = pd.read_csv("data/head_nb1.csv",
                  index_col=0,
                  parse_dates=True,
                  squeeze=True)
rain = pd.read_csv("data/rain_nb1.csv",
                   index_col=0,
                   parse_dates=True,
                   squeeze=True)
evap = pd.read_csv("data/evap_nb1.csv",
                   index_col=0,
                   parse_dates=True,
                   squeeze=True)

# Create a Pastas Project
mls = ps.Project(name="test_project")

mls.add_oseries(obs, "GWL", metadata={})
mls.add_stress(rain, name="Prec", kind="prec")
mls.add_stress(evap, name="Evap", kind="evap")

ml = mls.add_model(oseries="GWL")

mls.add_recharge(ml)
mls.solve_models()

mls.to_file("test_project.pas")