Example #1
0
    def _r_and_a(row, passthrough, accumulate_result, find_pins=True, fiber=None, exposure=None):
        grid = (skyexp_wlen_out if not use_loglam else skyexp_loglam_out) \
                    if use_skyexp_fid else (10**bdspec.fiducial_loglam if not use_loglam \
                    else bdspec.fiducial_loglam)
        resampled_data = resample(row, ('wavelength' if not use_loglam else 'loglam'), grid, passthrough)
        pins = None
        if find_pins:
            pins = _find_grid_pins(resampled_data, fiber, exposure)

        return accumulate(accumulate_result, resampled_data, data_out=accumulate_result,
                    join=('wavelength' if not use_loglam else 'loglam'),
                    add=('flux'), weight='ivar'), \
                pins
Example #2
0
    def _r_and_a(row,
                 passthrough,
                 accumulate_result,
                 find_pins=True,
                 fiber=None,
                 exposure=None):
        grid = (skyexp_wlen_out if not use_loglam else skyexp_loglam_out) \
                    if use_skyexp_fid else (10**bdspec.fiducial_loglam if not use_loglam \
                    else bdspec.fiducial_loglam)
        resampled_data = resample(
            row, ('wavelength' if not use_loglam else 'loglam'), grid,
            passthrough)
        pins = None
        if find_pins:
            pins = _find_grid_pins(resampled_data, fiber, exposure)

        return accumulate(accumulate_result, resampled_data, data_out=accumulate_result,
                    join=('wavelength' if not use_loglam else 'loglam'),
                    add=('flux'), weight='ivar'), \
                pins
Example #3
0
File: stax.py Project: zpace/dyson
    def incorporate_galaxy(self, plateifu, path_to_assign, elresids, z_map):
        '''incorporate a galaxy into the bin stack
        '''
        with fits.open(path_to_assign) as assign_hdu:
            goes_in_this_bin = self.spaxels_in_bin(assign_hdu)

        # are there any matching spaxels in this galaxy?
        # if yes, process them
        if goes_in_this_bin.sum() > 0:
            for i, j in zip(*np.where(goes_in_this_bin)):
                self.data_accum = accumulate(data1_in=self.data_accum,
                                             data2_in=elresids[:, i, j],
                                             data_out=self.data_accum,
                                             add='diffs',
                                             weight='ivars')

            self.z_accum.extend(z_map[goes_in_this_bin])

        # if no, proceed
        else:
            pass
Example #4
0
for file in os.listdir(path):
    if fnmatch.fnmatch(file, pattern):
        data2 = Table.read(os.path.join(path, file), format="ascii")
        plot_it(data2, key, data_col=data_col, title=file, stack=True)
        data_as_is.append(data2)

        if data is None:
            data = data2
            if 'wavelength' in data.colnames:
                key = 'wavelength'
            else:
                key = 'loglam'
        else:
            weight = 'ivar' if 'ivar' in data2.colnames else None
            add_names = [name for name in data2.colnames if name not in [weight, key]]
            result = accumulate(np.array(data), np.array(data2), result, join=key, add=add_names, weight=weight)

plt.show()
plt.close()

if result is None:
    result = data

peaks_table = None
if peaks is not None:
    peaks_table = Table.read(os.path.join(path, peaks), format="ascii")

    plot_it(result, key, peaks_table, no_con_flux=False, unmask=True)

'''
if 'loglam' not in result.dtype.names:
    plt.fill_between(wlen, flux, lw=0, color="red")
    plt.errorbar(wlen, flux, dflux, color="black", alpha=0.5, ls="None", capthick=0)
    plt.xlim(np.min(wlen), np.max(wlen))
    plt.ylim(0, np.percentile(flux + dflux, truncate_percentile))
    plt.xlabel("Wavelength ($\AA$)")
    plt.ylabel("Flux $10^{-17}$ erg/(s cm$^2 \AA$)")
    plt.show()


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"
    )
spec_sky["flux"] += spec_sky["sky"]

plot_stack(spec_sky, truncate_percentile=97.5)


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"
    )
plate_sky["flux"] += plate_sky["sky"]