pastas / pastastore

:spaghetti: :convenience_store: Tools for managing timeseries and Pastas models

Home Page:https://pastastore.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when parsing model dict because of the series names

OnnoEbbens opened this issue · comments

I create a pastas model and add a Stressmodel to it. Then I add this model to a Pastastore using the following code:

ml = ps.Model(df['stand_m_tov_nap'], name='tm')
w1 = ps.StressModel(df['Volume_sum'], rfunc=ps.Hantush, name='well_totaal', settings='well', up=False)
ml.add_stressmodel(w1)
pstore = pst.PastaStore('test',connector=pst.DictConnector("my_conn"))

pstore.add_model(ml)

Then when I try to retrieve with pstore.get_models('tm') the model I get this error:

Traceback (most recent call last):

  File "<ipython-input-150-256e244d4d4a>", line 1, in <module>
    pstore.get_models('tm')

  File "c:\users\oebbe\02_python\pastastore\pastastore\connectors.py", line 1372, in get_models
    ml = self._parse_model_dict(data)

  File "c:\users\oebbe\02_python\pastastore\pastastore\base.py", line 341, in _parse_model_dict
    raise LookupError(msg)

LookupError: oseries stand_m_tov_nap not present in project

Now I understand that I have to add the oseries and stresses to the pastastore seperately. So I use:

pstore = pst.PastaStore('test',connector=pst.DictConnector("my_conn"))
pstore.add_oseries(df['stand_m_tov_nap'], name='to')
pstore.add_stress(df['Volume_sum'], name='ts')
pstore.add_model(ml)

But still I get the same error when using pstore.get_models('tm'). This is because the oseries is added to the pastastore under the name 'to' while the model dictionary saves the stress series under the name 'stand_m_tov_nap'. This is the name of the pandas Series that was used to create the oseries.

I think this has to do with the way a model is added to the pastastore but I don't know how to solve it.

The pastastore was designed to build models from timeseries stored in the oseries/stresses. When adding a model it is assumed the timeseries are also present in the store. So if you build a model from timeseries not contained in the pastastore, it will happily add the model, but will not be able to re-create it when loading it.

Generally, it is easier to add your oseries/stresses to the Pastastore and build your models from there. Your approach should work however, but the name of the series is different in the model than in the pastastore. I think if you set the name to 'stand_m_tov_nap' it should work:

pstore.add_oseries(df['stand_m_tov_nap'], name='stand_m_tov_nap')

A better idea is probably to rename your series before building the model to give it a more unique name:

oseries = df['stand_m_tov_nap']
oseries.name = "piezometer_xx"
# build model, etc... 

Based on your issue, I think we can improve the behavior of the pastastore. I can make it so that when you add a model for which the timeseries are not present in the pastastore, it automatically adds those timeseries for you.

58b9359 adds functionality when adding a model that checks whether the oseries and stresses are contained in the PastaStore. If they cannot be found, the timeseries are added to the PastaStore. A test was added to ensure this works.

@OnnoEbbens, let me know if the issue can be closed!

Closed by #12