Skip to content

Commit

Permalink
Merge pull request #28 from mfixstsci/update-ci-pipelines
Browse files Browse the repository at this point in the history
Update GHA Pipeline
  • Loading branch information
mfixstsci authored Jul 16, 2024
2 parents 075f173 + 9b3df80 commit 0400e4e
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 33 deletions.
17 changes: 6 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ jobs:
name: Python - ${{ matrix.python-version }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 5
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [3.7, 3.8, 3.9]
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -28,10 +27,6 @@ jobs:
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install Package and Test
run: |
cd $RUNNER_WORKSPACE/
cd jwst_backgrounds/
python setup.py install
pytest
run: |
pip install -e .[test] pytest-xdist
pytest -n auto jwst_backgrounds/tests/
14 changes: 3 additions & 11 deletions jwst_backgrounds/jbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,8 @@ def read_bkg_data(self, cache_file, verbose=False):
"""

# Read the background file via http
try:
# Python 3
# Read the background cache version
version_file = urllib.request.urlopen(self.cache_url + 'VERSION')
sbet_file = urllib.request.urlopen(self.cache_url + cache_file)
except:
# Python 2
# Read the background cache version
version_file = urllib.urlopen(self.cache_url + 'VERSION')
sbet_file = urllib.urlopen(self.cache_url + cache_file)
version_file = urllib.request.urlopen(self.cache_url + 'VERSION')
sbet_file = urllib.request.urlopen(self.cache_url + cache_file)

self.cache_version = version_file.readlines()[0].decode('utf-8')[:-1]
sbet_data = sbet_file.read()
Expand Down Expand Up @@ -313,7 +305,7 @@ def plot_bathtub(self, showthresh=True, showplot=False, showsubbkgs=False, showa
plt.title(annotation)
plt.ylabel("bkg at " + str(bathtub['wavelength']) + " um (MJy/sr)", fontsize=12)
else:
plt.ylabel("bkg (MJy/SR)", fontsize=fontsize)
plt.ylabel("bkg (MJy/SR)", fontsize=20)

if showsubbkgs:
plt.scatter(calendar, bathtub['zodi_thiswave'], s=20, label="Zodiacal")
Expand Down
Empty file.
78 changes: 67 additions & 11 deletions jwst_backgrounds/tests/test_jwst_bkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,92 @@
from astropy.io import ascii
from astropy.table import Table
import numpy as np
import pytest

from jwst_backgrounds.jbt import background

from jwst_backgrounds.jbt import background, get_background

TEST_DIR = abspath(join(dirname(__file__)))


def test_backgrounds(thisday=100):
""" Test backgrounds output from github example."""
"""Test backgrounds output from github example."""

# Column Names
column_names = ['wavelenght', 'total_background', 'zodical_background', 'nonzodical_background',
'stray_light_background', 'thermal_background']
column_names = [
"wavelenght",
"total_background",
"zodical_background",
"nonzodical_background",
"stray_light_background",
"thermal_background",
]
# Read truth files
data_file = join(TEST_DIR, 'background.txt')
data_file = join(TEST_DIR, "background.txt")
truth = ascii.read(data_file, names=column_names)

# Run background calculation
bkg = background(261.6833333, -73.33222222, 2.15, thresh=1.1)
calendar = bkg.bkg_data['calendar']
calendar = bkg.bkg_data["calendar"]
thisday_index = np.where(thisday == calendar)[0][0]

data = []

for i, wavelength in enumerate(bkg.bkg_data['wave_array']):
data.append([wavelength, bkg.bkg_data['total_bg'][thisday_index][i],
bkg.bkg_data['zodi_bg'][thisday_index][i], bkg.bkg_data['nonzodi_bg'][i],
bkg.bkg_data['stray_light_bg'][thisday_index][i], bkg.bkg_data['thermal_bg'][i]])
for i, wavelength in enumerate(bkg.bkg_data["wave_array"]):
data.append(
[
wavelength,
bkg.bkg_data["total_bg"][thisday_index][i],
bkg.bkg_data["zodi_bg"][thisday_index][i],
bkg.bkg_data["nonzodi_bg"][i],
bkg.bkg_data["stray_light_bg"][thisday_index][i],
bkg.bkg_data["thermal_bg"][i],
]
)

# Build background output table
test_data = Table(rows=data, names=column_names)

# Compare values of tables.
assert truth.values_equal(test_data)


@pytest.mark.parametrize("thisday", [100, -1])
def test_get_background(thisday):
"""By default, get_background does plotting and writing of files.
Although we aren't testing intermediate or outputs of get_background
it does check to make sure it will run to completion.
"""
get_background(
261.6833333,
-73.33222222,
wavelength=2.15,
thisday=thisday,
plot_background=False,
plot_bathtub=False,
)


@pytest.mark.parametrize(
"wave, flux, new_wave, expected",
[([1, 2.5, 3.4, 5.8, 6], [2, 4, 5.8, 4.3, 4], 5, np.array(4.8))],
)
def test_interpolate_spec(wave, flux, new_wave, expected):
"""interpolate_spec wraps scipy.iterpolate.interp1d"""
bkg = background(82.82, -5.39, 2.15)
result = bkg.interpolate_spec(wave, flux, new_wave)

np.testing.assert_array_equal(result, expected)


@pytest.mark.parametrize(
"ra, dec, expected",
[
(82.82, -5.39, "1073/sl_pix_107381.bin"),
(10.68471, 41.26875, "0330/sl_pix_033039.bin"),
],
)
def test_myfile_from_healpix(ra, dec, expected):
bkg = background(ra, dec, 2.15)
healpix_file = bkg.myfile_from_healpix(ra, dec)

assert healpix_file == expected

0 comments on commit 0400e4e

Please sign in to comment.