Skip to content

Commit a3a41c6

Browse files
committed
some improvements for masks
1 parent ada7a4d commit a3a41c6

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

iCCF/masks.py

+22-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(self, mask, instrument=None):
1414
self.mask_name = mask
1515
self.instrument = instrument
1616

17-
mask_file = f'{instrument}_{mask}.fits'
17+
mask_file = self._mask_file = f'{instrument}_{mask}.fits'
1818

1919
if not os.path.exists(mask_file):
2020
try:
@@ -28,11 +28,25 @@ def __init__(self, mask, instrument=None):
2828
self._wavelength = self.wavelength.copy()
2929
self._contrast = self.contrast.copy()
3030

31+
@classmethod
32+
def from_arrays(cls, wavelength, contrast, name=None, instrument=None):
33+
self = cls.__new__(cls)
34+
self.wavelength = wavelength
35+
self.contrast = contrast
36+
self._wavelength = self.wavelength.copy()
37+
self._contrast = self.contrast.copy()
38+
self.mask_name = name or 'unnamed'
39+
self.instrument = None
40+
return self
41+
42+
3143
@property
3244
def nlines(self):
3345
return self.wavelength.size
3446

3547
def __repr__(self):
48+
if self.instrument is None:
49+
return f'Mask({self.mask_name}, {self.nlines} lines)'
3650
return f'Mask({self.mask_name}, {self.instrument}, {self.nlines} lines)'
3751

3852
def __getitem__(self, key):
@@ -75,16 +89,21 @@ def reset(self):
7589
self.wavelength = self._wavelength
7690
self.contrast = self._contrast
7791

78-
def plot(self, ax=None, rv=0, down=False, factor=1, show_original=True, **kwargs):
92+
def plot(self, ax=None, rv=0, down=False, factor=1, show_original=True, norm=False,
93+
**kwargs):
7994
if ax is None:
8095
fig, ax = plt.subplots(figsize=(8, 4), constrained_layout=True)
8196
else:
8297
fig = ax.figure
8398

8499
if down:
85100
a, b = -self.contrast * factor, 0
101+
if norm:
102+
a /= self.contrast.max()
86103
else:
87104
a, b = 0, self.contrast * factor
105+
if norm:
106+
b /= self.contrast.max()
88107

89108
w = doppler_shift_wave(self.wavelength, rv)
90109
ax.vlines(w, a, b, alpha=0.8, **kwargs,
@@ -98,3 +117,4 @@ def plot(self, ax=None, rv=0, down=False, factor=1, show_original=True, **kwargs
98117

99118
ax.legend()
100119
ax.set(xlabel=r'wavelength [$\AA$]', ylabel='contrast')
120+
return fig, ax

0 commit comments

Comments
 (0)