Skip to content
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
32 changes: 13 additions & 19 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,25 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v2
- uses: s-weigand/setup-conda@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
- uses: actions/checkout@v5

- name: Install uv
uses: astral-sh/setup-uv@v6
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ matrix.python-version }}

- name: Setup venv
run: uv python install

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 coverage psutil requests kaleido
python -m pip install -r requirements.txt
python -m pip install -r test-requirements.txt
python -m pip install -e .
- 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
run: uv sync --all-extras --dev

- name: Test with pytest
run: |
coverage run -m pytest --disable-warnings -p no:warnings test
uv run python -m coverage run -m pytest -v --disable-warnings -p no:warnings test
- name: Generate Coveralls reports
if: startsWith(matrix.os, 'ubuntu')
uses: AndreMiras/coveralls-python-action@develop
Expand Down
34 changes: 9 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
repos:
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
language_version: python3
args: # arguments to configure black
- --line-length=79

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand All @@ -23,20 +15,12 @@ repos:
- id: debug-statements
- id: requirements-txt-fixer

- repo: local
hooks:
- id: remarklint
name: remarklint
language: node
entry: remark
types: [markdown]
args: ["--frail", "--quiet"]
additional_dependencies:
[
remark,
remark-lint,
remark-cli,
remark-preset-lint-recommended,
remark-lint-list-item-indent,
remark-lint-no-undefined-references,
]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.14.0
hooks:
# Run the linter.
- id: ruff-check
args: [ --fix ]
# Run the formatter.
- id: ruff-format
23 changes: 8 additions & 15 deletions calibration_test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import astropy.units as u\n",
"from astropy.io import fits\n",
"from scipy.signal import find_peaks\n",
"from rascal.calibrator import Calibrator\n",
Expand Down Expand Up @@ -51,19 +50,16 @@
}
],
"source": [
"spectrum = np.median(fits.open('./examples/v_a_20190516_55_1_0_1.fits')[0].data[110:120], axis=0)\n",
"spectrum = np.median(fits.open(\"./examples/v_a_20190516_55_1_0_1.fits\")[0].data[110:120], axis=0)\n",
"print(spectrum.shape)\n",
"\n",
"resampled_flux = resample(spectrum-spectrum.min(), len(spectrum)*4)\n",
"resampled_flux = resample(spectrum - spectrum.min(), len(spectrum) * 4)\n",
"peaks, _ = find_peaks(resampled_flux, prominence=150, distance=20, threshold=None)\n",
"peaks = peaks / 4.0\n",
"\n",
"plt.figure(figsize=(18,3))\n",
"plt.figure(figsize=(18, 3))\n",
"plt.plot(spectrum)\n",
"plt.vlines(peaks,\n",
" spectrum[peaks.astype('int')],\n",
" spectrum.max(),\n",
" colors='C1')"
"plt.vlines(peaks, spectrum[peaks.astype(\"int\")], spectrum.max(), colors=\"C1\")"
]
},
{
Expand All @@ -72,10 +68,7 @@
"metadata": {},
"outputs": [],
"source": [
"c = Calibrator(peaks, elements=[\"Xe_strong\"],\n",
" min_wavelength=3400.,\n",
" max_wavelength=8100.,\n",
" range_tolerance=200)\n",
"c = Calibrator(peaks, elements=[\"Xe_strong\"], min_wavelength=3400.0, max_wavelength=8100.0, range_tolerance=200)\n",
"c.set_fit_constraints(n_pix=len(spectrum))"
]
},
Expand Down Expand Up @@ -155,10 +148,10 @@
}
],
"source": [
"peaks, wavelengths, lamps = np.loadtxt(\"./examples/ground_truth_v_a.csv\", delimiter=',', dtype='U').T\n",
"peaks, wavelengths, lamps = np.loadtxt(\"./examples/ground_truth_v_a.csv\", delimiter=\",\", dtype=\"U\").T\n",
"\n",
"peaks = peaks.astype('float32')\n",
"wavelengths = wavelengths.astype('float32')\n",
"peaks = peaks.astype(\"float32\")\n",
"wavelengths = wavelengths.astype(\"float32\")\n",
"\n",
"x, y = c._combine_linear_estimates(c.candidates)\n",
"plt.scatter(x, y, s=20, label=\"Candidate match\")\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@
html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
# html_static_path = ["_static"]
except:
except: #noqa E722
html_theme = "alabaster"
# html_static_path = ["_static"]
12 changes: 3 additions & 9 deletions docs/source/thresh_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
# data point
pix = np.arange(0, 1001, 50)
wave = 4000.0 + pix**0.63437 * 50.0
plt.scatter(
pix, wave, label="Solution", c="midnightblue", s=10, marker="x", zorder=15
)
plt.scatter(pix, wave, label="Solution", c="midnightblue", s=10, marker="x", zorder=15)

# minmax & range tolerance
wave_min = 4000.0
Expand All @@ -29,9 +27,7 @@
lw=1,
c="orangered",
)
plt.plot(
[pix[0], pix[-1]], [wave_min, wave_min], c="orangered", lw=1, label=""
)
plt.plot([pix[0], pix[-1]], [wave_min, wave_min], c="orangered", lw=1, label="")
plt.plot(
[pix[0], pix[-1]],
[wave_max - range_tolerance, wave_max - range_tolerance],
Expand All @@ -47,9 +43,7 @@
lw=1,
c="orangered",
)
plt.plot(
[pix[0], pix[-1]], [wave_max, wave_max], c="orangered", lw=1, label=""
)
plt.plot([pix[0], pix[-1]], [wave_max, wave_max], c="orangered", lw=1, label="")

plt.annotate(
s="",
Expand Down
Loading