Source code for pygaps.utilities.isotherm_interpolator
"""A class used for isotherm interpolation."""fromscipy.interpolateimportinterp1d
[docs]classIsothermInterpolator():""" 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. """def__init__(self,known_data,interp_data,interp_branch='ads',interp_kind='linear',interp_fill=None,):# Instantiate# The branch the internal interpolator is on.self.interp_branch=interp_branch# The kind of interpolator in the internal interpolator.self.interp_kind=interp_kind# Value of loading to assume beyond highest pressure in the data.self.interp_fill=interp_fill# The actual interpolator. This is generated# the first time it is needed to make calculations faster.ifknown_dataisNone:return# Create the interpolatorifinterp_fillisNone:self.interp_fun=interp1d(known_data,interp_data,kind=interp_kind,)# If we want to extrapolate, we need to use a different# interpolator.else:self.interp_fun=interp1d(known_data,interp_data,kind=interp_kind,fill_value=interp_fill,bounds_error=False)def__call__(self,data):"""Override direct call to return interpolated data."""returnself.interp_fun(data)