def test_model_summary_df(nepc_connect): """Verify nepc.model_summary_df returns a dataframe""" # TODO: check formatting of summary dataframe # FIXME: randomly sample models fict = nepc.Model(nepc_connect[1], "fict") df = fict.summary(lower=0, upper=10) assert isinstance(df, pd.io.formats.style.Styler)
def test_Model_class(nepc_connect): """Verify that the nepc.Model class is a list of CS type and test the methods within the Class.""" fict = nepc.Model(nepc_connect[1], "fict") # FIXME: randomly sample the models in the database # FIXME: randomly sample the cross sections in the model assert isinstance(fict.cs, list) assert isinstance(fict.cs[0].metadata, dict) assert isinstance(fict.cs[0].data, dict) # test len method # FIXME use data in .mod files to determine number of CS in Model for assert assert len(fict) == 30
def test_format_model_write_file(nepc_connect, tmpdir): file = tmpdir.join('lxcat.txt') fict = nepc.Model(nepc_connect[1], "fict") parser.format_model(fict, type='lxcat', filename=str(file)) lines = file.read().splitlines() assert len(lines) == 1981 assert lines[0] == 'EXCITATION' assert lines[99] == '1.500000e+03\t1.130000e-20' assert lines[184] == 'COLUMNS: Energy (eV) | Cross section (m2)' with open(str(file), 'rb') as f: fb = f.read() readable_hash = hashlib.md5(fb).hexdigest() assert readable_hash == '8f8c7935e3d80ea20ca9fffd98391ade'
def test_format_model_write_file(nepc_connect, tmpdir): file = tmpdir.join('lxcat.txt') fict = nepc.Model(nepc_connect[1], "fict") format_model(fict, type='lxcat', filename=str(file)) lines = file.read().splitlines() assert len(lines) == 1951 assert lines[0] == 'EXCITATION' assert lines[99] == '3.000000e+03\t6.300000e-21' assert lines[179] == 'COLUMNS: Energy (eV) | Cross section (m2)' with open(str(file), 'rb') as f: fb = f.read() readable_hash = hashlib.md5(fb).hexdigest() assert readable_hash == 'b0c0d9564c3f9c722a27c6e5a4d27260'
def test_model_subset(nepc_connect): """Verify that Model.subset returns a proper subset of cross sections from a model within the NEPC MySQL database""" # TODO: test for lhsB and rhsB # FIXME: randomly sample models and cross sections within the model fict = nepc.Model(nepc_connect[1], "fict") fict_subset = fict.subset({'process': 'excitation', 'lhsA': 'N2(X1Sigmag+)'}) assert isinstance(fict_subset, list) assert isinstance(fict_subset[0].metadata, dict) assert isinstance(fict_subset[0].data, dict) with pytest.raises(Exception): assert fict.subset()
pd.set_option('max_colwidth', 100) # %% [markdown] # ***NOTE: You may need to modify the `local` argument in the next command. # `local=True` points to a local copy of the NEPC database. # `local=False` points to a computer serving a NEPC MySQL database. # See `nepc.util.config.production()` and set the `$NEPC_PRODUCTION` environment variable.*** # %% cnx, cursor = nepc.connect(local=False, test=True) # %% [markdown] # # Full fict dataset # %% fict = nepc.Model(cursor, "fict") # %% type(fict.summary()) # %% fict.summary() # %% [markdown] # To inspect the `metadata` or `data` attribute of a particular cross section, use the `Model.subset` method. # %% fict.subset(metadata={'cs_id': 10})[0].metadata # %% [markdown] # # Electron-impact excitations provided by Model `fict`