Utilities#

Isotherm interpolator#

A class used for isotherm interpolation.

class pygaps.utilities.isotherm_interpolator.IsothermInterpolator(known_data, interp_data, interp_branch='ads', interp_kind='linear', interp_fill=None)[source]#

Class used to interpolate between isotherm points.

Call directly to use.

It is mainly a wrapper around scipy.interpolate.interp1d.

Parameters:
  • interp_type (str) -- What variable the interpolator works on (pressure, loading etc).

  • known_data (str) -- The values corresponding to the input variable.

  • interp_data (str) -- The values corresponding to the variable to be interpolated.

  • interp_branch (str, optional) -- Stores which isotherm branch the interpolator is based on.

  • interp_kind (str, optional) -- Determine which kind of interpolation is done between the datapoints.

  • interp_fill (str, optional) -- The parameter passed to the scipy.interpolate.interp1d function to determine what to do outside data bounds.

Thermodynamic backend utilities#

Utilities for interacting with the CoolProp backend.

pygaps.utilities.coolprop_utilities.COOLPROP_BACKEND = 'HEOS'#

The backend which CoolProp uses, normally either HEOS or REFPROP.

pygaps.utilities.coolprop_utilities.backend_use_refprop()[source]#

Switch the equation of state used to REFPROP. User should have REFPROP installed.

pygaps.utilities.coolprop_utilities.backend_use_coolprop()[source]#

Switch the equation of state used to HEOS (CoolProp).

Python utilities#

Collections of various python utilities.

pygaps.utilities.python_utilities.zip_varlen(*iterables)[source]#

Variable length zip() function.

pygaps.utilities.python_utilities.grouped(iterable, n)[source]#

Divide an iterable in subgroups of max n elements.

pygaps.utilities.python_utilities.deep_merge(a, b, path=None, update=True)[source]#

Recursive updates of a dictionary.

class pygaps.utilities.python_utilities.SimpleWarning[source]#

Context manager overrides warning formatter to remove unneeded info.

Exceptions#

Custom errors thrown by the program.

exception pygaps.utilities.exceptions.pgError[source]#

Base error raised by pyGAPS.

exception pygaps.utilities.exceptions.ParameterError[source]#

Raised when one of the parameters is unsuitable.

exception pygaps.utilities.exceptions.CalculationError[source]#

Raised when a calculation fails.

exception pygaps.utilities.exceptions.ParsingError[source]#

Raised when parsing fails.

exception pygaps.utilities.exceptions.GraphingError[source]#

Raised when graphing fails.

Math utilities#

Function-independent mathematical calculations.

pygaps.utilities.math_utilities.split_ads_data(data, pressure_key)[source]#

Find the inflection in an adsorption dataset with adsorption/desorption.

pygaps.utilities.math_utilities.find_limit_indices(array: list, limits: tuple[float, float] = None, smallest_selection: int = 3)[source]#

Find the indices of an array limits

pygaps.utilities.math_utilities.find_linear_sections(xdata, ydata)[source]#

Find all sections of a curve which are linear.

pygaps.utilities.math_utilities.bspline(xs, ys, n=100, degree=2, periodic=False)[source]#

Calculate n samples on a b-spline.

Adapted from: https://stackoverflow.com/questions/24612626/b-spline-interpolation-with-python

Parameters:
  • xs (array) -- X points of the curve to fit

  • ys (array) -- Y points of the curve to fit

  • n (int) -- Number of samples to return

  • degree (int) -- Curve degree

  • periodic (bool) -- True - Curve is closed False - Curve is open

String processing utilities#

General functions for string transformations.

pygaps.utilities.string_utilities.convert_chemformula_ltx(string: str) str[source]#

Convert a chemical formula string to a matplotlib parsable format (latex).

Parameters:

string or Adsorbate (str) -- String to process.

Returns:

str -- Processed string.

pygaps.utilities.string_utilities.convert_unit_ltx(string: str, negative: bool = False) str[source]#

Convert a unit string to a nice matplotlib parsable format (latex).

Parameters:
  • string (str) -- String to process.

  • negative (bool) -- Whether the power is negative instead.

Returns:

str -- Processed string.

pygaps.utilities.string_utilities.cast_string(s)[source]#

Check and cast strings of various data types.

SQLite utilities#

General functions for SQL query building.

pygaps.utilities.sqlite_utilities.db_execute_general(statement: str, pth: str, verbose: bool = False)[source]#

Execute general SQL statements.

Parameters:
  • statement (str) -- SQL statement to execute.

  • pth (str) -- Path where the database is located.

  • verbose (bool) -- Print out extra information.

pygaps.utilities.sqlite_utilities.build_update(table: str, to_set: list, where: list, prefix: str | None = None)[source]#

Build an update request.

Parameters:
  • table (str) -- Table where query will be directed.

  • to_set (iterable) -- The list of columns to update.

  • where (iterable) -- The list of conditions to constrain the query.

  • prefix (str, optional) -- The prefix to introduce to the second part of the constraint.

Returns:

str -- Built query string.

pygaps.utilities.sqlite_utilities.build_insert(table: str, to_insert: list)[source]#

Build an insert request.

Parameters:
  • table (str) -- Table where query will be directed.

  • to_insert (iterable) -- The list of columns where the values will be inserted.

Returns:

str -- Built query string.

pygaps.utilities.sqlite_utilities.build_select(table: str, to_select: list, where: list | None = None)[source]#

Build a select request.

Parameters:
  • table (str) -- Table where query will be directed.

  • to_set (iterable) -- The list of columns to select.

  • where (iterable) -- The list of conditions to constrain the query.

Returns:

str -- Built query string.

pygaps.utilities.sqlite_utilities.build_select_unnamed(table: str, to_select: list, where: list, join: str = 'AND')[source]#

Build an select request with multiple parameters.

Parameters:
  • table (str) -- Table where query will be directed.

  • to_set (iterable) -- The list of columns to select

  • where (iterable) -- The list of conditions to constrain the query.

  • join (str) -- The joining clause of the parameters.

Returns:

str -- Built query string.

pygaps.utilities.sqlite_utilities.build_delete(table: str, where: list)[source]#

Build a delete request.

Parameters:
  • table (str) -- Table where query will be directed.

  • where (iterable) -- The list of conditions to constrain the query.

Returns:

str -- Built query string.

pygaps.utilities.sqlite_utilities.check_SQL_bool(val)[source]#

Check if a value is a bool. Useful for storage.

pygaps.utilities.sqlite_utilities.check_SQL_python_type(val)[source]#

Convert between the database string dtype and a python data type.

pygaps.utilities.sqlite_utilities.find_SQL_python_type(val)[source]#

Convert between a python data type and a database string.

Generate the default sqlite database.

pygaps.utilities.sqlite_db_creator.db_create(path: str, verbose: bool = False)[source]#

Create the entire database.

Parameters:
  • path (str) -- Path where the database is created.

  • verbose (bool) -- Print out extra information.

All sql pragmas to generate the sqlite database.