This module defines base classes for parsers and ingesters.
carsus.io.base.
BaseParser
(input_data=None)¶Abstract base class for parsers.
Attributes
base_df | (pandas.DataFrame) Contains parsed results from the provided input data. |
Methods
load(input_data) | Parses the input data and stores the results in the base_df attribute |
__call__(input_data) | Call an instance with input data to invoke the load method. |
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_df of some parser has three columns:
atomic_mass_nominal_value | atomic_mass_std_dev | notes
The load method scans the input data with parser’s grammar. 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 the base_df:
atomic_mass_nominal_value 37.9627
atomic_mass_std_dev 2.1e-07
notes NaN
Attributes
base_df | (pandas.DataFrame) Contains parsed results from the provided input data. |
grammar | (pyparsing.ParseElement) The grammar used to parse input. Its labeled tokens correspond to the columns of the base_df |
columns | (list of str) The column names of the base_df |
Methods
load(input_data) | Parses the input data and stores the results in the base_df attribute |
carsus.io.base.
BaseIngester
(parser, downloader)¶Abstract base class for ingesters.
Attributes
parser | (BaseParser instance) Parses the downloaded data |
downloader | (function) Downloads the data |
ds_short_name | (str) The short name of the data source |
Methods
download() | Downloads the data with the ‘downloader’ and loads the parser with it |
ingest(session) | Persists the downloaded data into the database |
This package defines parsers and ingesters for the NIST databases.
carsus.io.nist.
download_weightscomp
(url='http://physics.nist.gov/cgi-bin/Compositions/stand_alone.pl', params={'isotype': 'some', 'ascii': 'ascii2'})¶Downloader function for the NIST Atomic Weights and Isotopic Compositions database
Makes a GET request to download data; then extracts preformatted text
Parameters: | url : str
params : dict
|
---|---|
Returns: | str
|
carsus.io.nist.
NISTWeightsCompPyparser
(grammar=isotope, columns=COLUMNS, input_data=None)¶Class for parsers for the NIST Atomic Weights and Isotopic Compositions database
Attributes
base_df | (pandas.DataFrame) |
grammar | (pyparsing.ParseElement) (default value = isotope) |
columns | (list of str) (default value = COLUMNS) |
Methods
load(input_data) | Parses the input data and stores the results in the base_df attribute |
prepare_atomic_dataframe() | Returns a new dataframe created from the base_df and containing data only related to atoms. |
prepare_isotopic_dataframe() | Returns a new dataframe created from the base_df and containing data only related to isotopes |
carsus.io.nist.
NISTWeightsCompIngester
(parser_cls=NISTWeightsCompPyparser, downloader=download_weightscomp)¶Class for ingesters for the NIST Atomic Weights and Isotopic Compositions database
Attributes
parser | (BaseParser instance) (default value = NISTWeightsCompPyparser()) |
downloader | (function) (default value = download_weightscomp) |
ds_short_name | (str) (default value = NIST) |
Methods
download() | Downloads the data with the ‘downloader’ and loads the parser with it |
ingest(session) | Persists the downloaded data into the database |