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

Fixed handling of the saturate keyword when we multiply be an array. #298

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all 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
27 changes: 21 additions & 6 deletions banzai/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,35 @@ def __getitem__(self, section):
return self.trim(trim_section=section)

def __imul__(self, value):
# TODO: Handle the case where this is an array. Add SATURATE and GAIN handling when array.
self.data *= value
self.uncertainty *= value
self.meta['SATURATE'] *= value
self.meta['GAIN'] /= value
self.meta['MAXLIN'] *= value
# Note: For array inputs, we need the arrays to be normalized around 1 for the saturate and gain keywords to
# make sense.
if isinstance(value, CCDData):
self.uncertainty = np.abs(self.data * value.data) * \
np.sqrt((self.uncertainty / self.data) ** 2 + (value.uncertainty / value.data) ** 2)
self.data *= value.data
self.mask |= value.mask
elif isinstance(value, np.ndarray):
self.uncertainty = np.abs(self.uncertainty * value)
self.data *= value
else:
self.data *= value
self.uncertainty *= value

Choose a reason for hiding this comment

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

Is it intentional that there is no protection for the uncertainties for negative values if value is a scalar, unlike for the array case? (Cf. line 145)

self.meta['SATURATE'] *= value
self.meta['GAIN'] /= value
self.meta['MAXLIN'] *= value
return self

def __itruediv__(self, value):
# Note: For array inputs, we need the arrays to be normalized around 1 for the saturate and gain keywords to
# make sense.
if isinstance(value, CCDData):
self.uncertainty = np.abs(self.data / value.data) * \
np.sqrt((self.uncertainty / self.data) ** 2 + (value.uncertainty / value.data) ** 2)
self.data /= value.data
self.mask |= value.mask
elif isinstance(value, np.ndarray):
self.uncertainty = np.abs(self.uncertainty / value)
self.data /= value
else:
self.__imul__(1.0 / value)
return self
Expand Down