dkirkby / bossdata

Tools for accessing SDSS BOSS data
MIT License
1 stars 3 forks source link

Add options to get_valid_data methods #88

Closed dkirkby closed 9 years ago

dkirkby commented 9 years ago

This is an update to get_valid_data in SpecFile, PlateFile and FrameFile. The new options are:

use_ivar: Replace ``dflux`` with ``ivar`` (inverse variance) in the returned
    data.
use_loglam: Replace ``wavelength`` with ``loglam`` (``log10(wavelength)``) in
    the returned data.
fiducial_grid: Return co-added data using the fiducial wavelength grid defined
    by :attr:`fiducial_pixel_index_range`.  If False, the returned array uses
    the native grid of the SpecFile, which generally trims pixels on both ends
    that have zero inverse variance.  Set this value True to ensure that all
    co-added spectra use aligned wavelength grids when this matters.

The last option only applies to the coadd of a (non-lite) SpecFile and does not apply at all to a FrameFile.

dkirkby commented 9 years ago

This PR is supposed to fix #86 and #67, and is designed to take advantage of the new speclite.combine module.

dkirkby commented 9 years ago

@dcunning11235 @dmargala Do either of you have time to check this PR today?

dmargala commented 9 years ago

taking a look now...

dkirkby commented 9 years ago

Here are examples of stacking sky using the new options with the new speclite package, for reference:

# Stack spec-lite sky spectra
spec_sky = None
for row in sky_table:
    filename = finder.get_spec_path(plate=row['PLATE'], mjd=row['MJD'], fiber=row['FIBER'], lite=True)
    spectrum = bossdata.spec.SpecFile(mirror.get(filename))
    data = spectrum.get_valid_data(include_sky=True, use_ivar=True, fiducial_grid=True)
    spec_sky = speclite.accumulate(spec_sky, data, data_out=spec_sky, join='wavelength',
                                   add=('flux', 'sky'), weight='ivar')

# Stack spectra from a plate file
plate_sky = None
filename = finder.get_plate_spec_path(plate=6641, mjd=56383)
plate = bossdata.plate.PlateFile(mirror.get(filename))
plate_data = plate.get_valid_data(sky_table['FIBER'], include_sky=True, use_ivar=True, fiducial_grid=True)
for data in plate_data:
    plate_sky = speclite.accumulate(plate_sky, data, data_out=plate_sky, join='wavelength',
                                    add=('flux', 'sky'), weight='ivar')