Skip to content

Commit

Permalink
fix dwave in rebin
Browse files Browse the repository at this point in the history
  • Loading branch information
cramirezpe committed Jan 17, 2023
1 parent 5dd9bd4 commit 59313e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
8 changes: 4 additions & 4 deletions py/picca/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ class Delta(QSO):
Neighbouring deltas/quasars
fname: string or None
String identifying Delta as part of a group
delta_log_lambda
Methods:
__init__: Initializes class instances.
Expand Down Expand Up @@ -1315,17 +1316,16 @@ def project(self):

self.delta -= mean_delta + res

def rebin(self, factor):
def rebin(self, factor, dwave=0.8):
"""Rebin deltas by an integer factor
Args:
factor: int
Factor to rebin deltas (new_bin_size = factor * old_bin_size)
dwave: float
Delta lambda of original deltas
"""
wave = 10**np.array(self.log_lambda)
dwave = wave[1] - wave[0]
if not np.isclose(dwave, wave[-1] - wave[-2]):
raise ValueError('Delta rebinning only implemented for linear lambda bins')

start = wave.min() - dwave / 2
num_bins = np.ceil(((wave[-1] - wave[0]) / dwave + 1) / factor)
Expand Down
22 changes: 18 additions & 4 deletions py/picca/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1439,8 +1439,19 @@ def read_delta_file(filename, rebin_factor=None):

# Rebin
if rebin_factor is not None:
if 'LAMBDA' in hdul:
card = 'METADATA'
else:
card = 1

if hdul[card].read_header()['WAVE_SOLUTION'] != 'lin':
raise ValueError('Delta rebinning only implemented for linear \
lambda bins')

dwave = hdul[card].read_header()['DELTA_LAMBDA']

for i in range(len(deltas)):
deltas[i].rebin(rebin_factor)
deltas[i].rebin(rebin_factor, dwave=dwave)

return deltas

Expand Down Expand Up @@ -1513,9 +1524,12 @@ def read_deltas(in_dir,
userprint(f"Rebinning deltas by a factor of {rebin_factor}\n")

arguments = [(f, rebin_factor) for f in files]
pool = Pool(processes=nproc)
results = pool.starmap(read_delta_file, arguments)
pool.close()
results = []
for argument in arguments:
results.append(read_delta_file(*argument))
# pool = Pool(processes=nproc)
# results = pool.starmap(read_delta_file, arguments)
# pool.close()

deltas = []
num_data = 0
Expand Down

0 comments on commit 59313e6

Please sign in to comment.