Skip to content

Commit

Permalink
Merge branch 'release/4.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
pauliacomi committed Mar 10, 2022
2 parents 2e490dc + d4571c8 commit 402010f
Show file tree
Hide file tree
Showing 31 changed files with 364 additions and 443 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
Changelog
=========

4.1.1 (2022-03-10)
------------------

Fixes:

* AIF file export now more reliable with custom properties
* Isotherm models correctly instantiate their variables (parameters would
otherwise be shared between instances)

4.1.0 (2022-03-02)
------------------

Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ or `Anaconda/Conda <https://www.anaconda.com/>`__:
If you are just starting out, `Anaconda/Conda <https://www.anaconda.com/>`__ is
a good bet since it manages virtual environments for you. Check out
`<https://pygaps.readthedocs.io/en/master/installation.html>`__ for more
details.
`Installation <https://pygaps.readthedocs.io/en/master/installation.html>`__ for
more details.

Development
===========
Expand All @@ -185,7 +185,7 @@ Then install the package with pip either in regular or developer mode.
If you want to contribute to pyGAPS or develop your own code from the package,
check out the detailed information in
`<https://pygaps.readthedocs.io/en/master/contributing.html>`.
`CONTRIBUTING.rst <https://pygaps.readthedocs.io/en/master/contributing.html>`__.

Bugs or questions?
==================
Expand Down
2 changes: 1 addition & 1 deletion conda_recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% set name = "pygaps" %}
{% set version = "4.1.0" %}
{% set version = "4.1.1" %}

package:
name: {{ name|lower }}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"
[tool.setuptools_scm]
write_to = "src/pygaps/_version.py"
local_scheme = 'dirty-tag'
fallback_version = '4.1.0'
fallback_version = '4.1.1'

# linting: pylint
[tool.pylint.basic]
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[bumpversion]
current_version = 4.1.0
current_version = 4.1.1
commit = True
tag = False
message = '{current_version} → {new_version}'

[metadata]
name = pygaps
version = 4.1.0
version = 4.1.1
description = A framework for processing adsorption data for porous materials.
long_description = file: README.rst
long_description_content_type = text/x-rst
Expand Down
2 changes: 1 addition & 1 deletion src/pygaps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ._version import version
__version__ = version
except ImportError:
__version__ = '4.1.0'
__version__ = '4.1.1'

import sys
from .logging import logger
Expand Down
39 changes: 12 additions & 27 deletions src/pygaps/core/modelisotherm.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ class ModelIsotherm(BaseIsotherm):

_reserved_params = BaseIsotherm._reserved_params + [
'model',
'param_guess',
'param_bounds',
]

##########################################################
Expand Down Expand Up @@ -189,45 +187,32 @@ def __init__(

# Name of analytical model to fit to pure-component isotherm data
# adsorption isotherm.
self.model = get_isotherm_model(model)
self.model = get_isotherm_model(
model,
pressure_range=(min(pressure), max(pressure)),
loading_range=(min(loading), max(loading)),
param_bounds=param_bounds,
)

# Pass odd parameters
self.model.__init_parameters__(other_properties)

# The pressure range on which the model was built.
self.model.pressure_range = [min(pressure), max(pressure)]

# The loading range on which the model was built.
self.model.loading_range = [min(loading), max(loading)]

# Override defaults if user provides param_bounds dictionary
if param_bounds is not None:
for param, bound in param_bounds.items():
if param not in self.model.param_bounds.keys():
raise ParameterError(
f"'{param}' is not a valid parameter"
f" in the '{model}' model."
)
self.model.param_bounds[param] = bound

# Dictionary of parameters as a starting point for data fitting.
self.param_guess = self.model.initial_guess(pressure, loading)

# Override defaults if user provides param_guess dictionary
if param_guess is not None:
for param, guess_val in param_guess.items():
if param not in self.param_guess.keys():
if param_guess:
for param in param_guess.keys():
if param not in self.model.param_names:
raise ParameterError(
f"'{param}' is not a valid parameter"
f" in the '{model}' model."
)
self.param_guess[param] = guess_val
else:
param_guess = self.model.initial_guess(pressure, loading)

# fit model to isotherm data
self.model.fit(
pressure,
loading,
self.param_guess,
param_guess,
optimization_params,
verbose,
)
Expand Down
13 changes: 8 additions & 5 deletions src/pygaps/graphing/isotherm_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ def plot_iso(

# Store which branches will be displayed
if not branch:
raise ParameterError("Specify a branch to display" " e.g. branch=\'ads\'")
raise ParameterError("Specify a branch to display"
" e.g. branch=\'ads\'")
if branch not in _BRANCH_TYPES:
raise GraphingError(
"The supplied branch type is not valid."
Expand Down Expand Up @@ -279,7 +280,9 @@ def plot_iso(
y2_ls.update(y2_line_style)

# If there's an adsorption branch, plot it
if ads and isotherm.has_branch('ads'):
iso_has_ads = isotherm.has_branch('ads')
iso_has_des = isotherm.has_branch('des')
if ads and iso_has_ads:
# Points
x1_p, y1_p, x2_p, y2_p = _get_data(
isotherm,
Expand All @@ -303,7 +306,7 @@ def plot_iso(
y2_ls['markerfacecolor'] = 'white'

# If there's a desorption branch, plot it
if des and isotherm.has_branch('des'):
if des and iso_has_des:
# Points
x1_p, y1_p, x2_p, y2_p = _get_data(
isotherm,
Expand All @@ -313,15 +316,15 @@ def plot_iso(
range_params=range_params,
)
# Plot line 1
if branch == 'all' and 'branch' not in lgd_keys:
if branch == 'all' and 'branch' not in lgd_keys and iso_has_ads:
y1_lbl = ''
else:
y1_lbl = label_lgd(isotherm, lgd_keys, 'des', y1_data)
ax1.plot(x1_p, y1_p, label=y1_lbl, **y1_ls)

# Plot line 2
if y2_data and y2_p is not None:
if branch == 'all' and 'branch' not in lgd_keys:
if branch == 'all' and 'branch' not in lgd_keys and iso_has_ads:
y2_lbl = ''
else:
y2_lbl = label_lgd(isotherm, lgd_keys, 'des', y2_data)
Expand Down
20 changes: 10 additions & 10 deletions src/pygaps/modelling/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
If adding a custom model, it should be also added below as a string.
"""

import typing as t
import importlib

from pygaps.utilities.exceptions import ParameterError
Expand Down Expand Up @@ -136,7 +136,7 @@ def is_model_class(model):
return isinstance(model, IsothermBaseModel)


def get_isotherm_model(model_name: str, params: dict = None):
def get_isotherm_model(model_name: str, **params: dict):
"""
Check whether specified model name exists and return an instance of that model class.
Expand Down Expand Up @@ -165,22 +165,22 @@ def get_isotherm_model(model_name: str, params: dict = None):
pg_model_name = _MODELS[index]
module = importlib.import_module(f"pygaps.modelling.{pg_model_name.lower()}")
model = getattr(module, pg_model_name)
return model(params)
return model(**params)


def model_from_dict(model_dict):
"""Obtain a model from a dictionary."""
return get_isotherm_model(model_dict.pop('name'), model_dict)
return get_isotherm_model(model_dict.pop('name'), **model_dict)


def model_iso(
isotherm,
branch='ads',
model=None,
param_guess=None,
param_bounds=None,
optimization_params=None,
verbose=False
branch: str = 'ads',
model: t.Union[str, t.List[str], t.Any] = None,
param_guess: dict = None,
param_bounds: dict = None,
optimization_params: dict = None,
verbose: bool = False,
):
"""
Fits a PointIsotherm with a model.
Expand Down
Loading

0 comments on commit 402010f

Please sign in to comment.