Skip to content

Commit e5888cf

Browse files
author
David Turner
committed
Hopefully removed every instance of np.NaN in XGA, and replaced it with np.nan - should sort out issue #1349
1 parent d8348f5 commit e5888cf

8 files changed

Lines changed: 43 additions & 43 deletions

File tree

xga/models/density.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This code is a part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (turne540@msu.edu) 08/06/2023, 22:40. Copyright (c) The Contributors
2+
# Last modified by David J Turner (turne540@msu.edu) 04/06/2025, 13:31. Copyright (c) The Contributors
33

44
from typing import Union, List
55

@@ -356,7 +356,7 @@ def model(x: Quantity, beta: Quantity, r_core: Quantity, alpha: Quantity, r_s: Q
356356
second_term = 1 / ((1 + rs_rat**3)**(epsilon / 3))
357357
result = norm * np.sqrt(first_term * second_term)
358358
except ZeroDivisionError:
359-
result = np.NaN
359+
result = np.nan
360360

361361
return result
362362

@@ -517,7 +517,7 @@ def model(x: Quantity, beta_one: Quantity, r_core_one: Quantity, alpha: Quantity
517517
second_term = 1 / ((1 + rs_rat**gamma)**(epsilon / gamma))
518518
additive_term = 1 / ((1 + rc2_rat**2)**(3 * beta_two))
519519
except ZeroDivisionError:
520-
return np.NaN
520+
return np.nan
521521

522522
return np.sqrt((np.power(norm_one, 2) * first_term * second_term) + (np.power(norm_two, 2) * additive_term))
523523

xga/models/fitting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This code is a part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (turne540@msu.edu) 20/02/2023, 14:04. Copyright (c) The Contributors
2+
# Last modified by David J Turner (turne540@msu.edu) 04/06/2025, 13:31. Copyright (c) The Contributors
33

44
from typing import List
55

@@ -26,7 +26,7 @@ def log_likelihood(theta: np.ndarray, r: np.ndarray, y: np.ndarray, y_err: np.nd
2626
try:
2727
lik = -np.sum(np.log(y_err*np.sqrt(2*np.pi)) + (((y - m_func(r, *theta))**2) / (2*y_err**2)))
2828
except ZeroDivisionError:
29-
lik = np.NaN
29+
lik = np.nan
3030
return lik
3131

3232

xga/models/temperature.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This code is a part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (turne540@msu.edu) 29/07/2024, 16:04. Copyright (c) The Contributors
2+
# Last modified by David J Turner (turne540@msu.edu) 04/06/2025, 13:31. Copyright (c) The Contributors
33

44
from typing import Union, List
55

@@ -117,7 +117,7 @@ def model(x: Quantity, r_cool: Quantity, a_cool: Quantity, t_min: Quantity, t_ze
117117
out_expr = 1 / ((1 + (x / r_tran)**2)**(c_power / 2))
118118
result = t_zero * cool_expr * out_expr
119119
except ZeroDivisionError:
120-
result = np.NaN
120+
result = np.nan
121121

122122
return result
123123

@@ -269,7 +269,7 @@ def model(x: Quantity, r_cool: Quantity, a_cool: Quantity, t_min: Quantity, t_ze
269269
result = t_zero * t_cool * t_outer
270270

271271
except ZeroDivisionError:
272-
result = np.NaN
272+
result = np.nan
273273

274274
return result
275275

xga/samples/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This code is a part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (turne540@msu.edu) 26/03/2025, 19:57. Copyright (c) The Contributors
2+
# Last modified by David J Turner (turne540@msu.edu) 04/06/2025, 13:31. Copyright (c) The Contributors
33

44
from typing import Union, List, Dict
55
from warnings import warn
@@ -317,7 +317,7 @@ def Lx(self, outer_radius: Union[str, Quantity], model: str,
317317
# that entry with a NaN - the names will be included in a warning at the end
318318
# warn(str(err))
319319
warns.append(src.name)
320-
lums.append(np.array([np.NaN, np.NaN, np.NaN]))
320+
lums.append(np.array([np.nan, np.nan, np.nan]))
321321

322322
# Turn the list of 3 element arrays into an Nx3 array which is then turned into an astropy Quantity
323323
lums = Quantity(np.array(lums), 'erg / s')

xga/samples/extended.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This code is a part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (turne540@msu.edu) 26/03/2025, 19:57. Copyright (c) The Contributors
2+
# Last modified by David J Turner (turne540@msu.edu) 04/06/2025, 13:31. Copyright (c) The Contributors
33

44
from typing import List
55

@@ -418,7 +418,7 @@ def _get_overdens_rad_checks(self, rad_name: str) -> Quantity:
418418
rad = gcs.get_radius(rad_name, 'kpc')
419419
# Result could be None, if the radius wasn't set for that clusters, have to account for that
420420
if rad is None:
421-
rads.append(np.NaN)
421+
rads.append(np.nan)
422422
else:
423423
rads.append(rad)
424424

@@ -651,24 +651,24 @@ def Tx(self, outer_radius: Union[str, Quantity] = 'r500', model: str = 'constant
651651
# If the measured temperature is 64keV I know that's a failure condition of the XSPEC fit,
652652
# so its set to NaN
653653
if quality_checks and gcs_temp[0] > 25:
654-
gcs_temp = np.array([np.NaN, np.NaN, np.NaN])
654+
gcs_temp = np.array([np.nan, np.nan, np.nan])
655655
warn("A temperature of {m}keV was measured for {s}, anything over 30keV considered a failed "
656656
"fit by XGA".format(s=gcs.name, m=gcs_temp), stacklevel=2)
657657
elif quality_checks and gcs_temp.min() < 0:
658-
gcs_temp = np.array([np.NaN, np.NaN, np.NaN])
658+
gcs_temp = np.array([np.nan, np.nan, np.nan])
659659
warn("A negative value was detected in the temperature array for {s}, this is considered a failed "
660660
"measurement".format(s=gcs.name), stacklevel=2)
661661
elif quality_checks and ((gcs_temp[0] - gcs_temp[1]) <= 0):
662-
gcs_temp = np.array([np.NaN, np.NaN, np.NaN])
662+
gcs_temp = np.array([np.nan, np.nan, np.nan])
663663
warn("The temperature value - the lower error goes below zero for {s}, this makes the temperature"
664664
" hard to use for scaling relations as values are often logged.".format(s=gcs.name),
665665
stacklevel=2)
666666
elif quality_checks and ((gcs_temp[1] / gcs_temp[2]) > 3 or (gcs_temp[1] / gcs_temp[2]) < 0.33):
667-
gcs_temp = np.array([np.NaN, np.NaN, np.NaN])
667+
gcs_temp = np.array([np.nan, np.nan, np.nan])
668668
warn("One of the temperature uncertainty values for {s} is more than three times larger than "
669669
"the other, this means the fit quality is suspect.".format(s=gcs.name), stacklevel=2)
670670
elif quality_checks and ((gcs_temp[0] - gcs_temp[1:].mean()) < 0):
671-
gcs_temp = np.array([np.NaN, np.NaN, np.NaN])
671+
gcs_temp = np.array([np.nan, np.nan, np.nan])
672672
warn("The temperature value - the average error goes below zero for {s}, this makes the "
673673
"temperature hard to use for scaling relations as values are often "
674674
"logged".format(s=gcs.name), stacklevel=2)
@@ -678,7 +678,7 @@ def Tx(self, outer_radius: Union[str, Quantity] = 'r500', model: str = 'constant
678678
# If any of the possible errors are thrown, we print the error as a warning and replace
679679
# that entry with a NaN
680680
warn(str(err), stacklevel=2)
681-
temps.append(np.array([np.NaN, np.NaN, np.NaN]))
681+
temps.append(np.array([np.nan, np.nan, np.nan]))
682682

683683
# Turn the list of 3 element arrays into an Nx3 array which is then turned into an astropy Quantity
684684
temps = Quantity(np.array(temps), 'keV')
@@ -774,29 +774,29 @@ def gas_mass(self, rad_name: str, dens_model: str, method: str, prof_outer_rad:
774774
try:
775775
cur_gmass = dens_profs.gas_mass(dens_model, gas_mass_rad)[0]
776776
if quality_checks and (cur_gmass[1] > cur_gmass[0] or cur_gmass[2] > cur_gmass[0]):
777-
gms.append([np.NaN, np.NaN, np.NaN])
777+
gms.append([np.nan, np.nan, np.nan])
778778
elif quality_checks and cur_gmass[0] < Quantity(1e+9, 'Msun'):
779-
gms.append([np.NaN, np.NaN, np.NaN])
779+
gms.append([np.nan, np.nan, np.nan])
780780
warn("{s}'s gas mass is less than 1e+12 solar masses")
781781
elif quality_checks and cur_gmass[0] > Quantity(1e+16, 'Msun'):
782-
gms.append([np.NaN, np.NaN, np.NaN])
782+
gms.append([np.nan, np.nan, np.nan])
783783
warn("{s}'s gas mass is greater than 1e+16 solar masses")
784784
else:
785785
gms.append(cur_gmass.value)
786786
except ModelNotAssociatedError:
787-
gms.append([np.NaN, np.NaN, np.NaN])
787+
gms.append([np.nan, np.nan, np.nan])
788788
except ValueError:
789-
gms.append([np.NaN, np.NaN, np.NaN])
789+
gms.append([np.nan, np.nan, np.nan])
790790
warn("{s}'s gas mass is negative")
791791

792792
else:
793793
warn("Somehow there multiple matches for {s}'s density profile, this is the developer's "
794794
"fault.".format(s=gcs.name))
795-
gms.append([np.NaN, np.NaN, np.NaN])
795+
gms.append([np.nan, np.nan, np.nan])
796796

797797
except NoProductAvailableError:
798798
# If no dens_prof has been run or something goes wrong then NaNs are added
799-
gms.append([np.NaN, np.NaN, np.NaN])
799+
gms.append([np.nan, np.nan, np.nan])
800800
warn("{s} doesn't have a density profile associated, please look at "
801801
"sourcetools.density.".format(s=gcs.name))
802802

@@ -850,23 +850,23 @@ def hydrostatic_mass(self, rad_name: str, temp_model_name: str = None, dens_mode
850850
try:
851851
cur_mass = mass_profs.mass(actual_rad)[0]
852852
if quality_checks and (cur_mass[1] > cur_mass[0] or cur_mass[2] > cur_mass[0]):
853-
ms.append([np.NaN, np.NaN, np.NaN])
853+
ms.append([np.nan, np.nan, np.nan])
854854
warn("{s}'s mass uncertainties are larger than the mass value.")
855855
elif quality_checks and cur_mass[0] < Quantity(1e+12, 'Msun'):
856-
ms.append([np.NaN, np.NaN, np.NaN])
856+
ms.append([np.nan, np.nan, np.nan])
857857
warn("{s}'s mass is less than 1e+12 solar masses")
858858
elif quality_checks and cur_mass[0] > Quantity(1e+16, 'Msun'):
859-
ms.append([np.NaN, np.NaN, np.NaN])
859+
ms.append([np.nan, np.nan, np.nan])
860860
warn("{s}'s mass is greater than 1e+16 solar masses")
861861
else:
862862
ms.append(cur_mass.value)
863863
except ValueError:
864864
warn("{s}'s mass is negative")
865-
ms.append([np.NaN, np.NaN, np.NaN])
865+
ms.append([np.nan, np.nan, np.nan])
866866

867867
except NoProductAvailableError:
868868
# If no dens_prof has been run or something goes wrong then NaNs are added
869-
ms.append([np.NaN, np.NaN, np.NaN])
869+
ms.append([np.nan, np.nan, np.nan])
870870
warn("{s} doesn't have a matching hydrostatic mass profile associated".format(s=gcs.name))
871871

872872
ms = np.array(ms)
@@ -927,11 +927,11 @@ def calc_overdensity_radii(self, delta: int, temp_model_name: str = None, dens_m
927927
"didn't bracket the requested overdensity radius. See the docs of overdensity_radius "
928928
"method of HydrostaticMass for more info.".format(s=gcs.name))
929929

930-
rs.append(np.NaN)
930+
rs.append(np.nan)
931931

932932
except NoProductAvailableError:
933933
# If no dens_prof has been run or something goes wrong then NaNs are added
934-
rs.append(np.NaN)
934+
rs.append(np.nan)
935935
warn("{s} doesn't have a matching hydrostatic mass profile associated".format(s=gcs.name))
936936

937937
# Turn the radii list into a quantity and return it

xga/samples/general.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This code is a part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (turne540@msu.edu) 13/04/2023, 15:21. Copyright (c) The Contributors
2+
# Last modified by David J Turner (turne540@msu.edu) 04/06/2025, 13:31. Copyright (c) The Contributors
33

44
from warnings import warn
55

@@ -107,7 +107,7 @@ def __init__(self, ra: np.ndarray, dec: np.ndarray, redshift: np.ndarray = None,
107107
# whether this has been set yet when all radii should be forced to be the same unit
108108
self._cr_unit = cr.unit
109109
else:
110-
self._custom_radii.append(np.NaN)
110+
self._custom_radii.append(np.nan)
111111
self._cr_unit = Unit('')
112112
final_names.append(n)
113113
except PeakConvergenceFailedError:

xga/sources/extended.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This code is a part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (turne540@msu.edu) 26/03/2025, 20:09. Copyright (c) The Contributors
2+
# Last modified by David J Turner (turne540@msu.edu) 04/06/2025, 13:31. Copyright (c) The Contributors
33

44
from typing import Union, List, Tuple, Dict
55
from warnings import warn, simplefilter
@@ -445,11 +445,11 @@ def weak_lensing_mass(self) -> Quantity:
445445
wl_list = [self._wl_mass.value]
446446
wl_unit = self._wl_mass.unit
447447
else:
448-
wl_list = [np.NaN]
448+
wl_list = [np.nan]
449449
wl_unit = ''
450450

451451
if self._wl_mass_err is None:
452-
wl_list.append(np.NaN)
452+
wl_list.append(np.nan)
453453
elif isinstance(self._wl_mass_err, Quantity) and not self._wl_mass_err.isscalar:
454454
wl_list += list(self._wl_mass_err.value)
455455
elif isinstance(self._wl_mass_err, Quantity) and self._wl_mass_err.isscalar:
@@ -469,10 +469,10 @@ def richness(self) -> Quantity:
469469
if self._richness is not None:
470470
r_list = [self._richness]
471471
else:
472-
r_list = [np.NaN]
472+
r_list = [np.nan]
473473

474474
if self._richness_err is None:
475-
r_list.append(np.NaN)
475+
r_list.append(np.nan)
476476
elif isinstance(self._richness_err, (float, int)):
477477
r_list.append(self._richness_err)
478478
elif isinstance(self._richness_err, list):

xga/sourcetools/stack.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This code is a part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (turne540@msu.edu) 26/07/2024, 14:21. Copyright (c) The Contributors
2+
# Last modified by David J Turner (turne540@msu.edu) 04/06/2025, 13:31. Copyright (c) The Contributors
33

44
from multiprocessing.dummy import Pool
55
from typing import List, Tuple, Union
@@ -334,7 +334,7 @@ def construct_profile(src_obj: GalaxyCluster, src_id: int, lower: Quantity, uppe
334334
interp_brightness = np.interp(radii, scaled_radii, (sb_prof.values - sb_prof.background).value)
335335
except ValueError as ve:
336336
# This will mean that the profile is thrown away in a later step
337-
interp_brightness = np.full(radii.shape, np.NaN)
337+
interp_brightness = np.full(radii.shape, np.nan)
338338
# But will also raise a warning so the user knows
339339
warn(str(ve).replace("you're looking at", "{s} is".format(s=src_obj.name)).replace(".", "")
340340
+ " - profile set to NaNs.", stacklevel=2)
@@ -596,12 +596,12 @@ def construct_profile(src_obj: GalaxyCluster, src_id: int, lower: Quantity, uppe
596596
model_brightness = fitted_model(model_radii)
597597

598598
except XGAFitError:
599-
model_brightness = np.full(radii.shape, np.NaN)
599+
model_brightness = np.full(radii.shape, np.nan)
600600
warn('Model fit for {s} failed - profile set to NaNs'.format(s=src_obj.name), stacklevel=2)
601601

602602
except ValueError as ve:
603603
# This will mean that the profile is thrown away in a later step
604-
model_brightness = np.full(radii.shape, np.NaN)
604+
model_brightness = np.full(radii.shape, np.nan)
605605
# But will also raise a warning so the user knows
606606
warn(str(ve).replace("you're looking at", "{s} is".format(s=src_obj.name)).replace(".", "")
607607
+ " - profile set to NaNs.", stacklevel=2)

0 commit comments

Comments
 (0)