Skip to content

Commit

Permalink
fixed bug with specutils reading in wrong units; added proper error t…
Browse files Browse the repository at this point in the history
…o HST
  • Loading branch information
afaisst committed Jun 14, 2024
1 parent 957d340 commit 12f839e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
15 changes: 11 additions & 4 deletions spectroscopy/code_src/mast_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,17 @@ def JWST_get_spec_helper(sample_table, search_radius_arcsec, datadir, verbose):
file_idx = np.where( [ tab["productFilename"][jj] in download_results["Local Path"][iii] for iii in range(len(download_results))] )[0]

# open spectrum
# Note that specutils returns the wrong units. Use Table.read() instead.
filepath = download_results["Local Path"][file_idx[0]]
spec1d = Table.read(filepath , hdu=1)

#print(filepath)
spec1d = Spectrum1D.read(filepath)
#spec1d = Spectrum1D.read(filepath)

dfsingle = pd.DataFrame(dict(wave=[spec1d.spectral_axis] , flux=[spec1d.flux], err=[np.repeat(0,len(spec1d.flux))],
dfsingle = pd.DataFrame(dict(#wave=[spec1d.spectral_axis] , flux=[spec1d.flux], err=[np.repeat(0,len(spec1d.flux))],,
wave=[spec1d["WAVELENGTH"].data * spec1d["WAVELENGTH"].unit] ,
flux=[spec1d["FLUX"].data * spec1d["FLUX"].unit],
err=[spec1d["FLUX_ERROR"].data * spec1d["FLUX_ERROR"].unit],
label=[stab["label"]],
objectid=[stab["objectid"]],
#objID=[tab["objID"][jj]], # REMOVE
Expand Down Expand Up @@ -205,7 +211,7 @@ def JWST_group_spectra(df, verbose, quickplot):
objects_unique = np.unique(tab["label"])

for obj in objects_unique:
if verbose: print("++Processing Object {} ++".format(obj))
print("Grouping object {}".format(obj))

## Get filters
filters_unique = np.unique(tab["filter"])
Expand Down Expand Up @@ -349,7 +355,8 @@ def HST_get_spec(sample_table, search_radius_arcsec, datadir, verbose):
spec1d = Spectrum1D.read(filepath)

# Note: this should be in erg/s/cm2/A and any wavelength unit.
dfsingle = pd.DataFrame(dict(wave=[spec1d.spectral_axis] , flux=[spec1d.flux], err=[np.repeat(0,len(spec1d.flux))],
dfsingle = pd.DataFrame(dict(#wave=[spec1d.spectral_axis] , flux=[spec1d.flux], err=[np.repeat(0,len(spec1d.flux))],
wave=[spec1d.spectral_axis] , flux=[spec1d.flux], err=[spec1d.uncertainty.array * spec1d.uncertainty.unit],
label=[stab["label"]],
objectid=[stab["objectid"]],
#objID=[tab["objID"][jj]],
Expand Down
22 changes: 13 additions & 9 deletions spectroscopy/spectra_generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,23 @@ labels = []
coords.append(SkyCoord("{} {}".format("09 54 49.40" , "+09 16 15.9"), unit=(u.hourangle, u.deg) ))
labels.append("NGC3049")

coords.append(SkyCoord("{} {}".format("12 45 17.44 " , "27 07 31.8"), unit=(u.hourangle, u.deg) ))
labels.append("NGC4670")
#coords.append(SkyCoord("{} {}".format("12 45 17.44 " , "27 07 31.8"), unit=(u.hourangle, u.deg) ))
#labels.append("NGC4670")

coords.append(SkyCoord("{} {}".format("14 01 19.92" , "−33 04 10.7"), unit=(u.hourangle, u.deg) ))
labels.append("Tol_89")
#coords.append(SkyCoord("{} {}".format("14 01 19.92" , "−33 04 10.7"), unit=(u.hourangle, u.deg) ))
#labels.append("Tol_89")

coords.append(SkyCoord(233.73856 , 23.50321, unit=u.deg ))
labels.append("Arp220")
#coords.append(SkyCoord(233.73856 , 23.50321, unit=u.deg ))
#labels.append("Arp220")

coords.append(SkyCoord( 150.091 , 2.2745833, unit=u.deg ))
labels.append("COSMOS1")

coords.append(SkyCoord( 150.1024475 , 2.2815559, unit=u.deg ))
labels.append("COSMOS2")

coords.append(SkyCoord("{} {}".format("150.000" , "+2.00"), unit=(u.deg, u.deg) ))
labels.append("COSMOS3")
#coords.append(SkyCoord("{} {}".format("150.000" , "+2.00"), unit=(u.deg, u.deg) ))
#labels.append("COSMOS3")

coords.append(SkyCoord("{} {}".format("+53.15508" , "-27.80178"), unit=(u.deg, u.deg) ))
labels.append("JADESGS-z7-01-QU")
Expand Down Expand Up @@ -232,7 +232,7 @@ This archive includes spectra taken by
```python
%%time
## Get Spectra for HST
df_spec_HST = HST_get_spec(sample_table , search_radius_arcsec = 0.5, datadir = "./data/", verbose = False)
df_spec_HST = HST_get_spec(sample_table , search_radius_arcsec = 0.5, datadir = "./data/", verbose = True)
df_spec.append(df_spec_HST)
```

Expand All @@ -243,6 +243,10 @@ df_jwst = JWST_get_spec(sample_table , search_radius_arcsec = 0.5, datadir = "./
df_spec.append(df_jwst)
```

```python
df_spec.data
```

### 2.3 SDSS Archive

This includes SDSS spectra.
Expand Down

0 comments on commit 12f839e

Please sign in to comment.