COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
atmosCompass.py
1 
37 from shesha.init.atmos_init import atmos_init
38 from shesha.constants import CONST
39 import numpy as np
40 from typing import List
41 
42 class AtmosCompass(object):
43  """ Atmosphere handler for compass simulation
44 
45  Attributes:
46  atmos : (sutraWrap.Atmos) : Sutra atmos instance
47 
48  is_enable : (bool) : Flag to enable/disable atmophere
49 
50  context : (carmaContext) : CarmaContext instance
51 
52  config : (config module) : Parameters configuration structure module
53  """
54  def __init__(self, context, config):
55  """ Initialize an AtmosCompass component for atmosphere related supervision
56 
57  Parameters:
58  context : (carmaContext) : CarmaContext instance
59 
60  config : (config module) : Parameters configuration structure module
61  """
62  self.context = context
63  self.is_enable = True # Flag to enable/disable atmophere
64  self.config = config # Parameters configuration coming from supervisor init
65  print("->atmosphere init")
66  self.atmos = atmos_init(self.context, self.config.p_atmos, self.config.p_tel,
67  self.config.p_geom, self.config.p_loop.ittime, p_wfss=self.config.p_wfss,
68  p_targets=self.config.p_targets)
69 
70 
71  def enable_atmos(self, enable : bool) -> None:
72  """ Set or unset whether atmos is enabled when running loop
73 
74  Parameters:
75  enable : (bool) : True to enable, False to disable
76  """
77  self.is_enable = enable
78 
79  def set_r0(self, r0 : float, *, reset_seed : int=-1) -> None:
80  """ Change the current r0 for all layers
81 
82  Parameters:
83  r0 : (float) : r0 @ 0.5 µm
84 
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
88  """
89  self.atmos.set_r0(r0)
90  if reset_seed != -1:
91  if reset_seed == 0:
92  ilayer = np.random.randint(1e4)
93  else:
94  ilayer = reset_seed
95  for k in range(self.atmos.nscreens):
96  self.atmos.set_seed(k, 1234 + ilayer)
97  self.atmos.refresh_screen(k)
98  ilayer += 1
99  self.config.p_atmos.set_r0(r0)
100 
101  def set_wind(self, screen_index : int, *, windspeed : float = None, winddir : float = None) -> None:
102  """ Set new wind information for the given screen
103 
104  Parameters:
105  screen_index : (int) : Atmos screen to change
106 
107  windspeed : (float) [m/s] : new wind speed of the screen. If None, the wind speed is unchanged
108 
109  winddir : (float) [deg]: new wind direction of the screen. If None, the wind direction is unchanged
110  """
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
115 
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): #Sign has changed, must change the stencil
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): #Sign has changed, must change the stencil
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)
134 
135  def reset_turbu(self) -> None:
136  """ Reset the turbulence layers to their original state
137  """
138  ilayer = 0
139  for k in range(self.atmos.nscreens):
140  self.atmos.set_seed(k, 1234 + ilayer)
141  self.atmos.refresh_screen(k)
142  ilayer += 1
143 
144  def get_atmos_layer(self, indx: int) -> np.ndarray:
145  """ Return the selected atmos screen
146 
147  Parameters:
148  indx : (int) : Index of the turbulent layer to return
149 
150  Return:
151  layer : (np.ndarray) : turbulent layer phase screen
152  """
153  return np.array(self.atmos.d_screens[indx].d_screen)
154 
155  def move_atmos(self) -> None:
156  """ Move the turbulent layers according to wind speed and direction for a single iteration
157  """
158  self.atmos.move_atmos()
shesha.supervisor.components.atmosCompass.AtmosCompass.reset_turbu
None reset_turbu(self)
Reset the turbulence layers to their original state.
Definition: atmosCompass.py:148
shesha.constants
Numerical constants for shesha and config enumerations for safe-typing.
Definition: constants.py:1
shesha.supervisor.components.atmosCompass.AtmosCompass.atmos
atmos
Definition: atmosCompass.py:77
shesha.supervisor.components.atmosCompass.AtmosCompass.__init__
def __init__(self, context, config)
Definition: atmosCompass.py:72
shesha.supervisor.components.atmosCompass.AtmosCompass
Atmosphere handler for compass simulation.
Definition: atmosCompass.py:46
shesha.supervisor.components.atmosCompass.AtmosCompass.config
config
Initialize an AtmosCompass component for atmosphere related supervision.
Definition: atmosCompass.py:75
shesha.supervisor.components.atmosCompass.AtmosCompass.is_enable
is_enable
Definition: atmosCompass.py:74
shesha.supervisor.components.atmosCompass.AtmosCompass.enable_atmos
None enable_atmos(self, bool enable)
Set or unset whether atmos is enabled when running loop.
Definition: atmosCompass.py:87
shesha.supervisor.components.atmosCompass.AtmosCompass.move_atmos
None move_atmos(self)
Move the turbulent layers according to wind speed and direction for a single iteration.
Definition: atmosCompass.py:168
shesha.supervisor.components.atmosCompass.AtmosCompass.set_r0
None set_r0(self, float r0, *int reset_seed=-1)
Change the current r0 for all layers.
Definition: atmosCompass.py:99
shesha.init.atmos_init
Initialization of a Atmos object.
Definition: atmos_init.py:1
shesha.supervisor.components.atmosCompass.AtmosCompass.get_atmos_layer
np.ndarray get_atmos_layer(self, int indx)
Return the selected atmos screen.
Definition: atmosCompass.py:163
shesha.supervisor.components.atmosCompass.AtmosCompass.context
context
Definition: atmosCompass.py:73
shesha.supervisor.components.atmosCompass.AtmosCompass.set_wind
None set_wind(self, int screen_index, *float windspeed=None, float winddir=None)
Set new wind information for the given screen.
Definition: atmosCompass.py:121