39 import astropy.io.fits
as fits
40 import matplotlib.pyplot
as plt
45 def __init__(self, SR=np.zeros((0, 0)), radius=0, wl=0, NGS=
None, LGS=
None, TS=
None,
46 AOtype=
"AO", sup=
None, filename=
None):
49 SR : np.ndarray : array of strehl (organised by position)
50 radius : float : radius of the map (in arcsec)
51 wl : float : wavelength of observation (in nm)
52 NGS : np.ndarray : position (arcsec) of the NGS (1st line:x axis, 2nd:y axis)
53 LGS : np.ndarray : position (arcsec) of the LGS (1st line:x axis, 2nd:y axis)
54 TS : np.ndarray : position (arcsec) of the TS (1st line:x axis, 2nd:y axis)
55 sup : shesha.supervisor : shesha supervisor to retrieve all data from
56 filename: str : filename to read the psf map from
59 using 'sup' will take only the supervisor into consideration
60 using 'filename' will overide previous values of the psf map (unless called with sup)
65 self.
_Rtar_Rtar = radius
72 self.
_Rngs_Rngs = max((self.
NGSxNGSx.max(), self.
NGSyNGSy.max()))
74 self.
NGSxNGSx = np.zeros((0))
75 self.
NGSyNGSy = np.zeros((0))
80 self.
_Rlgs_Rlgs = max(self.
LGSxLGSx.max(), self.
LGSyLGSy.max())
82 self.
LGSxLGSx = np.zeros((0))
83 self.
LGSyLGSy = np.zeros((0))
88 self.
_Rts_Rts = max(self.
TSxTSx.max(), self.
TSyTSy.max())
90 self.
TSxTSx = np.zeros((0))
91 self.
TSyTSy = np.zeros((0))
97 self.
NGSxNGSx = np.array([t.xpos
for t
in sup.config.p_wfs_ngs[:-1]])
98 self.
NGSyNGSy = np.array([t.ypos
for t
in sup.config.p_wfs_ngs[:-1]])
99 self.
_Rngs_Rngs = max((self.
NGSxNGSx.max(), self.
NGSyNGSy.max()))
100 self.
LGSxLGSx = np.array([t.xpos
for t
in sup.config.p_wfs_lgs])
101 self.
LGSyLGSy = np.array([t.ypos
for t
in sup.config.p_wfs_lgs])
102 self.
_Rlgs_Rlgs = max(self.
LGSxLGSx.max(), self.
LGSyLGSy.max())
103 self.
TSxTSx = np.array([t.xpos
for t
in sup.config.p_wfs_ts])
104 self.
TSyTSy = np.array([t.ypos
for t
in sup.config.p_wfs_ts])
105 self.
_Rts_Rts = max(self.
TSxTSx.max(), self.
TSyTSy.max())
106 self.
wavelengthwavelength = sup.config.p_targets[0].Lambda
107 NTAR = len(sup.config.p_targets)
108 NTAR_side = int(np.sqrt(NTAR))
109 if (NTAR != NTAR_side**2):
110 raise ValueError(
"not a square nb of targets")
111 self.
mapmap = np.zeros((NTAR_side, NTAR_side))
112 for i
in range(NTAR):
114 self.
mapmap.itemset(i, sup._sim.get_strehl(i)[0])
115 tar = sup._sim.tar.d_targets[i]
116 self.
_Rtar_Rtar = max(self.
_Rtar_Rtar, tar.posx, tar.posy)
118 elif (filename
is not None):
119 self.
readread(filename)
123 self.
NGSxNGSx = NGS[0]
124 self.
NGSyNGSy = NGS[1]
128 self.
_Rngs_Rngs = max((self.
NGSxNGSx.max(), self.
NGSyNGSy.max()))
132 self.
LGSxLGSx = LGS[0]
133 self.
LGSyLGSy = LGS[1]
137 self.
_Rlgs_Rlgs = max(self.
LGSxLGSx.max(), self.
LGSyLGSy.max())
146 self.
_Rts_Rts = max(self.
TSxTSx.max(), self.
TSyTSy.max())
151 def plot(self, title=False, GS=False, WFS=False, LGS=False, NGS=False, TS=False):
152 if (self.
mapmap.shape[0] > 0
and self.
mapmap.shape[1] > 0):
153 plt.matshow(self.
mapmap,
156 if (GS
or WFS
or LGS):
157 plt.scatter(self.
LGSyLGSy, self.
LGSxLGSx, color=
"red")
158 if (GS
or WFS
or NGS):
159 plt.scatter(self.
NGSyNGSy, self.
NGSxNGSx, color=
"blue")
161 plt.scatter(self.
TSyTSy, self.
TSxTSx, color=
"yellow", s=1)
163 t = self.
typetype +
" Strehl"
165 t +=
" @ {:.3f} nm".format(self.
wavelengthwavelength)
167 if (self.
_Rts_Rts > 0):
168 t +=
", {:.2f}".format(self.
_Rts_Rts) +
" arcsec ring optim"
173 hdu_map = fits.PrimaryHDU(self.
mapmap)
174 hdu_map.header[
"TYPE"] = self.
typetype
175 hdu_map.header[
"LAMBDA"] = self.
wavelengthwavelength
176 hdu_map.header[
"RTAR"] = self.
_Rtar_Rtar
177 hdu_map.header[
"RLGS"] = self.
_Rlgs_Rlgs
178 hdu_map.header[
"RNGS"] = self.
_Rngs_Rngs
179 hdu_map.header[
"RTS"] = self.
_Rts_Rts
180 hdu_LGSX = fits.ImageHDU(self.
LGSxLGSx, name=
"LGSX")
181 hdu_LGSY = fits.ImageHDU(self.
LGSyLGSy, name=
"LGSY")
182 hdu_NGSX = fits.ImageHDU(self.
NGSxNGSx, name=
"NGSX")
183 hdu_NGSY = fits.ImageHDU(self.
NGSyNGSy, name=
"NGSY")
184 hdu_TSX = fits.ImageHDU(self.
TSxTSx, name=
"TSX")
185 hdu_TSY = fits.ImageHDU(self.
TSyTSy, name=
"TSY")
187 hdul = fits.HDUList([
188 hdu_map, hdu_LGSX, hdu_LGSY, hdu_NGSX, hdu_NGSY, hdu_TSX, hdu_TSY
190 t = self.
typetype +
"_StrehlMap"
192 t +=
"_{:.3f}nm".format(self.
wavelengthwavelength)
193 if (self.
_Rts_Rts > 0):
194 t +=
"_{:.2f}arcsec".format(self.
_Rts_Rts)
198 hdul.writeto(name, overwrite=1)
201 hdu_map = fits.open(name)
202 self.
typetype = hdu_map[0].header[
"TYPE"]
203 self.
wavelengthwavelength = hdu_map[0].header[
"LAMBDA"]
204 self.
_Rtar_Rtar = hdu_map[0].header[
"RTAR"]
205 self.
_Rlgs_Rlgs = hdu_map[0].header[
"RLGS"]
206 self.
_Rngs_Rngs = hdu_map[0].header[
"RNGS"]
207 self.
_Rts_Rts = hdu_map[0].header[
"RTS"]
208 self.
mapmap = hdu_map[0].data
209 self.
LGSxLGSx = hdu_map[
"LGSx"].data
210 self.
LGSyLGSy = hdu_map[
"LGSy"].data
211 self.
NGSxNGSx = hdu_map[
"NGSx"].data
212 self.
NGSyNGSy = hdu_map[
"NGSy"].data
213 self.
TSxTSx = hdu_map[
"TSx"].data
214 self.
TSyTSy = hdu_map[
"TSy"].data
def plot(self, title=False, GS=False, WFS=False, LGS=False, NGS=False, TS=False)
def setLGS(self, LGS, LGSy=None)
def setNGS(self, NGS, NGSy=None)
def setWaveLength(self, wl)
def __init__(self, SR=np.zeros((0, 0)), radius=0, wl=0, NGS=None, LGS=None, TS=None, AOtype="AO", sup=None, filename=None)
SR_map class.
def setTS(self, TS, TSy=None)