Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deltas rebin #967

Merged
merged 4 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add explanation and type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I copied this line when it was already there.


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
13 changes: 12 additions & 1 deletion 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