COMPASS  5.4.4
End-to-end AO simulation tool using GPU acceleration
targetCompass.py
1 
37 from shesha.init.target_init import target_init
38 from shesha.supervisor.components.sourceCompass import SourceCompass
39 import numpy as np
40 
42  """ Target handler for compass simulation
43 
44  Attributes:
45  sources : (List) : List of SutraSource instances used for raytracing
46 
47  _target : (sutraWrap.Target) : Sutra target instance
48 
49  _context : (carmaContext) : CarmaContext instance
50 
51  _config : (config module) : Parameters configuration structure module
52  """
53  def __init__(self, context, config, tel):
54  """ Initialize a TargetCompass component for target related supervision
55 
56  Args:
57  context : (carmaContext) : CarmaContext instance
58 
59  config : (config module) : Parameters configuration structure module
60 
61  tel : (TelescopeCompass) : A TelescopeCompass instance
62  """
63  self._context_context = context
64  self._config_config = config # Parameters configuration coming from supervisor init
65  print("->target init")
66  self._target_target = target_init(self._context_context, tel._tel, self._config_config.p_targets,
67  self._config_config.p_atmos, self._config_config.p_tel,
68  self._config_config.p_geom, self._config_config.p_dms, brahma=False)
69  self.sourcessourcessources = self._target_target.d_targets
70 
71  def get_tar_image(self, tar_index : int, *, expo_type: str = "se") -> np.ndarray:
72  """ Get the PSF in the direction of the given target
73 
74  Args:
75  tar_index : (int) : Index of target
76 
77  Kwargs:
78  expo_type : (str) : "se" for short exposure (default)
79  "le" for long exposure
80 
81  Returns:
82  psf : (np.ndarray) : PSF
83  """
84  if (expo_type == "se"):
85  return np.fft.fftshift(
86  np.array(self._target_target.d_targets[tar_index].d_image_se))
87  elif (expo_type == "le"):
88  nb = self._target_target.d_targets[tar_index].strehl_counter
89  if nb == 0: nb = 1
90  return np.fft.fftshift(np.array(self._target_target.d_targets[tar_index].d_image_le)) / nb
91  else:
92  raise ValueError("Unknown exposure type")
93 
94  def set_tar_phase(self, tar_index : int, phase : np.ndarray) -> None:
95  """ Set the phase screen seen by the tar
96 
97  Args:
98  tar_index : (int) : target index
99 
100  phase : (np.ndarray) : phase screen to set
101  """
102  self._target_target.d_targets[tar_index].set_phase(phase)
103 
104  def get_tar_phase(self, tar_index: int, *, pupil: bool = False) -> np.ndarray:
105  """ Returns the target phase screen of target number tar_index
106 
107  Args:
108  tar_index : (int) : Target index
109 
110  Kwargs:
111  pupil : (bool) : If True, applies the pupil on top of the phase screen
112  Default is False
113 
114  Returns:
115  tar_phase : (np.ndarray) : Target phase screen
116  """
117  tar_phase = np.array(self._target_target.d_targets[tar_index].d_phase)
118  if pupil:
119  pup = self._config_config.p_geom._spupil
120  tar_phase *= pup
121  return tar_phase
122 
123  def reset_strehl(self, tar_index: int) -> None:
124  """ Reset the Strehl Ratio of the target tar_index
125 
126  Args:
127  tar_index : (int) : Target index
128  """
129  self._target_target.d_targets[tar_index].reset_strehlmeter()
130 
131  def reset_tar_phase(self, tar_index: int) -> None:
132  """ Reset the phase screen of the target tar_index
133 
134  Args:
135  tar_index : (int) : Target index
136  """
137  self._target_target.d_targets[tar_index].d_phase.reset()
138 
139  def get_strehl(self, tar_index: int, *, do_fit: bool = True) -> np.ndarray:
140  """ Return the Strehl Ratio of target number tar_index.
141  This fuction will return an array of 4 values as
142  [SR SE, SR LE, phase variance SE [rad²], phase variance LE [rad²]]
143 
144  Args:
145  tar_index : (int) : Target index
146 
147  Kwargs:
148  do_fit : (bool) : If True (default), fit the PSF
149  with a sinc before computing SR
150 
151  Returns:
152  strehl : (np.ndarray) : Strehl ratios and phase variances
153  """
154  src = self._target_target.d_targets[tar_index]
155  src.comp_strehl(do_fit)
156  avg_var = 0
157  if (src.phase_var_count > 0):
158  avg_var = src.phase_var_avg / src.phase_var_count
159  return [src.strehl_se, src.strehl_le, src.phase_var, avg_var]
160 
161  def get_ncpa_tar(self, tar_index : int) -> np.ndarray:
162  """ Return the current NCPA phase screen of the target path
163 
164  Args:
165  tar_index : (int) : Index of the target
166 
167  Returns:
168  ncpa : (np.ndarray) : NCPA phase screen
169  """
170  return np.array(self._target_target.d_targets[tar_index].d_ncpa_phase)
171 
172  def set_ncpa_tar(self, tar_index: int, ncpa: np.ndarray) -> None:
173  """ Set the additional fixed NCPA phase in the target path.
174  ncpa must be of the same size of the spupil support
175 
176  Args:
177  tar_index : (int) : WFS index
178 
179  ncpa : (ndarray) : NCPA phase screen to set [µm]
180  """
181  self._target_target.d_targets[tar_index].set_ncpa(ncpa)
182 
183  def comp_tar_image(self, tarNum: int, *, puponly: int = 0, compLE: bool = True) -> None:
184  """ Computes the PSF
185 
186  Args:
187  tarNum: (int): target index
188 
189  Kwargs:
190  puponly: (int) : if set to 1, computes Airy (default=0)
191 
192  compLE: (bool) : if True, the computed image is taken into account in long exposure image (default=True)
193  """
194  self._target_target.d_targets[tarNum].comp_image(puponly, compLE)
195 
196  def comp_strehl(self, tarNum: int, *, do_fit: bool = True) -> None:
197  """ Computes the Strehl ratio
198 
199  Args:
200  tarNum: (int): target index
201 
202  Kwargs:
203  do_fit: (bool): Flag for enabling fitting by sinc
204  """
205  self._target_target.d_targets[tarNum].comp_strehl(do_fit)
Source handler for compass simulation.
sources
(List) : List of SutraSource instances
Target handler for compass simulation.
None reset_tar_phase(self, int tar_index)
Reset the phase screen of the target tar_index.
None set_tar_phase(self, int tar_index, np.ndarray phase)
Set the phase screen seen by the tar.
None set_ncpa_tar(self, int tar_index, np.ndarray ncpa)
Set the additional fixed NCPA phase in the target path.
None comp_tar_image(self, int tarNum, *int puponly=0, bool compLE=True)
Computes the PSF.
np.ndarray get_strehl(self, int tar_index, *bool do_fit=True)
Return the Strehl Ratio of target number tar_index.
np.ndarray get_tar_image(self, int tar_index, *str expo_type="se")
Get the PSF in the direction of the given target.
np.ndarray get_ncpa_tar(self, int tar_index)
Return the current NCPA phase screen of the target path.
None comp_strehl(self, int tarNum, *bool do_fit=True)
Computes the Strehl ratio.
np.ndarray get_tar_phase(self, int tar_index, *bool pupil=False)
Returns the target phase screen of target number tar_index.
None reset_strehl(self, int tar_index)
Reset the Strehl Ratio of the target tar_index.
sources
(List) : List of SutraSource instances used for raytracing
Initialization of a Target object.
Definition: target_init.py:1