Skip to content

Commit

Permalink
Merge pull request #12 from desihub/zfind_dirs
Browse files Browse the repository at this point in the history
redmonster is once again an optional dependency
  • Loading branch information
sbailey committed Apr 16, 2015
2 parents d4f9134 + 84b7b3d commit 6923cc9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 60 deletions.
2 changes: 1 addition & 1 deletion bin/desi_zfind.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from desispec import io
from desispec.interpolation import resample_flux
from desispec.log import get_logger
from desispec.zfind import RedMonsterZfind
from desispec.zfind.redmonster import RedMonsterZfind

import optparse

Expand Down
1 change: 1 addition & 0 deletions py/desispec/zfind/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .zfind import ZfindBase
62 changes: 3 additions & 59 deletions py/desispec/zfind.py → py/desispec/zfind/redmonster.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,15 @@
from __future__ import division, absolute_import

import os

import numpy as np
from redmonster.physics.zfinder import Zfinder
from redmonster.physics.zfitter import Zfitter
from redmonster.physics.zpicker import Zpicker

from desispec.zfind import ZfindBase
from desispec.interpolation import resample_flux

class ZfindBase(object):
def __init__(self, wave, flux, ivar, R=None, results=None):
"""
Base class of classification / redshift finders.
Args:
wave : 1D[nwave] wavelength grid [Angstroms]
flux : 2D[nspec, nwave] flux [erg/s/cm2/A]
ivar : 2D[nspec, nwave] inverse variance of flux
Optional:
R : 1D[nspec] list of resolution objects
results : ndarray with keys such as z, zerr, zwarn (see below)
all results.dtype.names are added to this object
Subclasses should perform classification and redshift fitting
upon initialization and set the following member variables:
nspec : number of spectra
nwave : number of wavelegths (may be resampled from input)
z : 1D[nspec] best fit redshift
zerr : 1D[nspec] redshift uncertainty estimate
zwarn : 1D[nspec] integer redshift warning bitmask (details TBD)
type : 1D[nspec] classification [GALAXY, QSO, STAR, ...]
subtype : 1D[nspec] sub-classification
wave : 1D[nwave] wavelength grid used; may be resampled from input
flux : 2D[nspec, nwave] flux used; may be resampled from input
ivar : 2D[nspec, nwave] ivar of flux
model : 2D[nspec, nwave] best fit model
chi2?
zbase?
For the purposes of I/O, it is possible to create a ZfindBase
object that contains only the results, without the input
wave, flux, ivar, or output model.
"""
#- Inputs
if flux is not None:
nspec, nwave = flux.shape
self.nspec = nspec
self.nwave = nwave
self.wave = wave
self.flux = flux
self.ivar = ivar
self.R = R

#- Outputs to fill
if results is None:
self.model = np.zeros((nspec, nwave), dtype=flux.dtype)
self.z = np.zeros(nspec)
self.zerr = np.zeros(nspec)
self.zwarn = np.zeros(nspec, dtype=int)
self.type = np.zeros(nspec, dtype='S20')
self.subtype = np.zeros(nspec, dtype='S20')
else:
for key in results.dtype.names:
self.__setattr__(key.lower(), results[key])


class RedMonsterZfind(ZfindBase):
def __init__(self, wave, flux, ivar, R=None, dloglam=1e-4):
"""
Expand Down
60 changes: 60 additions & 0 deletions py/desispec/zfind/zfind.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import numpy as np

class ZfindBase(object):
def __init__(self, wave, flux, ivar, R=None, results=None):
"""
Base class of classification / redshift finders.
Args:
wave : 1D[nwave] wavelength grid [Angstroms]
flux : 2D[nspec, nwave] flux [erg/s/cm2/A]
ivar : 2D[nspec, nwave] inverse variance of flux
Optional:
R : 1D[nspec] list of resolution objects
results : ndarray with keys such as z, zerr, zwarn (see below)
all results.dtype.names are added to this object
Subclasses should perform classification and redshift fitting
upon initialization and set the following member variables:
nspec : number of spectra
nwave : number of wavelegths (may be resampled from input)
z : 1D[nspec] best fit redshift
zerr : 1D[nspec] redshift uncertainty estimate
zwarn : 1D[nspec] integer redshift warning bitmask (details TBD)
type : 1D[nspec] classification [GALAXY, QSO, STAR, ...]
subtype : 1D[nspec] sub-classification
wave : 1D[nwave] wavelength grid used; may be resampled from input
flux : 2D[nspec, nwave] flux used; may be resampled from input
ivar : 2D[nspec, nwave] ivar of flux
model : 2D[nspec, nwave] best fit model
chi2?
zbase?
For the purposes of I/O, it is possible to create a ZfindBase
object that contains only the results, without the input
wave, flux, ivar, or output model.
"""
#- Inputs
if flux is not None:
nspec, nwave = flux.shape
self.nspec = nspec
self.nwave = nwave
self.wave = wave
self.flux = flux
self.ivar = ivar
self.R = R

#- Outputs to fill
if results is None:
self.model = np.zeros((nspec, nwave), dtype=flux.dtype)
self.z = np.zeros(nspec)
self.zerr = np.zeros(nspec)
self.zwarn = np.zeros(nspec, dtype=int)
self.type = np.zeros(nspec, dtype='S20')
self.subtype = np.zeros(nspec, dtype='S20')
else:
for key in results.dtype.names:
self.__setattr__(key.lower(), results[key])

0 comments on commit 6923cc9

Please sign in to comment.