Skip to content

Commit be52b00

Browse files
committed
added rv attributes to MrsSpec & MrsEpoch
1 parent adb1dd5 commit be52b00

1 file changed

Lines changed: 48 additions & 11 deletions

File tree

laspec/mrs.py

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
import glob
12
import os
3+
4+
import matplotlib.pyplot as plt
25
import numpy as np
6+
from astropy import constants as const
37
from astropy.io import fits
48
from astropy.table import Table
9+
510
from .normalization import normalize_spectrum_iter
611

712

@@ -26,6 +31,7 @@ class MrsSpec:
2631
lmjmlist = ""
2732
lamplist = None
2833
info = {}
34+
rv = 0.
2935

3036
# status
3137
isempty = True
@@ -137,6 +143,17 @@ def normalize(self, **norm_kwargs):
137143
self.flux_norm, self.flux_cont, self.ivar_norm = None, None, None
138144
return
139145

146+
def wave_rv(self, rv=None):
147+
""" return RV-corrected wavelength array
148+
Parameter
149+
---------
150+
rv:
151+
float, radial velocity [km/s]
152+
"""
153+
if rv is None:
154+
rv = self.rv
155+
return self.wave / (1 + rv * 1000 / const.c.value)
156+
140157

141158
class MrsEpoch:
142159
""" MRS epoch spcetrum """
@@ -146,6 +163,7 @@ class MrsEpoch:
146163
# the most important attributes
147164
epoch = -1
148165
snr = []
166+
rv = 0.
149167

150168
wave = np.array([], dtype=np.float)
151169
flux = np.array([], dtype=np.float)
@@ -244,6 +262,17 @@ def normalize(self, **norm_kwargs):
244262
self.flux_cont = np.append(self.flux_cont, self.speclist[i_spec].flux_cont)
245263
return
246264

265+
def wave_rv(self, rv=0.):
266+
""" return RV-corrected wavelength array
267+
Parameter
268+
---------
269+
rv:
270+
float, radial velocity [km/s]
271+
"""
272+
if rv is None:
273+
rv = self.rv
274+
return self.wave / (1 + rv * 1000 / const.c.value)
275+
247276

248277
class MrsFits(fits.HDUList):
249278
nhdu = 0
@@ -293,11 +322,6 @@ def __init__(self, fp=None):
293322
elif not self.hdunames[i] == "Information":
294323
raise RuntimeError("@MrsSpec: error during processing HDU name")
295324

296-
# get one spec (specify a key)
297-
# get one epoch (specify a lmjm)
298-
# get all epochs (specify a file path)
299-
# get all
300-
301325
def __repr__(self):
302326
""" as self.info()
303327
Summarize the info of the HDUs in this `HDUList`.
@@ -320,6 +344,7 @@ def __repr__(self):
320344
results.append(format.format(*summary))
321345
return "\n".join(results[1:])
322346

347+
# or get one spec (specify a key)?
323348
def get_one_spec(self, lmjm="COADD", band="B"):
324349
if lmjm == "COADD":
325350
k = "COADD_{}".format(band)
@@ -371,12 +396,24 @@ def ls_epoch(self):
371396

372397
@property
373398
def ls_snr(self):
374-
return np.unique(self.lmjm[self.lmjm > 0])
399+
return np.unique(self.snr[self.lmjm > 0])
400+
401+
@property
402+
def epoch(self):
403+
return self.lmjm
404+
405+
@property
406+
def snr(self):
407+
_snr = np.zeros((self.nhdu,), dtype=np.float)
408+
for i in range(self.nhdu):
409+
if "SNR" in self[i].header.keys():
410+
_snr[i] = self[i].header["SNR"]
411+
return _snr
375412

376413

377414
class MrsSource(np.ndarray):
378415
""" array of MrsEpoch instances, """
379-
mes = [] # MrsEpoch list #
416+
mes = [] # MrsEpoch list #
380417
name = "" # source name
381418

382419
@property
@@ -391,6 +428,10 @@ def epoch(self):
391428
def nepoch(self):
392429
return len(self)
393430

431+
@property
432+
def rv(self):
433+
return np.array([_.rv for _ in self], dtype=np.float)
434+
394435
def __new__(cls, data, name="", normalize=True, norm_kwargs={}, **kwargs):
395436
# prepare
396437
data = np.array(data, dtype=MrsEpoch)
@@ -425,12 +466,9 @@ def normalize(self, **norm_kwargs):
425466
self[i].normalize(**norm_kwargs)
426467
return
427468

428-
# TODO: MrsFits: MJD & S/N of each epoch spec, and other information?
429-
430469

431470
if __name__ == "__main__":
432471
fp = "/Users/cham/PycharmProjects/laspec/laspec/data/KIC8098300/DR7_medium/med-58625-TD192102N424113K01_sp12-076.fits.gz"
433-
import glob
434472
fps = glob.glob("/Users/cham/PycharmProjects/laspec/laspec/data/KIC8098300/DR7_medium/*.fits.gz")
435473
# read fits
436474
mf = MrsFits(fp)
@@ -464,6 +502,5 @@ def normalize(self, **norm_kwargs):
464502
msrc = MrsSource(mes)
465503
msrc1 = MrsSource.read(fps)
466504

467-
import matplotlib.pyplot as plt
468505
fig = plt.figure()
469506
plt.plot(me.wave, me.flux_norm)

0 commit comments

Comments
 (0)