Skip to content
Open
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
39 changes: 39 additions & 0 deletions .github/workflows/example-scripts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Example scripts

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
run-examples:
runs-on: ubuntu-latest

env:
MPLBACKEND: Agg

steps:
- uses: actions/checkout@v5

- name: Install uv
uses: astral-sh/setup-uv@v6
with:
python-version: "3.11"

- name: Setup venv
run: uv python install

- name: Install dependencies
run: uv sync --all-extras --dev

- name: Run example scripts
run: |
for f in examples/*.py; do
echo "Running $f"
uv run python "$f" || exit 1
done

- name: Run example notebooks
run: |
uv run --with nbconvert jupyter nbconvert --to notebook --execute --inplace examples/*.ipynb
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Rascal: RANSAC Assisted Spectral CALibration

[![Python package](https://github.com/jveitchmichaelis/rascal/actions/workflows/python-package.yml/badge.svg)](https://github.com/jveitchmichaelis/rascal/actions/workflows/python-package.yml)
[![Example scripts](https://github.com/jveitchmichaelis/rascal/actions/workflows/example-scripts.yml/badge.svg)](https://github.com/jveitchmichaelis/rascal/actions/workflows/example-scripts.yml)
[![Coverage Status](https://coveralls.io/repos/github/jveitchmichaelis/rascal/badge.svg?branch=main)](https://coveralls.io/github/jveitchmichaelis/rascal?branch=main)
[![Readthedocs Status](https://readthedocs.org/projects/rascal/badge/?version=latest\&style=flat)](https://rascal.readthedocs.io/en/latest/)
[![PyPI version](https://badge.fury.io/py/rascal.svg)](https://badge.fury.io/py/rascal)
Expand Down
6 changes: 5 additions & 1 deletion examples/example_gemini_gmos_longslit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

sys.path.append("../../bhtomspec/GMOS")

from gmos_fieldflattening import create_pixel_array
try:
from gmos_fieldflattening import create_pixel_array
except ImportError:
print("Skipping: gmos_fieldflattening module not available")
sys.exit(0)

pixels = create_pixel_array("north", 2)
rawpix_to_pix_itp = interpolate.interp1d(np.arange(len(pixels)), pixels)
Expand Down
6 changes: 5 additions & 1 deletion examples/example_gemini_gmos_longslit_manual_atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@

sys.path.append("../../bhtomspec/GMOS")

from gmos_fieldflattening import create_pixel_array
try:
from gmos_fieldflattening import create_pixel_array
except ImportError:
print("Skipping: gmos_fieldflattening module not available")
sys.exit(0)

pixels = create_pixel_array("north", 2)
rawpix_to_pix_itp = interpolate.interp1d(np.arange(len(pixels)), pixels)
Expand Down
6 changes: 3 additions & 3 deletions examples/example_gtc_osiris.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

c.do_hough_transform()

c.plot_arc(save_fig="png", filename="output/gtc-osiris-arc-spectrum")
c.plot_arc(save_fig="png", filename=os.path.join(base_dir, "output", "gtc-osiris-arc-spectrum"))

c.do_hough_transform()

Expand All @@ -105,7 +105,7 @@
log_spectrum=False,
tolerance=5.0,
save_fig="png",
filename="output/gtc-osiris-wavelength-calibration",
filename=os.path.join(base_dir, "output", "gtc-osiris-wavelength-calibration"),
)

# Show the parameter space for searching possible solution
Expand All @@ -114,4 +114,4 @@
print("Peaks utilisation rate: {}%".format(peak_utilisation * 100))
print("Atlas utilisation rate: {}%".format(atlas_utilisation * 100))

c.plot_search_space(save_fig="png", filename="output/gtc-osiris-search-space")
c.plot_search_space(save_fig="png", filename=os.path.join(base_dir, "output", "gtc-osiris-search-space"))
11 changes: 7 additions & 4 deletions examples/example_keck_deimos_830g.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os

import numpy as np
from scipy.signal import find_peaks
Expand All @@ -8,15 +9,17 @@
from rascal.util import refine_peaks

# Load the 1D Spectrum from Pypeit
spectrum_json = json.load(open("data_keck_deimos/keck_deimos_830g_l_PYPIT.json"))
base_dir = os.path.dirname(__file__)
os.makedirs(os.path.join(base_dir, "output"), exist_ok=True)
spectrum_json = json.load(open(os.path.join(base_dir, "data_keck_deimos/keck_deimos_830g_l_PYPIT.json")))
spectrum = np.array(spectrum_json["spec"])

# Identify the arc lines
peaks, _ = find_peaks(spectrum, prominence=200, distance=10)
peaks = refine_peaks(spectrum, peaks, window_width=3)

c = Calibrator(peaks, spectrum=spectrum)
c.plot_arc(save_fig="png", filename="output/keck-deimos-arc-spectrum")
c.plot_arc(save_fig="png", filename=os.path.join(base_dir, "output", "keck-deimos-arc-spectrum"))
c.set_hough_properties(
num_slopes=10000.0,
range_tolerance=500.0,
Expand Down Expand Up @@ -66,7 +69,7 @@
log_spectrum=False,
tolerance=5.0,
save_fig="png",
filename="output/keck-deimos-wavelength-calibration",
filename=os.path.join(base_dir, "output", "keck-deimos-wavelength-calibration"),
)

# Show the parameter space for searching possible solution
Expand All @@ -75,4 +78,4 @@
print("Peaks utilisation rate: {}%".format(peak_utilisation * 100))
print("Atlas utilisation rate: {}%".format(atlas_utilisation * 100))

c.plot_search_space(save_fig="png", filename="output/keck-deimos-search-space")
c.plot_search_space(save_fig="png", filename=os.path.join(base_dir, "output", "keck-deimos-search-space"))
9 changes: 5 additions & 4 deletions examples/example_lt_sprat_xe_manual_atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
plt.xlabel("Spectral Direction / Pix")
plt.ylabel("Spatial Direction / Pix")
plt.tight_layout()
plt.savefig("output/lt-sprat-arc-image.png")
os.makedirs(os.path.join(base_dir, "output"), exist_ok=True)
plt.savefig(os.path.join(base_dir, "output", "lt-sprat-arc-image.png"))

# Collapse into 1D spectrum between row 110 and 120
spectrum = np.median(spectrum2D[110:120], axis=0)
Expand Down Expand Up @@ -126,7 +127,7 @@
print("Atlas utilisation rate: {}%".format(atlas_utilisation * 100))

c.use_matplotlib()
c.plot_arc(save_fig="png", filename="output/lt-sprat-arc-spectrum")
c.plot_arc(save_fig="png", filename=os.path.join(base_dir, "output", "lt-sprat-arc-spectrum"))

# Plot the solution
c.plot_fit(
Expand All @@ -136,8 +137,8 @@
log_spectrum=False,
tolerance=5.0,
save_fig="png",
filename="output/lt-sprat-wavelength-calibration",
filename=os.path.join(base_dir, "output", "lt-sprat-wavelength-calibration"),
)

# Show the parameter space for searching possible solution
c.plot_search_space(save_fig="png", filename="output/lt-sprat-search-space")
c.plot_search_space(save_fig="png", filename=os.path.join(base_dir, "output", "lt-sprat-search-space"))
5 changes: 4 additions & 1 deletion examples/example_ntt_efosc_grism11.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from astropy.io import fits
import numpy as np
from scipy.signal import find_peaks
Expand All @@ -7,7 +9,8 @@
from rascal.util import refine_peaks

# Load the 1D Spectrum from Pypeit
data = fits.open("data_eso36_efosc/EFOSC_spec_HeAr227_0005.fits")[0]
base_dir = os.path.dirname(__file__)
data = fits.open(os.path.join(base_dir, "data_eso36_efosc/EFOSC_spec_HeAr227_0005.fits"))[0]
spectrum = np.median(data.data.T, axis=0)

# Identify the arc lines
Expand Down
9 changes: 5 additions & 4 deletions examples/example_wht_isis_r300r.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
plt.xlabel("Spectral Direction / Pix")
plt.ylabel("Spatial Direction / Pix")
plt.tight_layout()
plt.savefig("output/wht-isis-arc-image.png")
os.makedirs(os.path.join(base_dir, "output"), exist_ok=True)
plt.savefig(os.path.join(base_dir, "output", "wht-isis-arc-image.png"))

# Identify the peaks
peaks, _ = find_peaks(spectrum, height=500, prominence=100, distance=5, threshold=None)
peaks = util.refine_peaks(spectrum, peaks, window_width=3)

# Initialise the calibrator
c = Calibrator(peaks, spectrum=spectrum)
c.plot_arc(log_spectrum=True, save_fig="png", filename="output/wht-isis-arc-spectrum")
c.plot_arc(log_spectrum=True, save_fig="png", filename=os.path.join(base_dir, "output", "wht-isis-arc-spectrum"))
c.set_hough_properties(
num_slopes=10000,
xbins=500,
Expand Down Expand Up @@ -75,11 +76,11 @@
log_spectrum=False,
tolerance=5.0,
save_fig="png",
filename="output/wht-isis-wavelength-calibration",
filename=os.path.join(base_dir, "output", "wht-isis-wavelength-calibration"),
)

# Show the parameter space for searching possible solution
c.plot_search_space(save_fig="png", filename="output/wht-isis-search-space")
c.plot_search_space(save_fig="png", filename=os.path.join(base_dir, "output", "wht-isis-search-space"))

print("Stdev error: {} A".format(residual.std()))
print("Peaks utilisation rate: {}%".format(peak_utilisation * 100))
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "rascal"
version = "0.4.0"
Expand Down
4 changes: 2 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading