def load_iast(): """A fixture which loads files from the disk.""" filepath = os.path.join(DATA_IAST_PATH, DATA_IAST['CH4'].get('file')) ch4 = pygaps.isotherm_from_jsonf(filepath) filepath = os.path.join(DATA_IAST_PATH, DATA_IAST['C2H6'].get('file')) c2h6 = pygaps.isotherm_from_jsonf(filepath) return ch4, c2h6
def test_alphas(self, sample): """Test calculation with several model isotherms.""" sample = DATA[sample] # exclude datasets where it is not applicable if sample.get('as_area', None): filepath = os.path.join(DATA_N77_PATH, sample['file']) isotherm = pygaps.isotherm_from_jsonf(filepath) ref_filepath = os.path.join(DATA_N77_PATH, DATA[sample['as_ref']]['file']) ref_isotherm = pygaps.isotherm_from_jsonf(ref_filepath) mref_isotherm = pygaps.ModelIsotherm.from_pointisotherm( ref_isotherm, model='BET') res = pygaps.alpha_s(isotherm, mref_isotherm) results = res.get('results') err_relative = 0.1 # 10 percent err_absolute_area = 0.1 # units err_absolute_volume = 0.01 # units assert isclose(results[-1].get('adsorbed_volume'), sample['as_volume'], err_relative, err_absolute_area) assert isclose(results[0].get('area'), sample['as_area'], err_relative, err_absolute_volume)
def test_iso_enthalpy_checks(self, use_material): """Checks for built-in safeguards.""" isotherms = [] # load test data for sample in DATA_ISOSTERIC: filepath = os.path.join(DATA_ISOSTERIC_PATH, DATA_ISOSTERIC[sample]['file']) isotherm = pygaps.isotherm_from_jsonf(filepath) isotherms.append(isotherm) # Will raise a "requires more than one isotherm error" with pytest.raises(pygaps.ParameterError): ie.isosteric_enthalpy([isotherms[0]]) # Will raise a "requires isotherms on the same material error" isotherms[0].material = 'Test' with pytest.raises(pygaps.ParameterError): ie.isosteric_enthalpy(isotherms) isotherms[0].material = isotherms[1].material # Will raise a "requires isotherm on the same basis error" isotherms[0].convert_adsorbent(basis_to='volume', unit_to='cm3') with pytest.raises(pygaps.ParameterError): ie.isosteric_enthalpy(isotherms)
def test_isotherm_from_json_file(self, basic_pointisotherm, tmpdir_factory): """Test the parsing of an isotherm to a json file.""" path = tmpdir_factory.mktemp('json').join('isotherm.json').strpath pygaps.isotherm_to_jsonf(basic_pointisotherm, path) isotherm = pygaps.isotherm_from_jsonf(path) assert isotherm == basic_pointisotherm
def test_iso_enthalpy_output(self): """Test verbosity.""" isotherms = [] for sample in DATA_ISOSTERIC: filepath = os.path.join(DATA_ISOSTERIC_PATH, DATA_ISOSTERIC[sample]['file']) isotherm = pygaps.isotherm_from_jsonf(filepath) isotherms.append(isotherm) ie.isosteric_enthalpy(isotherms, verbose=True)
def test_ienthalpy_comb(self, sample): """The combined polynomial method""" sample = DATA_CALO[sample] filepath = os.path.join(DATA_CALO_PATH, sample['file']) isotherm = pygaps.isotherm_from_jsonf(filepath) ienth_poly = pygaps.initial_enthalpy_comp( isotherm, 'enthalpy').get('initial_enthalpy') err_relative = 0.1 # 10 percent err_absolute = 1 # assert isclose(ienth_poly, sample['ienth'], err_relative, err_absolute)
def test_iso_enthalpy(self): """Test calculation with several model isotherms.""" isotherms = [] for sample in DATA_ISOSTERIC: filepath = os.path.join(DATA_ISOSTERIC_PATH, DATA_ISOSTERIC[sample]['file']) isotherm = pygaps.isotherm_from_jsonf(filepath) isotherms.append(isotherm) result_dict = ie.isosteric_enthalpy(isotherms) assert isclose(average(result_dict['isosteric_enthalpy']), 29, 0.5)
def test_area_BET_choice(self): """Test choice of points.""" sample = DATA['MCM-41'] filepath = os.path.join(DATA_N77_PATH, sample['file']) isotherm = pygaps.isotherm_from_jsonf(filepath) bet_area = pygaps.area_BET( isotherm, limits=[0.05, 0.30]).get("area") err_relative = 0.1 # 10 percent err_absolute = 0.1 # 0.1 m2 assert isclose(bet_area, sample['s_bet_area'], err_relative, err_absolute)
def test_ihenry_virial(self, sample): """Test virial method with several model isotherms.""" sample = DATA[sample] # exclude datasets where it is not applicable if sample.get('Khi_slope', None): filepath = os.path.join(DATA_N77_PATH, sample['file']) isotherm = pygaps.isotherm_from_jsonf(filepath) ihenry_virial = pygaps.initial_henry_virial(isotherm) err_relative = 0.1 # 10 percent err_absolute = 10 # assert isclose(ihenry_virial, sample['Khi_virial'], err_relative, err_absolute)
def test_area_bet(self, sample): """Test calculation with several model isotherms.""" sample = DATA[sample] # exclude datasets where it is not applicable if sample.get('bet_area', None): filepath = os.path.join(DATA_N77_PATH, sample['file']) isotherm = pygaps.isotherm_from_jsonf(filepath) bet_area = pygaps.area_BET(isotherm).get("area") err_relative = 0.1 # 10 percent err_absolute = 0.1 # 0.1 m2 assert isclose(bet_area, sample['bet_area'], err_relative, err_absolute)
def test_isotherm_create_guess(self, file): """Check isotherm can be guessed from PointIsotherm.""" filepath = os.path.join(DATA_N77_PATH, file) isotherm = pygaps.isotherm_from_jsonf(filepath) pygaps.ModelIsotherm.from_pointisotherm(isotherm, guess_model='all', verbose=True) pygaps.ModelIsotherm.from_pointisotherm( isotherm, guess_model=['Henry', 'Langmuir'], verbose=True) with pytest.raises(pygaps.ParameterError): pygaps.ModelIsotherm.from_pointisotherm( isotherm, guess_model=['Henry', 'DummyModel'], verbose=True)
def test_alphas_choice(self): """Test choice of points.""" sample = DATA['MCM-41'] filepath = os.path.join(DATA_N77_PATH, sample['file']) isotherm = pygaps.isotherm_from_jsonf(filepath) res = pygaps.alpha_s(isotherm, isotherm, limits=[0.7, 1.0]) results = res.get('results') err_relative = 0.1 # 10 percent err_absolute_area = 0.1 # units err_absolute_volume = 0.01 # units assert isclose(results[-1].get('adsorbed_volume'), 0, err_relative, err_absolute_area) assert isclose(results[-1].get('area'), sample['s_as_area'], err_relative, err_absolute_volume)
def test_ihenry_slope_limits(self): """Test introducing limits in the initial slope method.""" sample = DATA['SiO2'] filepath = os.path.join(DATA_N77_PATH, sample['file']) isotherm = pygaps.isotherm_from_jsonf(filepath) pygaps.initial_henry_slope(isotherm, max_adjrms=0.01, p_limits=[0, 0.2]) pygaps.initial_henry_slope(isotherm, max_adjrms=0.01, p_limits=[0.2, None]) pygaps.initial_henry_slope(isotherm, max_adjrms=0.01, l_limits=[5, None]) with pytest.raises(pygaps.ParameterError): pygaps.initial_henry_slope(isotherm, max_adjrms=0.01, l_limits=[25, None])
def test_da_plot(self, sample): """Test calculation with several model isotherms.""" sample = DATA[sample] # exclude datasets where it is not applicable if sample.get('da_volume', None): filepath = os.path.join(DATA_N77_PATH, sample['file']) isotherm = pygaps.isotherm_from_jsonf(filepath) res = pygaps.da_plot(isotherm, limits=[0, 0.01]) da_vol = res.get("pore_volume") da_pot = res.get("adsorption_potential") err_relative = 0.05 # 5 percent err_absolute = 0.01 # 0.01 cm3/g assert isclose(da_vol, sample['da_volume'], err_relative, err_absolute) assert isclose(da_pot, sample['da_potential'], err_relative, err_absolute)
def test_psd_micro(self, sample, method): """Test psd calculation with several model isotherms""" sample = DATA[sample] # exclude datasets where it is not applicable if sample.get('psd_micro_pore_size', None): filepath = os.path.join(DATA_N77_PATH, sample['file']) isotherm = pygaps.isotherm_from_jsonf(filepath) result_dict = pmic.psd_microporous(isotherm, psd_model=method) loc = np.where(result_dict['pore_distribution'] == max(result_dict['pore_distribution'])) principal_peak = result_dict['pore_widths'][loc] err_relative = 0.05 # 5 percent err_absolute = 0.01 # 0.01 assert np.isclose( principal_peak, sample['psd_micro_pore_size'], err_relative, err_absolute)
def test_tplot(self, sample): """Test calculation with several model isotherms.""" sample = DATA[sample] # exclude datasets where it is not applicable if sample.get('t_area', None): filepath = os.path.join(DATA_N77_PATH, sample['file']) isotherm = pygaps.isotherm_from_jsonf(filepath) res = pygaps.t_plot(isotherm) results = res.get('results') err_relative = 0.1 # 10 percent err_absolute_area = 0.1 # units err_absolute_volume = 0.01 # units assert isclose(results[-1].get('adsorbed_volume'), sample['t_pore_volume'], err_relative, err_absolute_area) assert isclose(results[0].get('area'), sample['t_area'], err_relative, err_absolute_volume)
def test_tplot_output(self): """Test verbosity.""" sample = DATA['MCM-41'] filepath = os.path.join(DATA_N77_PATH, sample['file']) isotherm = pygaps.isotherm_from_jsonf(filepath) pygaps.t_plot(isotherm, 'Halsey', verbose=True)
def test_ihenry_virial_verbose(self): """Test verbosity.""" sample = DATA['SiO2'] filepath = os.path.join(DATA_N77_PATH, sample['file']) isotherm = pygaps.isotherm_from_jsonf(filepath) pygaps.initial_henry_virial(isotherm, verbose=True)
def test_ienthalpy_comb_output(self): """Test verbosity.""" sample = DATA_CALO['Takeda 5A'] filepath = os.path.join(DATA_CALO_PATH, sample['file']) isotherm = pygaps.isotherm_from_jsonf(filepath) pygaps.initial_enthalpy_comp(isotherm, 'enthalpy', verbose=True)
def test_area_BET_output(self): """Test verbosity.""" sample = DATA['MCM-41'] filepath = os.path.join(DATA_N77_PATH, sample['file']) isotherm = pygaps.isotherm_from_jsonf(filepath) pygaps.area_BET(isotherm, verbose=True)
def test_da_output(self): """Test verbosity.""" sample = DATA['Takeda 5A'] filepath = os.path.join(DATA_N77_PATH, sample['file']) isotherm = pygaps.isotherm_from_jsonf(filepath) pygaps.da_plot(isotherm, verbose=True)
def test_psd_micro_verbose(self): """Test verbosity.""" data = DATA['MCM-41'] filepath = os.path.join(DATA_N77_PATH, data['file']) isotherm = pygaps.isotherm_from_jsonf(filepath) pygaps.psd_microporous(isotherm, verbose=True)