Skip to content

Commit

Permalink
Merge pull request #57 from p-slash/flux-calibration
Browse files Browse the repository at this point in the history
flux stacker in picca continuum enabled and saved to attributes file
  • Loading branch information
p-slash authored Apr 25, 2023
2 parents 299d36e + 3ee08c7 commit d9ca880
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions py/qsonic/picca_continuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class PiccaContinuumFitter():
Rank of the MPI process.
meanflux_interp: FastLinear1DInterp
Interpolator for mean flux. If fiducial is not set, this equals to 1.
flux_stacker: FluxStacker (disabled)
flux_stacker: FluxStacker
Stacks flux. Set up with 8 A wavelength bin size.
varlss_fitter: VarLSSFitter or None
None if fiducials are set for var_lss.
Expand Down Expand Up @@ -204,8 +204,8 @@ def __init__(self, args):
self.meanflux_interp = FastLinear1DInterp(
args.wave1, args.wave2 - args.wave1, np.ones(3))

# self.flux_stacker = FluxStacker(
# args.wave1, args.wave2, 8., comm=self.comm)
self.flux_stacker = FluxStacker(
args.wave1, args.wave2, 8., comm=self.comm)

if args.fiducial_varlss:
self.varlss_fitter = None
Expand Down Expand Up @@ -502,7 +502,7 @@ def update_mean_cont(self, spectra_list, noupdate):
norm_flux = np.zeros(self.nbins)
std_flux = np.empty(self.nbins)
counts = np.zeros(self.nbins)
# self.flux_stacker.reset()
self.flux_stacker.reset()

for spec in valid_spectra(spectra_list):
for arm, wave_arm in spec.forestwave.items():
Expand All @@ -521,9 +521,9 @@ def update_mean_cont(self, spectra_list, noupdate):
counts += np.bincount(
bin_idx, weights=weight, minlength=self.nbins)

# self.flux_stacker.add(wave_arm, flux, weight)
self.flux_stacker.add(wave_arm, flux, weight)

# self.flux_stacker.calculate()
self.flux_stacker.calculate()
self.comm.Allreduce(MPI.IN_PLACE, norm_flux)
self.comm.Allreduce(MPI.IN_PLACE, counts)
w = counts > 0
Expand Down Expand Up @@ -710,10 +710,10 @@ def save(self, fattr, suff=''):
names=['lambda_rf', 'mean_cont', 'e_mean_cont'],
extname=f'CONT{suff}')

# fattr.write(
# [self.flux_stacker.waveobs, self.flux_stacker.stacked_flux],
# names=['lambda', 'stacked_flux'],
# extname=f'STACKED_FLUX{suff}')
fattr.write(
[self.flux_stacker.waveobs, self.flux_stacker.stacked_flux],
names=['lambda', 'stacked_flux'],
extname=f'STACKED_FLUX{suff}')

if self.varlss_fitter is None:
return
Expand Down Expand Up @@ -1307,7 +1307,7 @@ class FluxStacker():

def __init__(self, w1obs, w2obs, dwobs, comm=None):
# Set up wavelength and inverse variance bins
self.nwbins = int((w2obs - w1obs) / dwobs)
self.nwbins = int(round((w2obs - w1obs) / dwobs))
wave_edges, self.dwobs = np.linspace(
w1obs, w2obs, self.nwbins + 1, retstep=True)
self.waveobs = (wave_edges[1:] + wave_edges[:-1]) / 2
Expand Down

0 comments on commit d9ca880

Please sign in to comment.