Skip to content
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

Add isoelectronic sequence property and helper function #320

Merged
merged 4 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion fiasco/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"""
from fiasco.collections import IonCollection
from fiasco.elements import Element
from fiasco.fiasco import list_elements, list_ions, proton_electron_ratio
from fiasco.fiasco import (
get_isoelectronic_sequence,
list_elements,
list_ions,
proton_electron_ratio,
)
from fiasco.gaunt import GauntFactor
from fiasco.ions import Ion
from fiasco.levels import Level, Transitions
Expand Down
4 changes: 4 additions & 0 deletions fiasco/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def ionization_stage(self):
def charge_state(self):
return self.ionization_stage - 1

@property
def isoelectronic_sequence(self):
return plasmapy.particles.atomic_symbol(self.atomic_number - self.charge_state)

@property
def _ion_name(self):
# Old CHIANTI format, only preserved for internal data access
Expand Down
27 changes: 25 additions & 2 deletions fiasco/fiasco.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
import fiasco

from fiasco.io import DataIndexer
from fiasco.util import parse_ion_name

__all__ = ['list_elements', 'list_ions', 'proton_electron_ratio']
__all__ = ['list_elements', 'list_ions', 'proton_electron_ratio', 'get_isoelectronic_sequence']


def list_elements(hdf5_dbase_root=None, sort=True):
Expand Down Expand Up @@ -74,7 +75,29 @@ def list_ions(hdf5_dbase_root=None, sort=True):
# NOTE: when grabbing straight from the index and not sorting, the result will be
# a numpy array. Cast to a list to make sure the return type is consistent for
# all possible inputs
return ions.tolist() if type(ions) == np.ndarray else ions
return ions.tolist() if isinstance(ions, np.ndarray) else ions


def get_isoelectronic_sequence(element, hdf5_dbase_root=None):
"""
Return a list of ions in the isoelectronic sequence of ``element``.

Parameters
----------
element: `str`, `int`
Name of sequence. Can be either the full name (e.g. "hydrogren"),
the atomic symbol (e.g. "H") or the atomic number (e.g. 1)
hdf5_dbase_root: path-like, optional
If not specified, will default to that specified in ``fiasco.defaults``.
"""
Z_iso = plasmapy.particles.atomic_number(element)
all_ions = list_ions(hdf5_dbase_root=hdf5_dbase_root)

def _is_in_sequence(ion):
Z, z = parse_ion_name(ion)
return Z_iso == (Z - z + 1)

return [ion for ion in all_ions if _is_in_sequence(ion)]


@u.quantity_input
Expand Down
5 changes: 3 additions & 2 deletions fiasco/ions.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def __repr__(self):
Name: {self.ion_name}
Element: {self.element_name} ({self.atomic_number})
Charge: +{self.charge_state}
Isoelectronic Sequence: {self.isoelectronic_sequence}
Number of Levels: {n_levels}
Number of Transitions: {n_transitions}

Expand Down Expand Up @@ -262,7 +263,7 @@ def hydrogenic(self):
-----
This is `True` if :math:`Z - z = 1`.
"""
return (self.atomic_number - self.charge_state == 1)
return self.isoelectronic_sequence == 'H'

@property
def helium_like(self):
Expand All @@ -273,7 +274,7 @@ def helium_like(self):
-----
This is `True` if :math:`Z - z = 2`.
"""
return (self.atomic_number - self.charge_state == 2)
return self.isoelectronic_sequence == 'He'

@property
@u.quantity_input
Expand Down
1 change: 1 addition & 0 deletions fiasco/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def test_create_ion_input_formats(hdf5_dbase_root, ion_name):
assert ion.atomic_number == 26
assert ion.ionization_stage == 21
assert ion.charge_state == 20
assert ion.isoelectronic_sequence == 'C'
assert ion._ion_name == 'fe_21'
assert ion.ion_name_roman == 'Fe XXI'
assert ion.ionization_stage_roman == 'XXI'
Expand Down
10 changes: 10 additions & 0 deletions fiasco/tests/test_fiasco.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ def test_list_ions(hdf5_dbase_root):
assert isinstance(ions, list)


def test_get_isoelectronic_sequence(hdf5_dbase_root):
iso_seq = fiasco.get_isoelectronic_sequence('iron',
hdf5_dbase_root=hdf5_dbase_root)
assert iso_seq == ['Fe 1',
'Co 2',
'Ni 3',
'Cu 4',
'Zn 5',]


def test_proton_electron_ratio(hdf5_dbase_root):
t = np.logspace(4, 9, 100) * u.K
# NOTE: this number will not be accurate as we are using only a subset of
Expand Down