Skip to content

Commit

Permalink
Fix Spitzer logic (#362)
Browse files Browse the repository at this point in the history
* Fix #358

* Apply @jkrick review comments

* Bugfix: Return a Table instead of a Row
  • Loading branch information
troyraen authored Dec 11, 2024
1 parent 83ab5ea commit 0e0cb9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions spectroscopy/code_src/mast_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
def JWST_get_spec(sample_table, search_radius_arcsec, datadir, verbose,
delete_downloaded_data=True):
"""
Retrieve HST spectra for a list of sources and groups/stacks them.
Retrieve JWST spectra for a list of sources and groups/stacks them.
This main function runs two sub-functions:
- `JWST_get_spec_helper()` which searches, downloads, retrieves the spectra.
- `JWST_group_spectra()` which groups and stacks the spectra.
Expand All @@ -31,7 +31,7 @@ def JWST_get_spec(sample_table, search_radius_arcsec, datadir, verbose,
Search radius in arcseconds.
datadir : str
Data directory where to store the data. Each function will create a
separate data directory (for example "[datadir]/HST/" for HST data).
separate data directory (for example "[datadir]/JWST/" for JWST data).
verbose : bool
Verbosity level. Set to True for extra talking.
delete_downloaded_data : bool, optional
Expand Down Expand Up @@ -60,7 +60,7 @@ def JWST_get_spec(sample_table, search_radius_arcsec, datadir, verbose,
def JWST_get_spec_helper(sample_table, search_radius_arcsec, datadir, verbose,
delete_downloaded_data=True):
"""
Retrieve HST spectra for a list of sources.
Retrieve JWST spectra for a list of sources.
Parameters
----------
Expand All @@ -70,7 +70,7 @@ def JWST_get_spec_helper(sample_table, search_radius_arcsec, datadir, verbose,
Search radius in arcseconds.
datadir : str
Data directory where to store the data. Each function will create a
separate data directory (for example "[datadir]/HST/" for HST data).
separate data directory (for example "[datadir]/JWST/" for JWST data).
verbose : bool
Verbosity level. Set to True for extra talking.
delete_downloaded_data : bool, optional
Expand Down
10 changes: 5 additions & 5 deletions spectroscopy/code_src/spitzer_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

def SpitzerIRS_get_spec(sample_table, search_radius_arcsec, COMBINESPEC):
"""
Retrieve HST spectra for a list of sources.
Retrieve Spitzer spectra for a list of sources.
Parameters
----------
Expand Down Expand Up @@ -47,14 +47,14 @@ def SpitzerIRS_get_spec(sample_table, search_radius_arcsec, COMBINESPEC):

# If multiple entries are found, pick the closest.
# Or should we take the average instead??
if len(tab) > 0:
if len(tab) > 1:
print("More than 1 entry found", end="")
if not COMBINESPEC:
print(" - pick the closest")
sep = [search_coords.separation(SkyCoord(tt["ra"], tt["dec"], unit=u.deg, frame='icrs')).to(
u.arcsecond).value for tt in tab]
id_min = np.where(sep == np.nanmin(sep))[0]
tab_final = tab[id_min]
id_min = np.nanargmin(sep)
tab_final = tab[[id_min]] # double brackets to return a Table instead of a Row
else:
print(" - Combine spectra")
tab_final = tab.copy()
Expand All @@ -63,7 +63,7 @@ def SpitzerIRS_get_spec(sample_table, search_radius_arcsec, COMBINESPEC):

# Now extract spectra and put all in one array
specs = []
for tt in tab:
for tt in tab_final:
url = "https://irsa.ipac.caltech.edu{}".format(tt["xtable"].split("\"")[1])
spec = Table.read(url, format="ipac") # flux_density in Jy
specs.append(spec)
Expand Down

0 comments on commit 0e0cb9a

Please sign in to comment.