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