Skip to content

Commit

Permalink
fix instrument wavecal bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-simpson committed Apr 20, 2024
1 parent 3c0c1b2 commit fd0235e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion geminidr/core/primitives_spect.py
Original file line number Diff line number Diff line change
Expand Up @@ -5304,7 +5304,7 @@ def _apply_wavelength_model_bounds(self, model=None, ext=None):
elif i == 1: # half the wavelength extent (~dispersion)
prange = 0.02 * abs(pvalue)
else: # higher-order terms
prange = 1
prange = 20
getattr(model, pname).bounds = (pvalue - prange, pvalue + prange)


Expand Down
4 changes: 2 additions & 2 deletions geminidr/gmos/primitives_gmos_spect.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ def _apply_wavelength_model_bounds(self, model=None, ext=None):
if i == 0: # central wavelength
prange = 10
elif i == 1: # half the wavelength extent (~dispersion)
prange = 0.02 * abs(pvalue)
prange = 0.05 * abs(pvalue)
else: # higher-order terms
prange = 1
prange = 2
getattr(model, pname).bounds = (pvalue - prange, pvalue + prange)
22 changes: 9 additions & 13 deletions geminidr/gnirs/primitives_gnirs_spect.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,16 +430,12 @@ def _get_arc_linelist(self, ext, waves=None):
def _apply_wavelength_model_bounds(self, model=None, ext=None):
# Apply bounds to an astropy.modeling.models.Chebyshev1D to indicate
# the range of parameter space to explore
dispaxis = 2 - ext.dispersion_axis()
npix = ext.shape[dispaxis]
for i, (pname, pvalue) in enumerate(zip(model.param_names, model.parameters)):
if i == 0: # central wavelength
if 'ARC' in ext.tags or ext.filter_name(pretty=True)[0] in 'LM':
prange = 10
else:
prange = abs(ext.dispersion(asNanometers=True)) * npix * 0.07
elif i == 1: # half the wavelength extent (~dispersion)
prange = 0.02 * abs(pvalue)
else: # higher-order terms
prange = 20
getattr(model, pname).bounds = (pvalue - prange, pvalue + prange)
# GNIRS has a different central wavelength uncertainty
super()._apply_wavelength_model_bounds(model, ext)
if 'ARC' in ext.tags or not (ext.filter_name(pretty=True)[0] in 'LM'):
prange = 10
else:
dispaxis = 2 - ext.dispersion_axis()
npix = ext.shape[dispaxis]
prange = abs(ext.dispersion(asNanometers=True)) * npix * 0.07
model.c0.bounds = (model.c0 - prange, model.c0 + prange)
5 changes: 4 additions & 1 deletion gempy/library/wavecal.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,16 +812,19 @@ def perform_piecewise_fit(model, peaks, arc_lines, pixel_start, kdsigma,
m_init = models.Chebyshev1D(1, c0=c0, c1=c1,
domain=[p0 - p1, p0 + p1])
bounds_setter(m_init)
#print(m_init.bounds)
if not first:
m_init.c0.bounds = (c0 - 5 * abs(dw), c0 + 5 * abs(dw))
#print("INPUT MODEL")
#print(m_init.parameters)
#print(m_init.bounds)
#print(datetime.now() - start)

# Need to set in_weights=None as there aren't many lines so
# the fit could be swayed by a single very bright line
m_this = _fit_region(m_init, peaks, arc_lines, kdsigma,
in_weights=None, ref_weights=arc_weights,
matches=matches, k=k, first=first)
#print("OUTPUT", m_this.parameters)
dw = 2 * m_this.c1 / np.diff(m_this.domain)[0]

# Add new matches to the list
Expand Down

0 comments on commit fd0235e

Please sign in to comment.