@@ -32,7 +32,8 @@ def calculate_spectral_index_for_multiple_ranges(intensity_data: IntensityMapDat
3232 ena_spectral_index = np .concat ([m .ena_spectral_index for m in spectral_maps ], axis = 1 ),
3333 ena_spectral_index_stat_uncert = np .concat ([m .ena_spectral_index_stat_uncert for m in spectral_maps ], axis = 1 ),
3434 ena_spectral_index_scalar_coefficient = np .concat ([m .ena_spectral_index_scalar_coefficient for m in spectral_maps ], axis = 1 ),
35- ena_spectral_index_scalar_coefficient_stat_uncert = np .concat ([m .ena_spectral_index_scalar_coefficient_stat_uncert for m in spectral_maps ], axis = 1 )
35+ ena_spectral_index_scalar_coefficient_stat_uncert = np .concat ([m .ena_spectral_index_scalar_coefficient_stat_uncert for m in spectral_maps ], axis = 1 ),
36+ ena_spectral_index_chisq = np .concat ([m .ena_spectral_index_chisq for m in spectral_maps ], axis = 1 ),
3637 )
3738
3839
@@ -82,7 +83,7 @@ def fit_spectral_index_map(intensity_data: IntensityMapData) -> SpectralIndexMap
8283 mean_energy = np .sqrt (min_energy * max_energy )
8384 new_energy_label = f"{ min_energy } - { max_energy } "
8485
85- output_scalar_coefficients , output_scalar_errors , output_gammas , output_gamma_errors = fit_arrays_to_power_law (fluxes , uncertainty , energy )
86+ output_scalar_coefficients , output_scalar_errors , output_gammas , output_gamma_errors , chisq = fit_arrays_to_power_law (fluxes , uncertainty , energy )
8687 mean_obs_date = calculate_datetime_weighted_average (intensity_data .obs_date ,
8788 weights = intensity_data .exposure_factor ,
8889 axis = 1 , keepdims = True )
@@ -94,7 +95,7 @@ def fit_spectral_index_map(intensity_data: IntensityMapData) -> SpectralIndexMap
9495 output_gammas [positive_gammas ] = np .nan
9596 output_scalar_coefficients [positive_gammas ] = np .nan
9697 output_gamma_errors [positive_gammas ] = np .nan
97-
98+ chisq [ positive_gammas ] = np . nan
9899
99100 return SpectralIndexMapData (
100101 epoch = intensity_data .epoch ,
@@ -113,11 +114,12 @@ def fit_spectral_index_map(intensity_data: IntensityMapData) -> SpectralIndexMap
113114 ena_spectral_index_stat_uncert = output_gamma_errors ,
114115 ena_spectral_index_scalar_coefficient = output_scalar_coefficients ,
115116 ena_spectral_index_scalar_coefficient_stat_uncert = output_scalar_errors ,
117+ ena_spectral_index_chisq = chisq ,
116118 )
117119
118120
119121def fit_arrays_to_power_law (fluxes : np .ndarray , uncertainties : np .ndarray , energy : np .ndarray ) -> tuple [
120- np .ndarray , np .ndarray , np .ndarray , np .ndarray ]:
122+ np .ndarray , np .ndarray , np .ndarray , np .ndarray , np . ndarray ]:
121123 par_info = [
122124 {'limits' : [0.0 , 1000.0 ]},
123125 {'limits' : [0.0 , 1000.0 ]},
@@ -128,6 +130,7 @@ def fit_arrays_to_power_law(fluxes: np.ndarray, uncertainties: np.ndarray, energ
128130 output_gamma_errors = np .full_like (output_gammas , np .nan )
129131 output_scalar_coefficients = np .full_like (output_gammas , np .nan )
130132 output_scalar_coefficients_errors = np .full_like (output_gammas , np .nan )
133+ output_chisqs = np .full_like (output_gammas , np .nan )
131134
132135 for epoch in range (fluxes .shape [0 ]):
133136 intensity = fluxes [epoch ].reshape ((fluxes [epoch ].shape [0 ], - 1 ))
@@ -137,6 +140,7 @@ def fit_arrays_to_power_law(fluxes: np.ndarray, uncertainties: np.ndarray, energ
137140 gamma_errors = np .full_like (gammas , np .nan )
138141 scalar_coefficients = np .full (intensity .shape [- 1 ], np .nan , dtype = float )
139142 scalar_coefficient_errors = np .full (intensity .shape [- 1 ], np .nan , dtype = float )
143+ chisqs = np .full (intensity .shape [- 1 ], np .nan , dtype = float )
140144
141145 for i in range (intensity .shape [- 1 ]):
142146 flux = intensity [:, i ]
@@ -163,11 +167,13 @@ def fit_arrays_to_power_law(fluxes: np.ndarray, uncertainties: np.ndarray, energ
163167 scalar_coefficients [i ] = a
164168 gamma_errors [i ] = gamma_error
165169 scalar_coefficient_errors [i ] = a_error
170+ chisqs [i ] = fit .fnorm
166171 output_gammas [epoch , 0 ] = gammas .reshape (fluxes .shape [2 :])
167172 output_gamma_errors [epoch , 0 ] = gamma_errors .reshape (fluxes .shape [2 :])
168173 output_scalar_coefficients [epoch , 0 ] = scalar_coefficients .reshape (fluxes .shape [2 :])
169174 output_scalar_coefficients_errors [epoch , 0 ] = scalar_coefficient_errors .reshape (fluxes .shape [2 :])
170- return output_scalar_coefficients , output_scalar_coefficients_errors , output_gammas , output_gamma_errors
175+ output_chisqs [epoch , 0 ] = chisqs .reshape (fluxes .shape [2 :])
176+ return output_scalar_coefficients , output_scalar_coefficients_errors , output_gammas , output_gamma_errors , output_chisqs
171177
172178
173179def power_law (params , ** kwargs ):
0 commit comments