Example #1
0
    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 = DATA_N77_PATH / sample['file']
            isotherm = pygaps.isotherm_from_json(filepath)
            ref_filepath = DATA_N77_PATH / DATA[sample['as_ref']]['file']
            ref_isotherm = pygaps.isotherm_from_json(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)
Example #2
0
def load_iast():
    """A fixture which loads files from the disk."""
    filepath = DATA_IAST_PATH / DATA_IAST['CH4']['file']
    ch4 = pygaps.isotherm_from_json(filepath)
    filepath = DATA_IAST_PATH / DATA_IAST['C2H6']['file']
    c2h6 = pygaps.isotherm_from_json(filepath)
    return ch4, c2h6
Example #3
0
    def test_isotherm_from_json_nist(self):
        """Test the parsing of an isotherm from json."""

        JSON_PATH_NIST = Path(
            __file__
        ).parent.parent.parent / 'docs' / 'examples' / 'data' / 'parsing' / 'nist' / 'nist_iso.json'

        with open(JSON_PATH_NIST) as file:
            pygaps.isotherm_from_json(file.read(), fmt='NIST')
Example #4
0
    def test_isotherm_from_json_nist(self):
        """Test the parsing of an isotherm from json."""

        JSON_PATH_NIST = os.path.join(
            os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
            'docs', 'examples', 'data', 'parsing', 'nist', 'nist_iso.json')

        with open(JSON_PATH_NIST) as file:
            pygaps.isotherm_from_json(file.read(), fmt='NIST')
Example #5
0
def load_iast():
    """Load the files from disk."""
    filepath = os.path.join(DATA_IAST_PATH, DATA_IAST['CH4'].get('file'))

    with open(filepath, 'r') as text_file:
        ch4 = pygaps.isotherm_from_json(text_file.read())

    filepath = os.path.join(DATA_IAST_PATH, DATA_IAST['C2H6'].get('file'))

    with open(filepath, 'r') as text_file:
        c2h6 = pygaps.isotherm_from_json(text_file.read())

    return ch4, c2h6
Example #6
0
    def test_iso_enthalpy_checks(self, use_material):
        """Test initial checks."""
        isotherms = []

        # load test data
        for temp in DATA_ISOSTERIC:

            filepath = os.path.join(DATA_ISOSTERIC_PATH,
                                    DATA_ISOSTERIC.get(temp)['file'])

            with open(filepath, 'r') as text_file:
                isotherm = pygaps.isotherm_from_json(text_file.read())

            isotherms.append(isotherm)

        # Check multiple isotherms
        with pytest.raises(pygaps.ParameterError):
            pygaps.isosteric_enthalpy([isotherms[0]])

        # Check same sample
        isotherms[0].material_name = 'Test'

        with pytest.raises(pygaps.ParameterError):
            pygaps.isosteric_enthalpy(isotherms)

        isotherms[0].material_name = isotherms[1].material_name

        # Check same basis
        isotherms[0].convert_adsorbent(basis_to='volume', unit_to='cm3')

        with pytest.raises(pygaps.ParameterError):
            pygaps.isosteric_enthalpy(isotherms)

        return
Example #7
0
 def test_read_excel(self, tmpdir_factory):
     """Test read excel files file."""
     for index, path in enumerate(DATA_EXCEL_STD):
         isotherm = pygaps.isotherm_from_xl(path=path)
         with open(DATA_JSON_STD[index], 'r') as file:
             isotherm2 = pygaps.isotherm_from_json(file.read())
             assert isotherm.to_dict() == isotherm2.to_dict()
Example #8
0
 def test_read_excel_mic(self):
     """Test reading of micromeritics report files."""
     for path in DATA_EXCEL_MIC:
         isotherm = pygaps.isotherm_from_xl(path=path, fmt='mic')
         json_path = path.replace('.xls', '.json')
         with open(json_path, 'r') as file:
             assert isotherm == pygaps.isotherm_from_json(file.read())
Example #9
0
    def test_pointisotherm_to_json(self, basic_pointisotherm):
        """Test the parsing of a PointIsotherm to json."""

        test_isotherm_json = pygaps.isotherm_to_json(basic_pointisotherm)
        new_isotherm = pygaps.isotherm_from_json(test_isotherm_json)

        assert basic_pointisotherm == new_isotherm
Example #10
0
    def test_psd_micro(self, sample):
        """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 = DATA_N77_PATH / sample['file']
            isotherm = pygaps.isotherm_from_json(filepath)

            result_dict = pmic.psd_microporous(
                isotherm, psd_model='HK', pore_geometry='slit'
            )

            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
            )
Example #11
0
    def test_modelisotherm_to_json(self, basic_modelisotherm):
        """Test the parsing of an ModelIsotherm to json."""

        test_isotherm_json = pygaps.isotherm_to_json(basic_modelisotherm)
        new_isotherm = pygaps.isotherm_from_json(test_isotherm_json)

        assert basic_modelisotherm.to_dict() == new_isotherm.to_dict()
Example #12
0
    def test_read_bel(self):
        """Tests reading of a bel data file"""

        for path in DATA_BEL:

            isotherm = pygaps.isotherm_from_bel(path=path)
            json_path = str(path).replace('.DAT', '.json')
            assert isotherm == pygaps.isotherm_from_json(json_path)
Example #13
0
 def test_read_excel_bel(self):
     """Test reading of bel report files."""
     for path in DATA_EXCEL_BEL:
         isotherm = pygaps.isotherm_from_xl(path=path, fmt='bel')
         json_path = path.replace('.xls', '.json')
         with open(json_path, 'r') as file:
             new_iso = pygaps.isotherm_from_json(file.read())
             assert isotherm == new_iso
Example #14
0
    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_json(basic_pointisotherm, path)
        isotherm = pygaps.isotherm_from_json(path)

        assert isotherm == basic_pointisotherm
Example #15
0
    def test_iso_enthalpy_output(self):
        """Test verbosity."""
        isotherms = []

        for sample in DATA_ISOSTERIC:
            filepath = DATA_ISOSTERIC_PATH / DATA_ISOSTERIC[sample]['file']
            isotherm = pygaps.isotherm_from_json(filepath)
            isotherms.append(isotherm)

        ie.isosteric_enthalpy(isotherms, verbose=True)
Example #16
0
    def test_da_display(self, file, exp_vol, exp_pot):
        """Test isotherm display."""
        if exp_vol is None:
            return

        filepath = os.path.join(DATA_N77_PATH, file)

        with open(filepath, 'r') as text_file:
            isotherm = pygaps.isotherm_from_json(text_file.read())

        pygaps.da_plot(isotherm, verbose=True)
Example #17
0
    def test_read_bel(self):
        """Tests reading of a bel data file"""

        for path in DATA_BEL:

            isotherm = pygaps.isotherm_from_bel(path=path)

            json_path = path.replace('.DAT', '.json')

            with open(json_path, 'r') as file:
                assert isotherm == pygaps.isotherm_from_json(file.read())
Example #18
0
    def test_area_BET_output(self, noplot):
        """Test verbosity"""

        data = DATA['MCM-41']

        filepath = os.path.join(DATA_N77_PATH, data['file'])

        with open(filepath, 'r') as text_file:
            isotherm = pygaps.isotherm_from_json(text_file.read())

        pygaps.area_BET(isotherm, verbose=True)
Example #19
0
    def test_iso_enthalpy(self):
        """Test calculation with several model isotherms."""
        isotherms = []

        for sample in DATA_ISOSTERIC:
            filepath = DATA_ISOSTERIC_PATH / DATA_ISOSTERIC[sample]['file']
            isotherm = pygaps.isotherm_from_json(filepath)
            isotherms.append(isotherm)

        result_dict = ie.isosteric_enthalpy(isotherms)

        assert isclose(average(result_dict['isosteric_enthalpy']), 29, 0.5)
Example #20
0
    def test_ienthalpy_comb(self, sample):
        """The combined polynomial method"""
        sample = DATA_CALO[sample]
        filepath = DATA_CALO_PATH / sample['file']
        isotherm = pygaps.isotherm_from_json(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)
Example #21
0
    def test_area_BET_choice(self):
        """Test choice of points."""

        sample = DATA['MCM-41']
        filepath = DATA_N77_PATH / sample['file']
        isotherm = pygaps.isotherm_from_json(filepath)

        bet_area = ab.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)
Example #22
0
    def test_area_BET(self, file, expected_bet):
        """Test calculation with several model isotherms"""

        filepath = os.path.join(DATA_N77_PATH, file)

        with open(filepath, 'r') as text_file:
            isotherm = pygaps.isotherm_from_json(text_file.read())

        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, expected_bet, err_relative, err_absolute)
Example #23
0
    def from_json(cls, json_string, **isotherm_parameters):
        """
        Construct a PointIsotherm from a standard json-represented isotherm.
        This function is just a wrapper around the more powerful .isotherm_from_json
        function.

        Parameters
        ----------
        json_string : str
            A json standard isotherm representation.
        isotherm_parameters :
            Any other options to be passed to the isotherm creation, like mode, basis or unit.
        """
        return pygaps.isotherm_from_json(json_string, **isotherm_parameters)
Example #24
0
    def test_psd_dft(self, file):
        """Test psd calculation with several model isotherms."""

        filepath = os.path.join(DATA_N77_PATH, file)

        with open(filepath, 'r') as text_file:
            isotherm = pygaps.isotherm_from_json(text_file.read())

        result_dict = pygaps.dft_size_distribution(isotherm,
                                                   'internal',
                                                   verbose=True)

        # max_error = 0.1  # 10 percent

        assert result_dict is not None
Example #25
0
    def test_ienthalpy_point(self, file, expected):
        """The point method."""

        filepath = os.path.join(DATA_CALO_PATH, file)

        with open(filepath, 'r') as text_file:
            isotherm = pygaps.isotherm_from_json(text_file.read())

        ienth_poly = pygaps.initial_enthalpy_point(
            isotherm, 'enthalpy', verbose=True).get('initial_enthalpy')

        err_relative = 0.1  # 10 percent
        err_absolute = 1  #

        assert isclose(ienth_poly, expected, err_relative, err_absolute)
Example #26
0
    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 = DATA_N77_PATH / sample['file']
            isotherm = pygaps.isotherm_from_json(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)
Example #27
0
    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 = DATA_N77_PATH / sample['file']
            isotherm = pygaps.isotherm_from_json(filepath)

            bet_area = ab.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)
Example #28
0
    def test_convert(self, basic_pointisotherm, tmpdir_factory):

        tempdir = tmpdir_factory.mktemp('cli')
        path = tempdir.join('isotherm.json').strpath
        outpath = tempdir.join('model.json').strpath
        basic_pointisotherm.adsorbate = 'N2'
        basic_pointisotherm.to_json(path)

        command = [
            "pygaps", "-cv", "pressure_mode=relative", "-o", outpath, path
        ]
        out, err, exitcode = capture(command)
        print(out, err)
        assert exitcode == 0

        assert pygaps.isotherm_from_json(outpath).pressure_mode == 'relative'
Example #29
0
    def test_psd_micro(self, file, method):
        """Test psd calculation with several model isotherms"""

        filepath = os.path.join(DATA_N77_PATH, file)

        with open(filepath, 'r') as text_file:
            isotherm = pygaps.isotherm_from_json(text_file.read())

        result_dict = pygaps.micropore_size_distribution(isotherm,
                                                         psd_model=method,
                                                         pore_geometry='slit',
                                                         verbose=True)

        # max_error = 0.1  # 10 percent

        assert result_dict is not None
Example #30
0
    def test_iso_enthalpy_output(self):
        """Test verbosity."""

        isotherms = []

        # load test data
        for temp in DATA_ISOSTERIC:

            filepath = os.path.join(DATA_ISOSTERIC_PATH,
                                    DATA_ISOSTERIC.get(temp)['file'])

            with open(filepath, 'r') as text_file:
                isotherm = pygaps.isotherm_from_json(text_file.read())

            isotherms.append(isotherm)

        pygaps.isosteric_enthalpy(isotherms, verbose=True)