Skip to content

Commit

Permalink
Merge pull request #300 from desihub/max-velo-diff-star
Browse files Browse the repository at this point in the history
set max_velo_diff  to 100 km/s for stars
  • Loading branch information
sbailey authored Apr 25, 2024
2 parents 1c5ed8f + 19c7e84 commit 4116707
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions py/redrock/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Set constants used by the rest of the package.
"""
max_velo_diff = 1000.0 # km/s
max_velo_diff_star = 100.0 # km/s
min_resolution_integral = 0.99

min_deltachi2 = 9.
Expand Down
13 changes: 9 additions & 4 deletions py/redrock/fitz.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,20 @@ def fitz(zchi2, redshifts, target, template, nminima=3, archetype=None, use_gpu=
else:
nz = zminfit_npoints

if template.template_type == 'STAR':
max_velo_diff = constants.max_velo_diff_star
else:
max_velo_diff = constants.max_velo_diff

for imin in find_minima(zchi2):
if len(results) == nminima:
break

#- Skip this minimum if it is within constants.max_velo_diff km/s of a
#- Skip this minimum if it is within max_velo_diff km/s of a
# previous one dv is in km/s
zprev = np.array([tmp['z'] for tmp in results])
dv = get_dv(z=redshifts[imin],zref=zprev)
if np.any(np.abs(dv) < constants.max_velo_diff):
if np.any(np.abs(dv) < max_velo_diff):
continue

#- Sample more finely around the minimum
Expand Down Expand Up @@ -309,10 +314,10 @@ def fitz(zchi2, redshifts, target, template, nminima=3, archetype=None, use_gpu=
zwarn |= ZW.Z_FITLIMIT

#- Skip this better defined minimum if it is within
#- constants.max_velo_diff km/s of a previous one
#- max_velo_diff km/s of a previous one
zprev = np.array([tmp['z'] for tmp in results])
dv = get_dv(z=zbest, zref=zprev)
if np.any(np.abs(dv) < constants.max_velo_diff):
if np.any(np.abs(dv) < max_velo_diff):
continue

if archetype is None:
Expand Down
12 changes: 9 additions & 3 deletions py/redrock/zfind.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ def sort_zfit_dict(zfit):
sort_dict_by_cols(zfit, ('__badfit__', 'chi2'), sort_first_column_first=True)
zfit.pop('__badfit__')

def zfind(targets, templates, mp_procs=1, nminima=3, archetypes=None, priors=None, chi2_scan=None, use_gpu=False, zminfit_npoints=15, per_camera=None, deg_legendre=None, n_nearest=None, prior_sigma=None, ncamera=None):
def zfind(targets, templates, mp_procs=1, nminima=3, archetypes=None, priors=None, chi2_scan=None, use_gpu=False,
zminfit_npoints=15, per_camera=None, deg_legendre=None, n_nearest=None, prior_sigma=None, ncamera=None):
"""Compute all redshift fits for the local set of targets and collect.
Given targets and templates distributed across a set of MPI processes,
Expand Down Expand Up @@ -438,6 +439,11 @@ def zfind(targets, templates, mp_procs=1, nminima=3, archetypes=None, priors=Non
else:
spectype, subtype = parse_fulltype(fulltype)

if spectype.upper() == 'STAR':
max_velo_diff = constants.max_velo_diff_star
else:
max_velo_diff = constants.max_velo_diff

#Have to create arrays of correct length since using dict of
#np arrays instead of astropy Table
nmin = len(tmp['chi2'])
Expand Down Expand Up @@ -524,8 +530,8 @@ def zfind(targets, templates, mp_procs=1, nminima=3, archetypes=None, priors=Non
tzfit['znum'] = np.arange(l)

#- calc deltachi2 and set ZW.SMALL_DELTA_CHI2 flag
deltachi2, setzwarn = calc_deltachi2(
tzfit['chi2'], tzfit['z'], tzfit['zwarn'])
deltachi2, setzwarn = calc_deltachi2(tzfit['chi2'], tzfit['z'], tzfit['zwarn'],
dvlimit=max_velo_diff)
tzfit['deltachi2'] = deltachi2
tzfit['zwarn'][setzwarn] |= ZW.SMALL_DELTA_CHI2

Expand Down

0 comments on commit 4116707

Please sign in to comment.