55# TODO : The way these work dpeending on if the input array (e.g. the weight map) are an auto array or not is a bit
66# TODO : clunky. For example, we can currently overwrite pixel_scales. We need to decade how we approach this.
77
8- def array_using_correct_dimensions (array , pixel_scales = None , sub_size = 1 , origin = (0.0 , 0.0 )):
8+
9+ def array_using_correct_dimensions (
10+ array , pixel_scales = None , sub_size = 1 , origin = (0.0 , 0.0 )
11+ ):
912
1013 if isinstance (array , arrays .AbstractArray ):
1114 return array
1215
1316 if len (array .shape ) == 1 :
14- return arrays .Array .manual_1d (array = array , shape_2d = array .shape_2d , pixel_scales = pixel_scales , sub_size = sub_size , origin = origin )
17+ return arrays .Array .manual_1d (
18+ array = array ,
19+ shape_2d = array .shape_2d ,
20+ pixel_scales = pixel_scales ,
21+ sub_size = sub_size ,
22+ origin = origin ,
23+ )
1524 elif len (array .shape ) == 2 :
16- return arrays .Array .manual_2d (array = array , pixel_scales = pixel_scales , sub_size = sub_size , origin = origin )
25+ return arrays .Array .manual_2d (
26+ array = array , pixel_scales = pixel_scales , sub_size = sub_size , origin = origin
27+ )
1728
1829
19- def noise_map_from_weight_map (weight_map , pixel_scales = None , sub_size = 1 , origin = (0.0 , 0.0 )):
30+ def noise_map_from_weight_map (
31+ weight_map , pixel_scales = None , sub_size = 1 , origin = (0.0 , 0.0 )
32+ ):
2033 """Setup the noise-map from a weight map, which is a form of noise-map that comes via HST image-reduction and \
2134 the software package MultiDrizzle.
2235
@@ -37,9 +50,14 @@ def noise_map_from_weight_map(weight_map, pixel_scales=None, sub_size=1, origin=
3750 np .seterr (divide = "ignore" )
3851 noise_map = 1.0 / np .sqrt (weight_map )
3952 noise_map [noise_map > 1.0e8 ] = 1.0e8
40- return array_using_correct_dimensions (array = noise_map , pixel_scales = pixel_scales , sub_size = sub_size , origin = origin )
53+ return array_using_correct_dimensions (
54+ array = noise_map , pixel_scales = pixel_scales , sub_size = sub_size , origin = origin
55+ )
4156
42- def noise_map_from_inverse_noise_map (inverse_noise_map , pixel_scales = None , sub_size = 1 , origin = (0.0 , 0.0 )):
57+
58+ def noise_map_from_inverse_noise_map (
59+ inverse_noise_map , pixel_scales = None , sub_size = 1 , origin = (0.0 , 0.0 )
60+ ):
4361 """Setup the noise-map from an root-mean square standard deviation map, which is a form of noise-map that \
4462 comes via HST image-reduction and the software package MultiDrizzle.
4563
@@ -57,43 +75,58 @@ def noise_map_from_inverse_noise_map(inverse_noise_map, pixel_scales=None, sub_s
5775 inverse_noise_map : ndarray
5876 The inverse noise_map value of each pixel which is converted to a variance.
5977 """
60- return array_using_correct_dimensions (array = 1.0 / inverse_noise_map , pixel_scales = pixel_scales , sub_size = sub_size , origin = origin )
78+ return array_using_correct_dimensions (
79+ array = 1.0 / inverse_noise_map ,
80+ pixel_scales = pixel_scales ,
81+ sub_size = sub_size ,
82+ origin = origin ,
83+ )
84+
6185
6286def noise_map_from_image_and_background_noise_map (
6387 image ,
6488 background_noise_map ,
6589 exposure_time_map ,
6690 gain = None ,
6791 convert_from_electrons = False ,
68- convert_from_adus = False , pixel_scales = None , sub_size = 1 , origin = (0.0 , 0.0 )
92+ convert_from_adus = False ,
93+ pixel_scales = None ,
94+ sub_size = 1 ,
95+ origin = (0.0 , 0.0 ),
6996):
7097
7198 if not convert_from_electrons and not convert_from_adus :
72- noise_map = np .sqrt (
99+ noise_map = (
100+ np .sqrt (
73101 np .abs (
74102 ((background_noise_map ) * exposure_time_map ) ** 2.0
75103 + (image ) * exposure_time_map
76- )) / exposure_time_map
104+ )
105+ )
106+ / exposure_time_map
107+ )
77108
78109 elif convert_from_electrons :
79- noise_map = np .sqrt (
80- np .abs (background_noise_map ** 2.0 + image )
81- )
110+ noise_map = np .sqrt (np .abs (background_noise_map ** 2.0 + image ))
82111 elif convert_from_adus :
83- noise_map = np .sqrt (
84- np .abs (
85- (gain * background_noise_map ) ** 2.0 + gain * image
86- )
87- ) / gain
112+ noise_map = (
113+ np .sqrt (np .abs ((gain * background_noise_map ) ** 2.0 + gain * image )) / gain
114+ )
115+
116+ return array_using_correct_dimensions (
117+ array = noise_map , pixel_scales = pixel_scales , sub_size = sub_size , origin = origin
118+ )
88119
89- return array_using_correct_dimensions (array = noise_map , pixel_scales = pixel_scales , sub_size = sub_size , origin = origin )
90120
91121def poisson_noise_map_from_image_and_exposure_time_map (
92122 image ,
93123 exposure_time_map ,
94124 gain = None ,
95125 convert_from_electrons = False ,
96- convert_from_adus = False , pixel_scales = None , sub_size = 1 , origin = (0.0 , 0.0 )
126+ convert_from_adus = False ,
127+ pixel_scales = None ,
128+ sub_size = 1 ,
129+ origin = (0.0 , 0.0 ),
97130):
98131 if not convert_from_electrons and not convert_from_adus :
99132 noise_map = np .sqrt (np .abs (image ) * exposure_time_map ) / exposure_time_map
@@ -103,4 +136,6 @@ def poisson_noise_map_from_image_and_exposure_time_map(
103136 elif convert_from_adus :
104137 noise_map = np .sqrt (gain * np .abs (image )) / gain
105138
106- return array_using_correct_dimensions (array = noise_map , pixel_scales = pixel_scales , sub_size = sub_size , origin = origin )
139+ return array_using_correct_dimensions (
140+ array = noise_map , pixel_scales = pixel_scales , sub_size = sub_size , origin = origin
141+ )
0 commit comments