Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeshingles committed Dec 17, 2024
1 parent 6c447b7 commit 72f120a
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 48 deletions.
5 changes: 0 additions & 5 deletions .flake8

This file was deleted.

20 changes: 11 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ jobs:
run: |
python -m pip install -e .
- name: Lint with flake8
working-directory: artisatomic/
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Lint with mypy
run: |
mypy --install-types --non-interactive
Expand Down Expand Up @@ -97,7 +89,7 @@ jobs:
tests:
strategy:
matrix:
testname: [cmfgen, jplt]
testname: [cmfgen, jplt, floers25]
fail-fast: false

runs-on: macos-15
Expand Down Expand Up @@ -152,6 +144,16 @@ jobs:
cp tests/${{ matrix.testname }}/artisatomicionhandlers.json .
makeartisatomicfiles -output_folder tests/${{ matrix.testname }}/output
- name: Extract Floers25 atomic data
if: matrix.testname == 'floers25'
working-directory: atomic-data-floers25/
run: tar -zxvf testdata.tar.xz

- name: Generate artis atomic data files
run: |
cp tests/${{ matrix.testname }}/artisatomicionhandlers.json .
makeartisatomicfiles -output_folder tests/${{ matrix.testname }}/output
- name: Checksum output files
working-directory: tests/${{ matrix.testname }}/output
run: |
Expand Down
5 changes: 0 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ repos:
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/pycqa/flake8
rev: 7.1.1
hooks:
- id: flake8
types: [python]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
hooks:
Expand Down
60 changes: 32 additions & 28 deletions artisatomic/readfloers25data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,44 @@

import artisatomic

# from astropy import units as u
# import os.path
# import pandas as pd
# from carsus.util import parse_selected_species

BASEPATH = Path(Path.home() / "Google Drive/Shared drives/Atomic Data Group/FloersOpacityPaper/OutputFiles")
def get_basepath() -> Path:
return artisatomic.PYDIR / ".." / "atomic-data-floers25" / "OutputFiles"


def extend_ion_list(ion_handlers, calibrated=True):
BASEPATH = get_basepath()
assert BASEPATH.is_dir()
handlername = "floers25" + "calib" if calibrated else "uncalib"
for s in BASEPATH.glob("*_levels_calib.txt"):
ionstr = s.name.lstrip("0123456789").split("_")[0]
elsym = ionstr.rstrip("IVX")
ion_stage_roman = ionstr.removeprefix(elsym)
atomic_number = artisatomic.elsymbols.index(elsym)

ion_stage = artisatomic.roman_numerals.index(ion_stage_roman)

found_element = False
for tmp_atomic_number, list_ions in ion_handlers:
if tmp_atomic_number == atomic_number:
if ion_stage not in [x[0] if len(x) > 0 else x for x in list_ions]:
list_ions.append((ion_stage, handlername))
list_ions.sort()
found_element = True
if not found_element:
ion_handlers.append(
(
atomic_number,
[(ion_stage, handlername)],
# if calibrated is requested, also add uncalibrated data where calibrated data is not available
calibflags = [True, False] if calibrated else [False]
for searchcalib in calibflags:
calibstr = "calib" if searchcalib else "uncalib"
handlername = f"floers25{calibstr}"
for s in BASEPATH.glob(f"*_levels_{calibstr}.txt*"):
ionstr = s.name.lstrip("0123456789").split("_")[0]
elsym = ionstr.rstrip("IVX")
ion_stage_roman = ionstr.removeprefix(elsym)
atomic_number = artisatomic.elsymbols.index(elsym)

ion_stage = artisatomic.roman_numerals.index(ion_stage_roman)

found_element = False
for tmp_atomic_number, list_ions in ion_handlers:
if tmp_atomic_number == atomic_number:
if ion_stage not in [x[0] if len(x) > 0 else x for x in list_ions]:
list_ions.append((ion_stage, handlername))
list_ions.sort()
found_element = True
if not found_element:
ion_handlers.append(
(
atomic_number,
[(ion_stage, handlername)],
)
)
)

ion_handlers.sort(key=lambda x: x[0])

return ion_handlers


Expand All @@ -64,13 +67,14 @@ def read_levels_and_transitions(atomic_number: int, ion_stage: int, flog, calibr
ion_stage_roman = artisatomic.roman_numerals[ion_stage]
calibstr = "calib" if calibrated else "uncalib"

BASEPATH = get_basepath()
ionstr = f"{atomic_number}{elsym}{ion_stage_roman}"
levels_file = BASEPATH / f"{ionstr}_levels_{calibstr}.txt"
lines_file = BASEPATH / f"{ionstr}_transitions_{calibstr}.txt"

artisatomic.log_and_print(
flog,
f"Reading Floers+25 {calibstr}rated data for Z={atomic_number} ion_stage {ion_stage} ({elsym} {ion_stage_roman})",
f"Reading Floers+25 {calibstr}rated data for Z={atomic_number} ion_stage {ion_stage} ({elsym} {ion_stage_roman}) from {levels_file.name} and {lines_file.name}",
)

ionization_energy_in_ev = artisatomic.get_nist_ionization_energies_ev()[(atomic_number, ion_stage)]
Expand Down
1 change: 1 addition & 0 deletions atomic-data-floers25/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OutputFiles
4 changes: 4 additions & 0 deletions atomic-data-floers25/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Suggested method is either copy or symlink the data to a subfolder called "OutputFiles"

e.g.
ln -s ~/Google\ Drive/Shared\ drives/Atomic\ Data\ Group/FloersOpacityPaper/OutputFiles OutputFiles
Binary file added atomic-data-floers25/testdata.tar.xz
Binary file not shown.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
argcomplete>=3.5.1
astropy>=6.1.4
ChiantiPy>=0.15.1
flake8>=6.1.0
h5py>=3.10.0
matplotlib>=3.9.2
mypy>=1.13.0
Expand Down
3 changes: 3 additions & 0 deletions tests/floers25/artisatomicionhandlers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
[66, [[3, "floersuncalib"]]]
]
4 changes: 4 additions & 0 deletions tests/floers25/checksums.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1305990e95d64971cad693ecaf27305f adata.txt
e19eb2c4a80a6dd70b7be8bdc045d030 compositiondata.txt
a673d82823ddddbb9b26ef8c8e6aed28 phixsdata_v2.txt
1f22937fa04c26bae7c170674ccc2513 transitiondata.txt

0 comments on commit 72f120a

Please sign in to comment.