40 from typing
import List
43 """ Atmosphere handler for compass simulation
46 atmos : (sutraWrap.Atmos) : Sutra atmos instance
48 is_enable : (bool) : Flag to enable/disable atmophere
50 context : (carmaContext) : CarmaContext instance
52 config : (config module) : Parameters configuration structure module
55 """ Initialize an AtmosCompass component for atmosphere related supervision
58 context : (carmaContext) : CarmaContext instance
60 config : (config module) : Parameters configuration structure module
65 print(
"->atmosphere init")
68 p_targets=self.
config.p_targets)
72 """ Set or unset whether atmos is enabled when running loop
75 enable : (bool) : True to enable, False to disable
79 def set_r0(self, r0 : float, *, reset_seed : int=-1) ->
None:
80 """ Change the current r0 for all layers
83 r0 : (float) : r0 @ 0.5 µm
85 reset_seed : (int, optional): if -1 (default), keep same seed and same screen
86 if 0 random seed is applied and refresh screens
87 if (value) set the given seed and refresh screens
92 ilayer = np.random.randint(1e4)
95 for k
in range(self.
atmos.nscreens):
96 self.
atmos.set_seed(k, 1234 + ilayer)
97 self.
atmos.refresh_screen(k)
101 def set_wind(self, screen_index : int, *, windspeed : float =
None, winddir : float =
None) ->
None:
102 """ Set new wind information for the given screen
105 screen_index : (int) : Atmos screen to change
107 windspeed : (float) [m/s] : new wind speed of the screen. If None, the wind speed is unchanged
109 winddir : (float) [deg]: new wind direction of the screen. If None, the wind direction is unchanged
111 if windspeed
is not None:
112 self.
config.p_atmos.windspeed[screen_index] = windspeed
113 if winddir
is not None:
114 self.
config.p_atmos.winddir[screen_index] = winddir
116 lin_delta = self.
config.p_geom.pupdiam / self.
config.p_tel.diam * self.
config.p_atmos.windspeed[screen_index] * \
117 np.cos(CONST.DEG2RAD * self.
config.p_geom.zenithangle) * self.
config.p_loop.ittime
118 oldx = self.
config.p_atmos._deltax[screen_index]
119 oldy = self.
config.p_atmos._deltay[screen_index]
120 self.
config.p_atmos._deltax[screen_index] = lin_delta * np.sin(CONST.DEG2RAD * self.
config.p_atmos.winddir[screen_index] + np.pi)
121 self.
config.p_atmos._deltay[screen_index] = lin_delta * np.cos(CONST.DEG2RAD * self.
config.p_atmos.winddir[screen_index] + np.pi)
122 self.
atmos.d_screens[screen_index].set_deltax(self.
config.p_atmos._deltax[screen_index])
123 self.
atmos.d_screens[screen_index].set_deltay(self.
config.p_atmos._deltay[screen_index])
124 if(oldx * self.
config.p_atmos._deltax[screen_index] < 0):
125 stencilx = np.array(self.
atmos.d_screens[screen_index].d_istencilx)
126 n = self.
config.p_atmos.dim_screens[screen_index]
127 stencilx = (n * n - 1) - stencilx
128 self.
atmos.d_screens[screen_index].set_istencilx(stencilx)
129 if(oldy * self.
config.p_atmos._deltay[screen_index] < 0):
130 stencily = np.array(self.
atmos.d_screens[screen_index].d_istencily)
131 n = self.
config.p_atmos.dim_screens[screen_index]
132 stencily = (n * n - 1) - stencily
133 self.
atmos.d_screens[screen_index].set_istencily(stencily)
136 """ Reset the turbulence layers to their original state
139 for k
in range(self.
atmos.nscreens):
140 self.
atmos.set_seed(k, 1234 + ilayer)
141 self.
atmos.refresh_screen(k)
145 """ Return the selected atmos screen
148 indx : (int) : Index of the turbulent layer to return
151 layer : (np.ndarray) : turbulent layer phase screen
153 return np.array(self.
atmos.d_screens[indx].d_screen)
156 """ Move the turbulent layers according to wind speed and direction for a single iteration