Skip to content

Commit

Permalink
Update dataframes import/export (#2351)
Browse files Browse the repository at this point in the history
* Update pandas.py

* add doc + fix scales

* fix venv and BLAS

* fix tests

* revert BLAS changes

* Update scripts/installAmiciArchive.sh

---------

Co-authored-by: Daniel Weindl <[email protected]>
  • Loading branch information
FFroehlich and dweindl authored Mar 7, 2024
1 parent 2316f2a commit 9824aba
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
57 changes: 55 additions & 2 deletions python/sdist/amici/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,20 @@ def _fill_conditions_dict(
]
else:
datadict[par + "_presim"] = np.nan

for i_par, par in enumerate(
_get_names_or_ids(model, "Parameter", by_id=by_id)
):
if len(edata.parameters):
datadict[par] = edata.parameters[i_par]
else:
datadict[par] = model.getParameters()[i_par]

if len(edata.pscale):
datadict[par + "_scale"] = edata.pscale[i_par]
else:
datadict[par + "_scale"] = model.getParameterScale()[i_par]

return datadict


Expand Down Expand Up @@ -438,6 +452,11 @@ def _get_extended_observable_cols(model: AmiciModel, by_id: bool) -> list[str]:
name + "_presim"
for name in _get_names_or_ids(model, "FixedParameter", by_id=by_id)
]
+ _get_names_or_ids(model, "Parameter", by_id=by_id)
+ [
name + "_scale"
for name in _get_names_or_ids(model, "Parameter", by_id=by_id)
]
+ _get_names_or_ids(model, "Observable", by_id=by_id)
+ [
name + "_std"
Expand Down Expand Up @@ -471,6 +490,11 @@ def _get_observable_cols(model: AmiciModel, by_id: bool) -> list[str]:
name + "_presim"
for name in _get_names_or_ids(model, "FixedParameter", by_id=by_id)
]
+ _get_names_or_ids(model, "Parameter", by_id=by_id)
+ [
name + "_scale"
for name in _get_names_or_ids(model, "Parameter", by_id=by_id)
]
+ _get_names_or_ids(model, "Observable", by_id=by_id)
)

Expand Down Expand Up @@ -500,6 +524,11 @@ def _get_state_cols(model: AmiciModel, by_id: bool) -> list[str]:
name + "_presim"
for name in _get_names_or_ids(model, "FixedParameter", by_id=by_id)
]
+ _get_names_or_ids(model, "Parameter", by_id=by_id)
+ [
name + "_scale"
for name in _get_names_or_ids(model, "Parameter", by_id=by_id)
]
+ _get_names_or_ids(model, "State", by_id=by_id)
)

Expand Down Expand Up @@ -528,6 +557,11 @@ def _get_expression_cols(model: AmiciModel, by_id: bool) -> list[str]:
name + "_presim"
for name in _get_names_or_ids(model, "FixedParameter", by_id=by_id)
]
+ _get_names_or_ids(model, "Parameter", by_id=by_id)
+ [
name + "_scale"
for name in _get_names_or_ids(model, "Parameter", by_id=by_id)
]
+ _get_names_or_ids(model, "Expression", by_id=by_id)
)

Expand Down Expand Up @@ -641,10 +675,11 @@ def constructEdataFromDataFrame(
Model instance.
:param condition:
pd.Series with FixedParameter Names/Ids as columns.
pd.Series with (Fixed)Parameter Names/Ids as columns.
Preequilibration conditions may be specified by appending
'_preeq' as suffix. Presimulation conditions may be specified by
appending '_presim' as suffix.
appending '_presim' as suffix. Parameter scales may be specified by
appending '_scale' as suffix.
:param by_id:
Indicate whether in the arguments, column headers are based on ids or
Expand Down Expand Up @@ -681,6 +716,20 @@ def constructEdataFromDataFrame(
.values
)

# fill in parameters
edata.parameters = (
condition[_get_names_or_ids(model, "Parameter", by_id=by_id)]
.astype(float)
.values
)

edata.pscale = amici.parameterScalingFromIntVector(
[
amici.ParameterScaling(condition[par + "_scale"].astype(int))
for par in list(_get_names_or_ids(model, "Parameter", by_id=by_id))
]
)

# fill in preequilibration parameters
if any(
[overwrite_preeq[key] != condition[key] for key in overwrite_preeq]
Expand Down Expand Up @@ -767,6 +816,10 @@ def getEdataFromDataFrame(
condition_parameters.append(par + "_preeq")
if par + "_presim" in df.columns:
condition_parameters.append(par + "_presim")
# parameters & scales
for par in _get_names_or_ids(model, "Parameter", by_id=by_id):
condition_parameters.append(par)
condition_parameters.append(par + "_scale")
# presimulation time
if "t_presim" in df.columns:
condition_parameters.append("t_presim")
Expand Down
1 change: 0 additions & 1 deletion scripts/buildAmici.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ fi

# set python executable for cmake
export PYTHON_EXECUTABLE="${amici_path}/venv/bin/python"
# install numpy
python3 -m pip install numpy

${cmake} \
Expand Down

0 comments on commit 9824aba

Please sign in to comment.