Skip to content

Commit

Permalink
fixed coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-zieba committed Feb 21, 2024
1 parent 6d2b650 commit 96d24c3
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 128 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Python package
name: Pytest (Linux)
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- name: Checkout
Expand All @@ -24,17 +24,9 @@ jobs:
python -m pip install --upgrade pip
pip install -e ".[test]"
# - name: Lint with flake8
# 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: Test with pytest
run: |
pytest tests --cov=./src/pacman --cov-report=xml
pytest tests --cov=./src/pacman --cov-report=xml -s
- name: Upload coverage.xml as artifact
uses: actions/upload-artifact@v4
Expand All @@ -52,3 +44,11 @@ jobs:
#name: codecov-umbrella # optional
fail_ci_if_error: false # optional (default = false)
verbose: true # optional (default = false)

# - name: Lint with flake8
# 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

4 changes: 2 additions & 2 deletions .github/workflows/ci_windows.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Python package
name: Pytest (Windows)
on: [push, pull_request]

jobs:
Expand All @@ -23,7 +23,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ".[test]"
pip install -e ".[test]"
- name: Test with pytest
run: |
Expand Down
2 changes: 1 addition & 1 deletion src/pacman/s10_direct_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ def run10(eventlabel, workdir: Path, meta=None):
# Save results
print('Saving Metadata')
me.saveevent(meta, meta.workdir / f'WFC3_{meta.eventlabel}_Meta_Save', save=[])
print('tmp: ', 2+1)

print('Finished s10 \n')
return meta
228 changes: 114 additions & 114 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,120 +321,120 @@ def test_sim_source(capsys):
assert source_ypos-1 <= results[3] <= source_ypos+1


# @pytest.mark.run(order=27)
# def test_s20(capsys):
# """The extraction step. Extracts flux as a function
# of wavelength and time.
# """
# reload(s20)
# time.sleep(1)
#
# workdir, eventlabel = workdir_finder()
#
# # Run s20
# meta = s20.run20(eventlabel, workdir)
#
# extracted_lc_dir_path = workdir / 'extracted_lc'
#
# s20_dir = np.array([path for path in extracted_lc_dir_path.iterdir() if path.is_dir()])[0]
# s20_lc_spec_file = s20_dir / 'lc_spec.txt'
# s20_lc_white_file = s20_dir / 'lc_white.txt'
#
# # Check if the files were created
# assert s20_lc_spec_file.exists()
# assert s20_lc_white_file.exists()
#
# s20_lc_spec = ascii.read(s20_lc_spec_file)
# s20_lc_white = ascii.read(s20_lc_white_file)
#
# # Check the amount of columns
# assert len(s20_lc_spec.colnames) == 10
# assert len(s20_lc_white.colnames) == 11
#
# # test_optextr
# spectrum = np.ones((20, 9))
#
# for i in range(len(spectrum)):
# for j in range(len(spectrum[0])):
# if 4 < i < 8:
# if 1 < j < 7:
# spectrum[i, j] = 10
#
# err = np.ones((20, 9))*0.01
# Mnew = np.ones((20, 9))
# spec_box_0 = 15 * 10
# var_box_0 = 1
#
# [f_opt_0, _, numoutliers] = optextr.optextr(
# spectrum, err, spec_box_0, var_box_0, Mnew,
# meta.nsmooth, meta.sig_cut, meta.save_optextr_plot, 0, 0, meta)
#
# assert np.round(np.sum(f_opt_0), 0) == np.round(np.sum(spectrum), 0) #optimal extraction flux should be the same as the total flux in the array
# assert numoutliers == 0 # We didnt introduce any outliers
#
#
# @pytest.mark.run(order=29)
# def test_s21(capsys):
# """Creates spectroscopic light curves."""
# reload(s21)
# time.sleep(1)
#
# workdir, eventlabel = workdir_finder()
#
# # Run s21
# meta = s21.run21(eventlabel, workdir)
#
# extracted_sp_dir_path = workdir / 'extracted_sp'
#
# s21_dir = np.array([path for path in extracted_sp_dir_path.iterdir()
# if path.is_dir()])[0]
# s21_wvl_table_file = s21_dir / 'wvl_table.dat'
# assert s21_wvl_table_file.exists()
# s21_wvl_table = ascii.read(s21_wvl_table_file)
#
# wvl_s21 = s21_wvl_table['wavelengths']
#
# # Check if the number of bins defined in the pcf is the same as
# # the number of wavelength bins saved into the wvl_table.dat file.
# assert meta.wvl_bins == len(wvl_s21)
#
# # Number of light curves should be the same as meta.wvl_bins
# extracted_sp_lcs_files = list(s21_dir.glob("*.txt"))
# assert meta.wvl_bins == len(extracted_sp_lcs_files)
#
# # There should be 10 columns as for the /lc_spec.txt file which was generated after running s20.
# extracted_sp_lc_file_0 = sn.sort_nicely(extracted_sp_lcs_files)[0]
# extracted_sp_lc_0 = ascii.read(extracted_sp_lc_file_0)
# assert len(extracted_sp_lc_0.colnames) == 10
#
#
# @pytest.mark.run(order=30)
# def test_s30(capsys):
# """Fits spectroscopic light curves."""
# reload(s30)
# time.sleep(1)
#
# workdir, eventlabel = workdir_finder()
#
# # Run s30
# meta = s30.run30(eventlabel, workdir)
#
# dirs = np.array([path for path in workdir.iterdir() if path.is_dir()])
# dirs_bool = np.array(['fit_' in dir.name for dir in dirs])
# fit_dirs = dirs[dirs_bool]
# fit_dir = fit_dirs[0]
# assert fit_dir.exists()
#
# meta.s30_fit_white = True
# meta.s30_most_recent_s20 = True
#
# s30.run30(eventlabel, workdir, meta=meta)
#
# dirs = np.array([path for path in workdir.iterdir() if path.is_dir()])
# dirs_bool = np.array(['fit_' in dir.name for dir in dirs])
#
# print('dirs_bool: ', dirs_bool)
# assert True
@pytest.mark.run(order=27)
def test_s20(capsys):
"""The extraction step. Extracts flux as a function
of wavelength and time.
"""
reload(s20)
time.sleep(1)

workdir, eventlabel = workdir_finder()

# Run s20
meta = s20.run20(eventlabel, workdir)

extracted_lc_dir_path = workdir / 'extracted_lc'

s20_dir = np.array([path for path in extracted_lc_dir_path.iterdir() if path.is_dir()])[0]
s20_lc_spec_file = s20_dir / 'lc_spec.txt'
s20_lc_white_file = s20_dir / 'lc_white.txt'

# Check if the files were created
assert s20_lc_spec_file.exists()
assert s20_lc_white_file.exists()

s20_lc_spec = ascii.read(s20_lc_spec_file)
s20_lc_white = ascii.read(s20_lc_white_file)

# Check the amount of columns
assert len(s20_lc_spec.colnames) == 10
assert len(s20_lc_white.colnames) == 11

# test_optextr
spectrum = np.ones((20, 9))

for i in range(len(spectrum)):
for j in range(len(spectrum[0])):
if 4 < i < 8:
if 1 < j < 7:
spectrum[i, j] = 10

err = np.ones((20, 9))*0.01
Mnew = np.ones((20, 9))
spec_box_0 = 15 * 10
var_box_0 = 1

[f_opt_0, _, numoutliers] = optextr.optextr(
spectrum, err, spec_box_0, var_box_0, Mnew,
meta.nsmooth, meta.sig_cut, meta.save_optextr_plot, 0, 0, meta)

assert np.round(np.sum(f_opt_0), 0) == np.round(np.sum(spectrum), 0) #optimal extraction flux should be the same as the total flux in the array
assert numoutliers == 0 # We didnt introduce any outliers


@pytest.mark.run(order=29)
def test_s21(capsys):
"""Creates spectroscopic light curves."""
reload(s21)
time.sleep(1)

workdir, eventlabel = workdir_finder()

# Run s21
meta = s21.run21(eventlabel, workdir)

extracted_sp_dir_path = workdir / 'extracted_sp'

s21_dir = np.array([path for path in extracted_sp_dir_path.iterdir()
if path.is_dir()])[0]
s21_wvl_table_file = s21_dir / 'wvl_table.dat'
assert s21_wvl_table_file.exists()
s21_wvl_table = ascii.read(s21_wvl_table_file)

wvl_s21 = s21_wvl_table['wavelengths']

# Check if the number of bins defined in the pcf is the same as
# the number of wavelength bins saved into the wvl_table.dat file.
assert meta.wvl_bins == len(wvl_s21)

# Number of light curves should be the same as meta.wvl_bins
extracted_sp_lcs_files = list(s21_dir.glob("*.txt"))
assert meta.wvl_bins == len(extracted_sp_lcs_files)

# There should be 10 columns as for the /lc_spec.txt file which was generated after running s20.
extracted_sp_lc_file_0 = sn.sort_nicely(extracted_sp_lcs_files)[0]
extracted_sp_lc_0 = ascii.read(extracted_sp_lc_file_0)
assert len(extracted_sp_lc_0.colnames) == 10


@pytest.mark.run(order=30)
def test_s30(capsys):
"""Fits spectroscopic light curves."""
reload(s30)
time.sleep(1)

workdir, eventlabel = workdir_finder()

# Run s30
meta = s30.run30(eventlabel, workdir)

dirs = np.array([path for path in workdir.iterdir() if path.is_dir()])
dirs_bool = np.array(['fit_' in dir.name for dir in dirs])
fit_dirs = dirs[dirs_bool]
fit_dir = fit_dirs[0]
assert fit_dir.exists()

meta.s30_fit_white = True
meta.s30_most_recent_s20 = True

s30.run30(eventlabel, workdir, meta=meta)

dirs = np.array([path for path in workdir.iterdir() if path.is_dir()])
dirs_bool = np.array(['fit_' in dir.name for dir in dirs])

print('dirs_bool: ', dirs_bool)
assert True


@pytest.mark.run(order=40)
Expand Down

0 comments on commit 96d24c3

Please sign in to comment.