API Reference
carsus.io.base Module
This module defines base classes for parsers and ingesters.
Members
- class carsus.io.base.BaseParser(input_data=None)
Abstract base class for parsers.
- Attributes
- basepandas.DataFrame
Contains parsed results from the provided input data.
Methods
load(input_data)
Parses the input data and stores the results in the
base
attribute__call__(input_data)
Call an instance with input data to invoke the
load
method.
- class carsus.io.base.BasePyparser(grammar, columns, input_data=None)
Abstract base class for parsers that use pyparsing grammar.
Notes
Rationale: pyparsers have a specific load workflow illustrated below.
Suppose a
base
of some parser has three columns:atomic_mass_nominal_value | atomic_mass_std_dev | notes
The
load
method scans the input data with parser’sgrammar
. The returned matches have nested labeled tokens that correspond to the columns. Say, one of the matches has the following nested tokens list:- atomic_mass: ['37.96273211', '(', '21', ')'] - nominal_value: 37.96273211 - std_dev: 2.1e-07
The
load
method then infers the columns’ values from the nested labels and adds the following row to thebase
:atomic_mass_nominal_value 37.9627 atomic_mass_std_dev 2.1e-07 notes NaN
- Attributes
- basepandas.DataFrame
Contains parsed results from the provided input data.
- grammarpyparsing.ParseElement
The grammar used to parse input. Its labeled tokens correspond to the columns of the
base
- columnslist of str
The column names of the
base
Methods
load(input_data)
Parses the input data and stores the results in the
base
attribute
- class carsus.io.base.BaseIngester(session, ds_short_name, parser, downloader)
Abstract base class for ingesters.
- Attributes
- session: SQLAlchemy session
- data_source: DataSource instance
The data source of the ingester
- parserBaseParser instance
Parses the downloaded data
- downloaderfunction
Downloads the data
Methods
download()
Downloads the data with the ‘downloader’ and loads the
parser
with itingest(session)
Persists the downloaded data into the database
Class inheritance diagram
![../../_images/io_base_inheritance.png](../../_images/io_base_inheritance.png)
carsus.io.nist Package
This package defines parsers and ingesters for the NIST databases.
Members
- carsus.io.nist.download_weightscomp(nist_url=False, ascii='ascii2', isotype='some')
Downloader function for the NIST Atomic Weights and Isotopic Compositions database
Makes a GET request to download data; then extracts preformatted text
- Parameters
- nist_url: bool
If False, downloads data from the carsus-dat-nist repository, else, downloads data from the NIST Atomic Weights and Isotopic Compositions Database.
- ascii: str
GET request parameter, refer to the NIST docs (default: ‘ascii’)
- isotype: str
GET request parameter, refer to the NIST docs (default: ‘some’)
- Returns
- str
Preformatted text data
- class carsus.io.nist.NISTWeightsCompPyparser(grammar=isotope, columns=COLUMNS, input_data=None)
Class for parsers for the NIST Atomic Weights and Isotopic Compositions
- Attributes
- basepandas.DataFrame
- grammarpyparsing.ParseElement
(default value = isotope)
- columnslist of str
(default value = COLUMNS)
Methods
load(input_data)
Parses the input data and stores the results in the
base
attributeprepare_atomic_dataframe()
Returns a new dataframe created from the
base
and containing data only related to atoms.prepare_isotopic_dataframe()
Returns a new dataframe created from the
base
and containing data only related to isotopes
- class carsus.io.nist.NISTWeightsCompIngester(parser_cls=NISTWeightsCompPyparser, downloader=download_weightscomp)
Class for ingesters for the NIST Atomic Weights and Isotopic Compositions
- Attributes
- session: SQLAlchemy session
- data_source: DataSource instance
The data source of the ingester
- parserBaseParser instance
(default value = NISTWeightsCompPyparser())
- downloaderfunction
(default value = download_weightscomp)
Methods
download()
Downloads the data with the ‘downloader’ and loads the
parser
with itingest(session)
Persists the downloaded data into the database
Class inheritance diagram
![../../_images/io_nist_inheritance.png](../../_images/io_nist_inheritance.png)