Skip to content

Commit 25fd657

Browse files
committed
Made a new version of _get_lc_prod which should do fuzzy matching of radii properly. Might close issue #1372
1 parent 9fd2adc commit 25fd657

File tree

1 file changed

+2
-94
lines changed

1 file changed

+2
-94
lines changed

xga/sources/base.py

Lines changed: 2 additions & 94 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) 18/07/2025, 10:21. Copyright (c) The Contributors
2+
# Last modified by David J Turner (turne540@msu.edu) 18/07/2025, 10:25. Copyright (c) The Contributors
33

44
import gc
55
import os
@@ -2317,7 +2317,7 @@ def _get_prof_prod(self, search_key: str, obs_id: str = None, inst: str = None,
23172317

23182318
return matched_prods
23192319

2320-
def _new_get_lc_prod(self, outer_radius: Union[str, Quantity] = None, obs_id: str = None, inst: str = None,
2320+
def _get_lc_prod(self, outer_radius: Union[str, Quantity] = None, obs_id: str = None, inst: str = None,
23212321
inner_radius: Union[str, Quantity] = None, lo_en: Quantity = None, hi_en: Quantity = None,
23222322
time_bin_size: Quantity = None, telescope: str = None) \
23232323
-> Union[LightCurve, List[LightCurve], AggregateLightCurve, List[AggregateLightCurve]]:
@@ -2409,98 +2409,6 @@ def _new_get_lc_prod(self, outer_radius: Union[str, Quantity] = None, obs_id: st
24092409

24102410
return matched_prods
24112411

2412-
def _get_lc_prod(self, outer_radius: Union[str, Quantity] = None, obs_id: str = None, inst: str = None,
2413-
inner_radius: Union[str, Quantity] = None, lo_en: Quantity = None, hi_en: Quantity = None,
2414-
time_bin_size: Quantity = None, telescope: str = None) \
2415-
-> Union[LightCurve, List[LightCurve], AggregateLightCurve, List[AggregateLightCurve]]:
2416-
"""
2417-
A protected method to retrieve XGA LightCurve objects, the user should never interact with this directly.
2418-
2419-
:param str/Quantity outer_radius: The name or value of the outer radius that was used for the generation of
2420-
the lightcurve (for instance 'point' would be acceptable for a PointSource, or Quantity(100, 'kpc')).
2421-
Default is None, meaning all lightcurves will be retrieved.
2422-
:param str obs_id: Optionally, a specific obs_id to search for can be supplied. The default is None,
2423-
which means all lightcurves matching the other criteria will be returned.
2424-
:param str inst: Optionally, a specific instrument to search for can be supplied. The default is None,
2425-
which means all lightcurves matching the other criteria will be returned.
2426-
:param str/Quantity inner_radius: The name or value of the inner radius that was used for the generation of
2427-
the lightcurve (for instance 'point' would be acceptable for a PointSource, or Quantity(0, 'kpc')).
2428-
Default is None, meaning all lightcurves will be retrieved.
2429-
:param Quantity lo_en: The lower energy limit of the lightcurves you wish to retrieve, the default
2430-
is None (which will retrieve all lightcurves regardless of energy limit).
2431-
:param Quantity hi_en: The upper energy limit of the lightcurves you wish to retrieve, the default
2432-
is None (which will retrieve all lightcurves regardless of energy limit).
2433-
:param Quantity time_bin_size: The time bin size used to generate the desired lightcurve. The default value
2434-
is None, in which case all lightcurves matching other criteria will be retrieved.
2435-
:param str telescope: Optionally, a specific telescope to search for can be supplied. The default is None,
2436-
which means all profiles matching the other criteria will be returned.
2437-
:return: An XGA LightCurve object (if there is an exact match), or a list of XGA LightCurve objects (if there
2438-
were multiple matching products), or a single/list of AggregateLightCurve objects.
2439-
:rtype: Union[LightCurve, List[LightCurve], AggregateLightCurve, List[AggregateLightCurve]]
2440-
"""
2441-
# Set up search strings (for the product storage keys) for the inner and outer radii here. The default None
2442-
# value just creates a key that looks for the 'ri' or 'ro' precursor to the value in the key, i.e. it doesn't
2443-
# do anything - we also make sure that any radii passed by the user are converted properly
2444-
if inner_radius is not None and isinstance(inner_radius, Quantity):
2445-
inn_rad_search = '_ri{}_'.format(self.convert_radius(inner_radius, 'deg').value)
2446-
elif inner_radius is not None and isinstance(inner_radius, str):
2447-
inn_rad_search = '_ri{}_'.format(self.get_radius(inner_radius, 'deg').value)
2448-
elif inner_radius is None:
2449-
inn_rad_search = "_ri"
2450-
else:
2451-
raise TypeError("You may only pass a quantity or a string as inner_radius")
2452-
2453-
if outer_radius is not None and isinstance(outer_radius, Quantity):
2454-
out_rad_search = '_ro{}_'.format(self.convert_radius(outer_radius, 'deg').value)
2455-
elif outer_radius is not None and isinstance(outer_radius, str):
2456-
out_rad_search = '_ro{}_'.format(self.get_radius(outer_radius, 'deg').value)
2457-
elif outer_radius is None:
2458-
out_rad_search = "_ro"
2459-
else:
2460-
raise TypeError("You may only pass a quantity or a string as outer_radius")
2461-
2462-
# Check to make sure that the time bin size is a legal value, and set up a search string for the time bin
2463-
# size in order to narrow down the lightcurves to just the ones that the user wants
2464-
if time_bin_size is not None and not time_bin_size.unit.is_equivalent('s'):
2465-
raise UnitConversionError("The 'time_bin_size' argument must be convertible to seconds.")
2466-
elif time_bin_size is None:
2467-
time_bin_search = '_timebin'
2468-
else:
2469-
time_bin_search = '_timebin{}'.format(time_bin_size.to('s').value)
2470-
2471-
# Setting up the energy band search string - if one bound is specified then the other has to be as well, I
2472-
# didn't think it made sense otherwise
2473-
if any([lo_en is not None, hi_en is not None]) and not all([lo_en is not None, hi_en is not None]):
2474-
raise ValueError("The 'lo_en' and 'hi_en' values must either both be None, or both be an energy value.")
2475-
if (lo_en is not None and not lo_en.unit.is_equivalent('keV')) or \
2476-
(hi_en is not None and not hi_en.unit.is_equivalent('keV')):
2477-
raise UnitConversionError("The 'lo_en' and 'hi_en' arguments must be convertible to keV.")
2478-
# If either is None then we know both are because we checked earlier
2479-
elif lo_en is None:
2480-
en_search = 'bound_'
2481-
elif lo_en is not None:
2482-
en_search = 'bound_{l}-{u}'.format(l=lo_en.to('keV').value, u=hi_en.to('keV').value)
2483-
2484-
if obs_id == 'combined':
2485-
search_key = 'combined_lightcurve'
2486-
else:
2487-
search_key = 'lightcurve'
2488-
# Grabbing every single lightcurve that matches ObsID, instrument, and telescope passed by the
2489-
# user (None by default) - we'll then sweep through whatever list is returned and narrow them down
2490-
all_lcs = self.get_products(search_key, obs_id, inst, telescope=telescope)
2491-
# It was getting to the point where a list comprehension was less readable than a for loop, particularly
2492-
# with the pattern logic, so I changed it to this
2493-
matched_prods = []
2494-
for lc in all_lcs:
2495-
if out_rad_search in lc.storage_key and inn_rad_search in lc.storage_key and \
2496-
time_bin_search in lc.storage_key and en_search in lc.storage_key:
2497-
matched_prods.append(lc)
2498-
2499-
if len(matched_prods) == 0:
2500-
raise NoProductAvailableError("Cannot find any lightcurves matching your input.")
2501-
2502-
return matched_prods
2503-
25042412
def _all_peaks(self, method: str, source_type: str):
25052413
"""
25062414
An internal method that finds the X-ray peaks for all the available telescopes, observations, and

0 commit comments

Comments
 (0)