New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NIST parser new HDF output #144
Merged
Merged
Changes from 12 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
acfd45e
New class for straight to HDF parse and dump
epassaro a0299b4
New class for NIST weights
epassaro 1fecb8a
Changed attribute name to match with the usual HDF5 key
epassaro 7665602
Lot of fixes for `nist_weights_comp` notebook
epassaro a28e0c0
Inheriting from `BaseParser` class
epassaro 243b0ce
Inheriting from `BaseParser` class
epassaro dac2e7a
Final version of the notebook for documentation
epassaro e9b00da
Added docstrings
epassaro 3759736
Added docstring for `to_hdf` methods
epassaro 314bcb6
Added `get_ground_levels` method to NISTIonizationEnergies class
epassaro eb797e3
Docstring for new method
epassaro 68da5d3
Removed `line_id` column
epassaro 091e02e
Removed SQLite stuff from notebook
epassaro 1a37c04
Breaking long lines (PEP8)
epassaro ec86bf9
Minor PEP8 fixes (whitespaces, new line at the end)
epassaro 62d2f0b
More PEP8 fixes
epassaro 4b9d08f
Replace `append` for `put` in HDFStore
epassaro File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
from .weightscomp import download_weightscomp, NISTWeightsCompPyparser, NISTWeightsCompIngester | ||
from .ionization import download_ionization_energies, NISTIonizationEnergiesParser, NISTIonizationEnergiesIngester | ||
from carsus.io.nist.weightscomp import (download_weightscomp, | ||
NISTWeightsCompPyparser, | ||
NISTWeightsCompIngester, | ||
NISTWeightsComp) | ||
from carsus.io.nist.ionization import (download_ionization_energies, | ||
NISTIonizationEnergiesParser, | ||
NISTIonizationEnergiesIngester, | ||
NISTIonizationEnergies) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,12 @@ | |
|
||
from bs4 import BeautifulSoup | ||
from astropy import units as u | ||
from carsus.base import basic_atomic_data_fname | ||
from carsus.model import AtomWeight | ||
from carsus.io.base import BasePyparser, BaseIngester | ||
from carsus.util import parse_selected_atoms | ||
from carsus.io.base import BasePyparser, BaseIngester, BaseParser | ||
from carsus.io.util import to_nom_val_and_std_dev | ||
from carsus.util.helpers import ATOMIC_SYMBOLS_DATA | ||
from carsus.io.nist.weightscomp_grammar import isotope, COLUMNS, ATOM_NUM_COL, MASS_NUM_COL,\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PEP8 line length. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't touch any previous existing code, applied PEP8 standards to my changes only. There are a LOT of long lines! |
||
AM_VAL_COL, AM_SD_COL, INTERVAL, STABLE_MASS_NUM, ATOM_WEIGHT_COLS, AW_STABLE_MASS_NUM_COL,\ | ||
AW_TYPE_COL, AW_VAL_COL, AW_SD_COL, AW_LWR_BND_COL, AW_UPR_BND_COL | ||
|
@@ -183,3 +186,56 @@ def ingest(self, atomic_weights=True): | |
if atomic_weights: | ||
self.ingest_atomic_weights() | ||
self.session.flush() | ||
|
||
|
||
class NISTWeightsComp(BaseParser): | ||
""" | ||
Attributes | ||
---------- | ||
base : pandas.DataFrame | ||
|
||
columns : list of str | ||
|
||
Methods | ||
------- | ||
to_hdf(fname) | ||
Dump the `base` attribute into an HDF5 file | ||
|
||
""" | ||
def __init__(self, atoms): | ||
input_data = download_weightscomp() | ||
self.parser = NISTWeightsCompPyparser(input_data=input_data) | ||
self._prepare_data(atoms) | ||
|
||
def _prepare_data(self, atoms): | ||
atomic_numbers = parse_selected_atoms(atoms) | ||
atom_data_list = [] | ||
|
||
for atomic_number in atomic_numbers: | ||
basic_atomic_data = pd.read_csv(basic_atomic_data_fname) | ||
basic_atomic_data = basic_atomic_data.loc[atomic_number-1] | ||
|
||
atom_masses = self.parser.prepare_atomic_dataframe() | ||
atom_masses = atom_masses.drop(columns='atomic_weight_std_dev') | ||
atom_masses = atom_masses.rename(columns={'atomic_weight_nominal_value': 'mass'}) | ||
epassaro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
data = atom_masses.loc[[(atomic_number)]] | ||
data['symbol'] = basic_atomic_data['symbol'] | ||
data['name'] = basic_atomic_data['name'] | ||
|
||
atom_data_list.append(data) | ||
|
||
atom_data = pd.concat(atom_data_list) | ||
self.base = atom_data[['symbol', 'name', 'mass']] | ||
self.columns = atom_data.columns | ||
|
||
def to_hdf(self, fname): | ||
"""Dump the `base` attribute into an HDF5 file | ||
|
||
Parameters | ||
---------- | ||
fname : path | ||
Path to the HDF5 output file | ||
""" | ||
with pd.HDFStore(fname, 'a') as f: | ||
f.append('/atom_data', self.base, min_itemsize={'symbol': 2, 'name': 15}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make indentation consistent with above line.