COMPASS  5.4.4
End-to-end AO simulation tool using GPU acceleration
util/writers/yao/wfs.py
1 import numpy as np
2 
3 YAO_WFSTYPE={"sh":"\"hartmann\"", "pyrhr":"\"pyramid\""}
4 
5 def init_wfs(file_name):
6  """ Initialise wfs entry in yao parameter file
7 
8  Args:
9  file_name : (str) : yao parameter file name
10  """
11  f = open(file_name,"a+")
12  f.write("\n\n//------------------------------")
13  f.write("\n//WFS parameters")
14  f.write("\n//------------------------------")
15  return (0,0)
16 
17 def write_wfs(file_name, wfs, index, *, sub_system=1):
18  """Write (append) wfs parameter to file for YAO use for a single wfs
19 
20  Args:
21  file_name : (str) : name of the file to append the parameter to
22 
23  wfs : (Param_wfs) : compass wfs parameters
24 
25  index :(int) : wfs index in ayo parameter file
26 
27  Kwargs:
28  sub_system : (int) : (optional), default 1 sub_system in yao
29  """
30  obj = "wfs(" + str(index) + ")"
31  f = open(file_name, "a+")
32  f.write("\ngrow,wfs,wfss;")
33  f.write("\n" + obj + ".type = " + YAO_WFSTYPE[wfs.type] + ";")
34  f.write("\n" + obj + ".subsystem = " + str(sub_system) + ";")
35  f.write("\n" + obj + ".shmethod = 2" + ";")
36  f.write("\n" + obj + ".shnxsub = " + str(wfs.nxsub) + ";")
37  f.write("\n" + obj + ".lambda = " + str(wfs.Lambda) + ";")
38  f.write("\n" + obj + ".pixsize = " + str(wfs.pixsize) + ";")
39  f.write("\n" + obj + ".npixels = " + str(wfs.npix) + ";")
40  f.write("\n" + obj + ".shthreshold = 0; // not set by compass")
41  f.write("\n" + obj + ".dispzoom = 1.0; // not set by compass")
42  f.write("\n" + obj + ".fracIllum = " + str(wfs.fracsub) + ";")
43  f.write("\n" + obj + ".rotation = " + str(wfs.thetaML) + ";")
44  f.write("\n" + obj + ".shift = [ " + str(wfs.dx) + " , " + \
45  str(wfs.dy) + " ];")
46  f.write("\n" + obj + ".LLTxy = [ " + str(wfs.lltx) + " , " + \
47  str(wfs.llty) + " ];")
48  f.write("\n" + obj + ".gspos = [ " + str(wfs.xpos) + " , " + \
49  str(wfs.ypos) + " ];")
50  if(wfs.noise<0):
51  f.write("\n" +obj + ".noise = 1;")
52  f.write("\n" +obj + ".ron = 0;")
53  else:
54  f.write("\n" + obj + ".noise = 1;")
55  f.write("\n" + obj + ".ron = " + str(wfs.noise) + ";")
56  f.write("\n" + obj + ".darkcurrent = 0 ; // not set by compass ")
57  if(wfs.gsalt > 0):
58  f.write("\n" + obj + ".gsalt = " + str(wfs.gsalt) + ";")
59  f.write("\n" + obj + ".gsdepth = " + str(1) + ";")
60  f.write("\n" + obj + ".optthroughput = " + str(wfs.optthroughput) +\
61  ";")
62  f.write("\n" + obj + ".laserpower = " + str(wfs.laserpower) + ";")
63  f.write("\n" + obj + ".filtertilt = " + str(1) + ";")
64  f.write("\n" + obj + ".correctUpTT = " + str(1) + ";")
65  f.write("\n" + obj + ".uplinkgain = " + str(0.2) + ";")
66  f.close()
67 
68 
69 def write_wfss(file_name, wfss, *, n_wfs=-1, sub_system=1, offset=0):
70  """Write (append) wfs parameter to file for YAO use for a wfs list
71 
72  Args:
73  file_name : (str) : name of the file to append the parameter to
74 
75  wfss : (list[ Param_wfs]) : compass wfs parameters list
76 
77  Kwargs:
78  n_wfs : (int) : (optional), default -1 number of wfs passed to yao (-1 : all wfs)
79 
80  sub_system : (int) : (optional), default 1 yao sub system index
81 
82  offset : (int) : (optional), default 0 yao wfs index offset
83 
84  Returns:
85  n_ngs : (int) : number of ngs passed to yao
86  n_lgs : (int) : number of lgs passed to yao
87  """
88  #counting nb of lgs and ngs
89  n_ngs=0
90  n_lgs=0
91  if(n_wfs<0):
92  n_wfs = len(wfss)
93  for w in wfss[:n_wfs]:
94  if(w.gsalt>0):
95  n_lgs += 1
96  else:
97  n_ngs += 1
98  n_wfs = n_ngs + n_lgs
99  f=open(file_name, "a+")
100 
101  i = 1
102  for w in wfss[:n_wfs] :
103  f.write("\n\n//WFS" + str(i + offset))
104  f.flush()
105  write_wfs(file_name, w, i + offset, sub_system=sub_system)
106  i += 1
107 
108  f.close()
109  return (n_ngs , n_lgs)
110 
111 
112 
113 def finish_wfs(file_name, n_ngs, n_lgs):
114  """ Finalize wfs section in yao parameter file
115 
116  Args:
117  file_name : (str) : yao parameter file name
118 
119  n_ngs : (int) : number of ngs written to yao parameter file
120 
121  n_lgs : (int) : number of lgs written to yao parameter file
122  """
123  f=open(file_name,"a+")
124  f.write("\n\nnngs = "+str(n_ngs)+";")
125  f.write("\nnlgs = "+str(n_lgs)+";")
126  f.write("\nnwfs = "+str(n_ngs+n_lgs)+";")
127  f.close()
def finish_wfs(file_name, n_ngs, n_lgs)
Finalize wfs section in yao parameter file.
def write_wfs(file_name, wfs, index, *sub_system=1)
Write (append) wfs parameter to file for YAO use for a single wfs.
def init_wfs(file_name)
Initialise wfs entry in yao parameter file.
def write_wfss(file_name, wfss, *n_wfs=-1, sub_system=1, offset=0)
Write (append) wfs parameter to file for YAO use for a wfs list.