9
9
from coolest .template .json import JSONSerializer
10
10
11
11
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 ):
13
13
"""
14
14
Rescale an image such that it has units of electrons per second (e/s),
15
15
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):
21
21
where `mag_zero_point` corresponds to the magnitude of 1 e/s.
22
22
:param image: input image, as a 2D array.
23
23
: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.
25
26
"""
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." )
26
29
flux_tot = np .sum (image )
27
30
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
29
36
flux_unit_mag = 10 ** ( - delta_mag / 2.5 )
30
37
image_rescaled = image_unit_flux * flux_unit_mag
31
38
return image_rescaled
0 commit comments