39 import astropy.io.fits
as fits
40 import matplotlib.pyplot
as plt
47 def __init__(self, SR=np.zeros((0, 0)), radius=0, wl=0, NGS=
None, LGS=
None, TS=
None,
48 AOtype=
"AO", sup=
None, filename=
None):
51 SR : np.ndarray : array of strehl (organised by position)
52 radius : float : radius of the map (in arcsec)
53 wl : float : wavelength of observation (in nm)
54 NGS : np.ndarray : position (arcsec) of the NGS (1st line:x axis, 2nd:y axis)
55 LGS : np.ndarray : position (arcsec) of the LGS (1st line:x axis, 2nd:y axis)
56 TS : np.ndarray : position (arcsec) of the TS (1st line:x axis, 2nd:y axis)
57 sup : shesha.supervisor : shesha supervisor to retrieve all data from
58 filename: str : filename to read the psf map from
61 using 'sup' will take only the supervisor into consideration
62 using 'filename' will overide previous values of the psf map (unless called with sup)
76 self.
NGSx = np.zeros((0))
77 self.
NGSy = np.zeros((0))
84 self.
LGSx = np.zeros((0))
85 self.
LGSy = np.zeros((0))
90 self.
_Rts = max(self.
TSx.max(), self.
TSy.max())
92 self.
TSx = np.zeros((0))
93 self.
TSy = np.zeros((0))
99 self.
NGSx = np.array([t.xpos
for t
in sup.config.p_wfs_ngs[:-1]])
100 self.
NGSy = np.array([t.ypos
for t
in sup.config.p_wfs_ngs[:-1]])
102 self.
LGSx = np.array([t.xpos
for t
in sup.config.p_wfs_lgs])
103 self.
LGSy = np.array([t.ypos
for t
in sup.config.p_wfs_lgs])
105 self.
TSx = np.array([t.xpos
for t
in sup.config.p_wfs_ts])
106 self.
TSy = np.array([t.ypos
for t
in sup.config.p_wfs_ts])
107 self.
_Rts = max(self.
TSx.max(), self.
TSy.max())
108 self.
wavelength = sup.config.p_targets[0].Lambda
109 NTAR = len(sup.config.p_targets)
110 NTAR_side = int(np.sqrt(NTAR))
111 if (NTAR != NTAR_side**2):
112 raise ValueError(
"not a square nb of targets")
113 self.
map = np.zeros((NTAR_side, NTAR_side))
114 for i
in range(NTAR):
116 self.
map.itemset(i, sup._sim.get_strehl(i)[0])
117 tar = sup._sim.tar.d_targets[i]
118 self.
_Rtar = max(self.
_Rtar, tar.posx, tar.posy)
120 elif (filename
is not None):
148 self.
_Rts = max(self.
TSx.max(), self.
TSy.max())
153 def plot(self, title=False, GS=False, WFS=False, LGS=False, NGS=False, TS=False):
154 if (self.
map.shape[0] > 0
and self.
map.shape[1] > 0):
155 plt.matshow(self.
map,
158 if (GS
or WFS
or LGS):
159 plt.scatter(self.
LGSy, self.
LGSx, color=
"red")
160 if (GS
or WFS
or NGS):
161 plt.scatter(self.
NGSy, self.
NGSx, color=
"blue")
163 plt.scatter(self.
TSy, self.
TSx, color=
"yellow", s=1)
165 t = self.
type +
" Strehl"
170 t +=
", {:.2f}".format(self.
_Rts) +
" arcsec ring optim"
175 hdu_map = fits.PrimaryHDU(self.
map)
176 hdu_map.header[
"TYPE"] = self.
type
178 hdu_map.header[
"RTAR"] = self.
_Rtar
179 hdu_map.header[
"RLGS"] = self.
_Rlgs
180 hdu_map.header[
"RNGS"] = self.
_Rngs
181 hdu_map.header[
"RTS"] = self.
_Rts
182 hdu_LGSX = fits.ImageHDU(self.
LGSx, name=
"LGSX")
183 hdu_LGSY = fits.ImageHDU(self.
LGSy, name=
"LGSY")
184 hdu_NGSX = fits.ImageHDU(self.
NGSx, name=
"NGSX")
185 hdu_NGSY = fits.ImageHDU(self.
NGSy, name=
"NGSY")
186 hdu_TSX = fits.ImageHDU(self.
TSx, name=
"TSX")
187 hdu_TSY = fits.ImageHDU(self.
TSy, name=
"TSY")
189 hdul = fits.HDUList([
190 hdu_map, hdu_LGSX, hdu_LGSY, hdu_NGSX, hdu_NGSY, hdu_TSX, hdu_TSY
192 t = self.
type +
"_StrehlMap"
196 t +=
"_{:.2f}arcsec".format(self.
_Rts)
200 hdul.writeto(name, overwrite=1)
203 hdu_map = fits.open(name)
204 self.
type = hdu_map[0].header[
"TYPE"]
206 self.
_Rtar = hdu_map[0].header[
"RTAR"]
207 self.
_Rlgs = hdu_map[0].header[
"RLGS"]
208 self.
_Rngs = hdu_map[0].header[
"RNGS"]
209 self.
_Rts = hdu_map[0].header[
"RTS"]
210 self.
map = hdu_map[0].data
211 self.
LGSx = hdu_map[
"LGSx"].data
212 self.
LGSy = hdu_map[
"LGSy"].data
213 self.
NGSx = hdu_map[
"NGSx"].data
214 self.
NGSy = hdu_map[
"NGSy"].data
215 self.
TSx = hdu_map[
"TSx"].data
216 self.
TSy = hdu_map[
"TSy"].data