2 from shesha.util.writers.common
import dm
3 from shesha.util.writers.common
import wfs
4 from shesha.util.writers.common
import imat
5 from astropy.io
import fits
8 """Return a fits Header Data Unit (HDU) representation of a single WFS
11 sup : (compasSSupervisor) : supervisor
13 wfs_id : (int) : index of the WFS in the supervisor
16 hdu : (ImageHDU) : fits representation of the WFS
18 hdu_name =
"WFS" + str(wfs_id)
19 X,Y = wfs.get_subap_pos_meter(sup, wfs_id)
20 valid_subap = np.array([X,Y],dtype=np.float64)
21 hdu = fits.ImageHDU( valid_subap, name=hdu_name)
22 hdu.header[
"NSSP"] = sup.config.p_wfss[wfs_id].get_nxsub()
23 hdu.header[
"SSPSIZE"] = sup.config.p_wfss[wfs_id].get_subapd()
27 """Return a fits Header Data Unit (HDU) representation of a single DM
30 sup : (compasSSupervisor) : supervisor
32 wfs_id : (int) : index of the DM in the supervisor
35 hdu : (ImageHDU) : fits representation of the DM
37 hdu_name =
"DM" + str(dm_id)
38 X,Y = dm.get_actu_pos_meter(sup, dm_id)
39 valid_subap = np.array([X,Y],dtype=np.float64)
40 hdu = fits.ImageHDU( valid_subap, name=hdu_name)
41 hdu.header[
"NACTU"] = sup.config.p_dms[dm_id].get_nact()
42 hdu.header[
"PITCH"] = sup.config.p_dms[dm_id].get_pitch()
43 hdu.header[
"COUPLING"] = sup.config.p_dms[dm_id].get_coupling()
44 hdu.header[
"ALT"] = sup.config.p_dms[dm_id].get_alt()
48 """Return a fits Header Data Unit (HDU) holding the influence functions of a specific DM
51 sup : (compasSSupervisor) : supervisor
53 wfs_id : (int) : index of the DM in the supervisor
56 influ_index : (int) : (optional) default -1, index of the actuator to get the influence function from. -1 : get all influence functions
59 hdu : (ImageHDU) : hdu holding the DM influence functions
61 hdu_name =
"INFLU_DM" + str(dm_id)
63 influ_fct = sup.config.p_dms[dm_id].get_influ().astype(np.float64)
65 influ_fct = sup.config.p_dms[dm_id].get_influ()[:,:,influ_index].astype(np.float64)
66 hdu = fits.ImageHDU( influ_fct, name=hdu_name)
69 def write_data(file_name, sup, *, wfss_indices=None, dms_indices=None,
70 controller_id=0, influ=0, compose_type="controller"):
71 """ Write data for yao compatibility
73 write into a single fits:
74 * number of valide subapertures
76 * subapertures position (2-dim array x,y) in meters centered
77 * actuator position (2-dim array x,y) in pixels starting from 0
78 * interaction matrix (2*nSubap , nactu)
79 * command matrix (nacy , 2*nSubap)
82 file_name : (str) : data file name
84 sup : (compasSSupervisor) : supervisor
87 wfss_indices : (list[int]) : optional, default all, list of the wfs indices to include
89 dms_indices : (list[int]) : optional, default all, list of the DM indices to include
91 controller_id : (int) : optional, index of the controller passed to yao
93 influ : (int) : optional, actuator index for the influence function
95 compose_type : (str) : optional, possibility to specify split tomography case ("controller" or "splitTomo")
97 print(
"writing data to" + file_name)
102 if(wfss_indices
is None):
103 wfss_indices = np.arange(len(conf.p_wfss))
104 if(dms_indices
is None):
106 for i
in range(len(conf.p_dms)):
107 if( conf.p_dms[i].type !=
"tt"):
108 dms_indices.append(i)
112 for i
in wfss_indices :
113 if(conf.p_wfss[i].get_gsalt() > 0):
117 hdu = fits.PrimaryHDU(np.zeros(1,dtype=np.int32))
118 hdu.header[
"DIAM"] = conf.p_tel.get_diam()
119 hdu.header[
"COBS"] = conf.p_tel.get_cobs()
120 hdu.header[
"NLGS"] = n_lgs
121 hdu.header[
"NNGS"] = len(wfss_indices) - n_lgs
122 hdu.header[
"NDM" ] = len(dms_indices)
123 hdu.header[
"PIXSIZE"] = conf.p_geom.get_pixsize()
129 for i
in wfss_indices:
133 for i
in dms_indices:
137 if(controller_id > -1):
139 interaction_mat=imat.compose_imat(sup, compose_type=compose_type,
140 controller_id=controller_id)
141 hdu_imat=fits.ImageHDU(interaction_mat,name=
"IMAT")
144 hdu_cmat=fits.ImageHDU(sup.rtc.get_command_matrix(controller_id),
147 print(
"\t* number of subaperture per WFS")
148 print(
"\t* subapertures position")
149 print(
"\t* number of actuator per DM")
150 print(
"\t* actuators position")
154 hdul.writeto(file_name, overwrite=1)
def write_data(file_name, sup, *wfss_indices=None, dms_indices=None, controller_id=0, influ=0, compose_type="controller")
Write data for yao compatibility.
def wfs_to_fits_hdu(sup, wfs_id)
Return a fits Header Data Unit (HDU) representation of a single WFS.
def dm_influ_to_fits_hdu(sup, dm_id, *influ_index=-1)
Return a fits Header Data Unit (HDU) holding the influence functions of a specific DM.
def dm_to_fits_hdu(sup, dm_id)
Return a fits Header Data Unit (HDU) representation of a single DM.