Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove specutils cap #421

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
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
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ authors = [
{ name = "Peter Teuben", email = "teuben@umd.edu" },
{ name = "Thomas Chamberlin", email = "tchamber@nrao.edu" },
{ name = "Pedro Salas", email = "psalas@nrao.edu" },
{ name = "Evan Smith", email = "esmith@nrao.edu" },
]
classifiers = [
"Development Status :: 3 - Alpha",
"Programming Language :: Python",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
]
dependencies = [
Expand All @@ -26,7 +30,7 @@ dependencies = [
"numpy",
"pandas",
"scipy",
"specutils",
"specutils>1.16",
"httpx",
"rich",
"tenacity",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ snowballstemmer==2.2.0
# via sphinx
soupsieve==2.5
# via beautifulsoup4
specutils==1.12.0
specutils==1.17.0
# via dysh (pyproject.toml)
sphinx==7.2.6
# via
Expand Down
12 changes: 10 additions & 2 deletions src/dysh/spectra/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def exclude_to_mask(exclude, refspec):


@log_function_call()
def baseline(spectrum, order, exclude=None, **kwargs):
def baseline(spectrum, order, exclude=None, exclude_region_upper_bounds=True, **kwargs):
"""Fit a baseline for a spectrum

Parameters
Expand Down Expand Up @@ -289,6 +289,8 @@ def baseline(spectrum, order, exclude=None, **kwargs):
One of 'polynomial' or 'chebyshev', Default: 'polynomial'
fitter : `~astropy.fitting._FitterMeta`
The fitter to use. Default: `~astropy.fitter.LinearLSQFitter` (with `calc_uncertaintes=True`). Be care when choosing a different fitter to be sure it is optimized for this problem.
exclude_region_upper_bounds : bool
Makes the upper bound of any excision region(s) inclusive. Allows excising channel 0 for lower-sideband data, and the last channel for upper-sideband data.

Returns
-------
Expand Down Expand Up @@ -340,7 +342,13 @@ def baseline(spectrum, order, exclude=None, **kwargs):
# exist (they will be a list of SpectralRegions or None)
regionlist = p._exclude_regions
print(f"EXCLUDING {regionlist}")
return fit_continuum(spectrum=p, model=selected_model, fitter=fitter, exclude_regions=regionlist)
return fit_continuum(
spectrum=p,
model=selected_model,
fitter=fitter,
exclude_regions=regionlist,
exclude_region_upper_bounds=exclude_region_upper_bounds,
)


def mean_tsys(calon, caloff, tcal, mode=0, fedge=0.1, nedge=None):
Expand Down
18 changes: 10 additions & 8 deletions src/dysh/spectra/tests/test_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ def test_radd_scalar(self):
assert addition.velocity_frame == self.ps0.velocity_frame
compare_spectrum(self.ps0, addition)

def test_sub(self):
"""Test that we can subtract two `Spectrum`."""
subtraction = self.ps0 - self.ps1

assert subtraction.meta["EXPOSURE"] == (self.ps0.meta["EXPOSURE"] + self.ps1.meta["EXPOSURE"])
compare_spectrum(self.ps0, addition)

def test_sub(self):
"""Test that we can subtract two `Spectrum`."""
subtraction = self.ps0 - self.ps1
Expand Down Expand Up @@ -363,7 +370,9 @@ def test_smooth_multi(self):

# Check fitter first.
g_fit = fit_gauss(self.ss)
assert g_fit.stddev.value * 2.35482 == pytest.approx(abs(self.ss.meta["CDELT1"]) * self.ss.meta["FWHM"])
assert g_fit.stddev.value * 2.35482 == pytest.approx(
abs(self.ss.meta["CDELT1"]) * self.ss.meta["FWHM"], g_fit.stddev.std * 2.35482
)

# Now smooth the same Spectrum multiple times.
sss = self.ss._copy()
Expand Down Expand Up @@ -419,13 +428,6 @@ def test_shift(self):
# Load GBTIDL answer.
with fits.open(get_project_testdata() / "gshift_box.fits") as hdu:
table = hdu[1].data
gbtidl = table["DATA"][0]

# Compare.
# Ignore the edge channels to avoid edge effects.
diff = (spec.data - gbtidl)[10:-10]
assert np.all(abs(diff) < 5e-4)

assert spec.meta["CRPIX1"] == org_spec.meta["CRPIX1"] + shift
assert spec.spectral_axis[0].to("Hz").value == (
org_spec.spectral_axis[0].to("Hz").value - spec.meta["CDELT1"] * shift
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions testdata/AGBT17A_404_01/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# GBT17A-404

Position-switched HI scans of a nearby galaxy from project [AGBT17A-404](https://dss.gb.nrao.edu/project/GBT17A-404) (PI D.J. Pisano). This data is used for the baseline modelling tests and features a 3rd order baseline with 2 regions of interest (3 regions excised from the baseline modelling)

Some of the integrations have a significant GPS-L3 RFI spike, requiring the excision of integrations 43-51.


To generate the GBTIDL results:
```
filein,'AGBT17A_404_01.raw.vegas.A.fits'
for i=0,42 do begin & getps,19,plnum=0,intnum=i & accum & end
for i=0,42 do begin & getps,19,plnum=1,intnum=i & accum & end
for i=52,60 do begin & getps,19,plnum=0,intnum=i & accum & end
for i=52,60 do begin & getps,19,plnum=1,intnum=i & accum & end
ave
boxcar,5,/decimate
copy,0,1
fileout,'AGBT17A_404_01_scan_19_prebaseline.fits'
keep
;precisely place fitting regions for baseline
!g.nregion=2
!g.regions[0,0] = 100
!g.regions[1,0] = 380
!g.regions[0,1] = 450
!g.regions[1,1] = 720
bshape,nfit=3,modelbuffer=2
bsubtract
fileout,'AGBT17A_404_01_scan_19_postbaseline.fits'
keep
copy,2,0
fileout,'AGBT17A_404_01_scan_19_bmodel.fits'
keep
```

To generate the dysh results:
```
import numpy as np
from dysh.fits.gbtfitsload import GBTFITSLoad
import dysh

#where to find the data?
fname_base = "[/path/to/dysh]/dysh/testdata/AGBT17A_404_01/"
pre_fname = fname_base + 'AGBT17A_404_01_scan_19_prebaseline.fits'
post_fname = fname_base + 'AGBT17A_404_01_scan_19_postbaseline.fits'
bline_fname = fname_base+ 'AGBT17A_404_01_scan_19_bmodel.fits'

#load in with dysh, get data
sdf = dysh.fits.gbtfitsload.GBTFITSLoad(pre_fname)
dysh_spectrum = sdf.getspec(0)

#set baseline parameters and fit
order = 3
excised_regions = [(0,100),(381,450),(751,820)]




```
Loading