Skip to content

Commit e39729b

Browse files
committed
A COOLEST object can be provided to rescale an image
1 parent 1a27ba2 commit e39729b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

coolest/api/util.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from coolest.template.json import JSONSerializer
1010

1111

12-
def convert_image_to_data_units(image, mag_tot, mag_zero_point):
12+
def convert_image_to_data_units(image, mag_tot, mag_zero_point=None, coolest_object=None):
1313
"""
1414
Rescale an image such that it has units of electrons per second (e/s),
1515
given a total magnitude and a magnitude zero-point.
@@ -21,11 +21,18 @@ def convert_image_to_data_units(image, mag_tot, mag_zero_point):
2121
where `mag_zero_point` corresponds to the magnitude of 1 e/s.
2222
:param image: input image, as a 2D array.
2323
:param mag_tot: target total magnitude, integrated over the whole image
24-
:param mag_zero_point: magnitude zero point of the observation (that corresponds to 1 e/s)
24+
:param mag_zero_point: magnitude zero point of the observation (that corresponds to 1 e/s). If coolest_object is not None, mag_zero_point is ignored.
25+
:param coolest_object: if given, will be used to retrieve the zero-point magnitude of the observation.
2526
"""
27+
if coolest_object is None and mag_zero_point is None:
28+
raise ValueError("Either a COOLEST object or a zero-point magnitude should be provided.")
2629
flux_tot = np.sum(image)
2730
image_unit_flux = image / flux_tot
28-
delta_mag = mag_tot - mag_zero_point
31+
if coolest_object is not None:
32+
mag_zp = coolest.observation.mag_zero_point
33+
else:
34+
mag_zp = mag_zero_point
35+
delta_mag = mag_tot - mag_zp
2936
flux_unit_mag = 10 ** ( - delta_mag / 2.5 )
3037
image_rescaled = image_unit_flux * flux_unit_mag
3138
return image_rescaled

0 commit comments

Comments
 (0)