-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathyao_wfs.i
2629 lines (2210 loc) · 92.4 KB
/
yao_wfs.i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* yao_wfs.i
*
* Compilation of functions related to Wavefront Sensors
*
* This file is part of the yao package, an adaptive optics simulation tool.
*
* Copyright (c) 2002-2017, Francois Rigaut
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details (to receive a copy of the GNU
* General Public License, write to the Free Software Foundation, Inc., 675
* Mass Ave, Cambridge, MA 02139, USA).
*
*/
func shwfs_init(pupsh,ns,silent=,imat=,clean=)
/* DOCUMENT func shwfs_init(pupsh,ns,silent=,imat=)
pupsh: pupil image. Should be 1/0 for SHWFS. dimension sim._size
ns: WFS # (for multi-wfs systems, if not, put 1)
silent: be silent (except for error messages of course)
imat: will be used for imat computation (will use kernel)
clean: force recomputing everything (in particular rayleight maps)
SEE ALSO: sh_wfs
*/
{
// extern wfs;
if (silent==[]) silent = (sim.verbose==0);
// wfs._initkernels = array(1n,nwfs);
if (is_void(ns)) {ns=1;} // default to wfs#1 for one WFS work.
if (typeof(pupsh) != "float") {error,"pupsh was not float !";}
pupd = sim.pupildiam;
size = sim._size;
nxsub = wfs(ns).shnxsub(0);
subsize = pupd/nxsub;
if (wfs(ns).npixpersub) subsize = wfs(ns).npixpersub;
fracsub = wfs(ns).fracIllum;
sdim = long(2^ceil(log(subsize)/log(2)+wfs(ns).pad_simage));
sdimpow2 = int(log(sdim)/log(2));
// first rotate/translate if needed:
// 20201201: I have concluded that this cause a lot of issues. Because ipupil
// has discontinuities, it is near impossible to rotate it with linear operators
// without changing the values at the edge. So for now (20201201), I am *not*
// rotating the pupil amplitude. This means any anisotropy in the pupil will not
// rotate, i.e. spiders etc. Beware. When fixed, just re-establish the rotation
// by uncommenting all the yao_wfs_rotate_shift() relative to pupsh.
// pupsh = yao_wfs_rotate_shift(pupsh,wfs(ns).rotation,wfs(ns).shift,integer=1);
// wfs(ns)._pupil = &float(pupsh*1);
wfs(ns)._centroidgain = 1.f;
// if (anyof(wfs.svipc>1)) status = quit_wfs_forks();
//====================================================================
// WORK OUT THE NUMBER OF PHOTONS COLLECTED PER SUBAPERTURE AND SAMPLE
//====================================================================
// this is modified to take into account the actual surface area of the
// telescope, rather than the telescope area for a circular telescope with
// no central obscuration
telSurf = sum(pupil)*(tel.diam/sim.pupildiam)^2;
// from the guide star (computed here as used in wfs_check_pixel_size):
if (wfs(ns).gsalt == 0) {
wfs(ns)._nphotons = wfs(ns)._zeropoint*10^(-0.4*wfs(ns).gsmag)*
wfs(ns).optthroughput* // include throughput to WFS
(tel.diam/wfs(ns).shnxsub)^2./telSurf* // for unobstructed subaperture
loop.ittime; // per iteration
} else { // we are dealing with a LGS
wfs(ns)._nphotons = gs.lgsreturnperwatt*cos(dtor*gs.zenithangle)* // detected by WFS
wfs(ns).laserpower* // ... for given power
wfs(ns).optthroughput* // include throughput to WFS
(tel.diam/wfs(ns).shnxsub)^2.*1e4* // for unobstructed subaperture
loop.ittime; // per iteration
}
// see below for # of photons from sky
//=============================================================
// LGS ELONGATION FROM DEFOCUS METHOD (NOT KERNEL CONVOLUTION)
//=============================================================
// existence of lgs_prof_amp and alt have been done in check_parameters()
// Compute the defocus coef. wfs._lgs_defocuses from wfs.lgs_prof_alt:
shwfs_comp_lgs_defocuses,ns;
// compute wfs(ns)._unitdefocus, used in the extended field defocus method:
if (wfs(ns).type=="hartmann") {
xyc = sim._cent;
xyc += wfs(ns).LLTxy*sim.pupildiam/tel.diam;
wfs(ns)._unitdefocus = &float(2*sqrt(3.)*(dist(sim._size,xc=xyc(1),\
yc=xyc(2))/(sim.pupildiam/2.))^2.);
dyn_range_correct = (numberof(*wfs(ns).lgs_prof_amp)>0);
tmp = float(indices(subsize));
wfs(ns)._unittip = &(tmp(,,1)*dyn_range_correct);
wfs(ns)._unittilt = &(tmp(,,2)*dyn_range_correct);
}
//==================================
// COMPUTE ISTART AND JSTART VECTORS
//==================================
// they are vectors containing the start
// indices (X and Y) of the subapertures
is = size/2+1-pupd/2;
if (wfs(ns).npixpersub) {
is = size/2+1-(subsize*nxsub)/2;
}
if (wfs(ns).pupoffset!=[]) {
puppixoffset = long(round(wfs(ns).pupoffset/tel.diam*sim.pupildiam));
} else puppixoffset = [0,0];
nsubs = nxsub*nxsub;
istart = ((indgen(nsubs)-1)%nxsub)*subsize + is + puppixoffset(1);
jstart = ((indgen(nsubs)-1)/nxsub)*subsize + is + puppixoffset(2);
xsub = (((indgen(nsubs)-1)%nxsub)+0.5)*tel.diam/nxsub-tel.diam/2.;
ysub = ((indgen(nsubs)-1)/nxsub+0.5)*tel.diam/nxsub-tel.diam/2.;
//==========================================================
// COMPUTE WHICH SUBAPERTURES ARE ENABLED (FLUX > THRESHOLD)
//==========================================================
fluxPerSub = array(float,nsubs);
for (i=1;i<=nsubs;i++) {
fluxPerSub(i) = sum(pupsh(istart(i):istart(i)+subsize-1,
jstart(i):jstart(i)+subsize-1));
}
fluxPerSub = fluxPerSub/subsize^2.;
// indices of the enabled subapertures: gind
// gind = where(fluxPerSub > fracsub);
// changed 2009oct07: we display *all* subaps for which there is flux
// this is to have a more realistic display (wfs._fimage)
// however, now we have 2 sets of valid subapertures:
// - the one for which we want to compute an image in _shwfs() -> _nsub4disp
// - the really valid ones, for which we will compute the slope information -> _nsub
if (wfs(ns).shmethod==2) {
gind = where(fluxPerSub > 0);
} else {
// shmethod=1 -> geometrical SH.
// for these, it makes no sense to differentiate display and slope/valid
// subapertures. We'll make them the same
gind = where(fluxPerSub > fracsub);
}
// alternatively, the user can supply a number of subaperture, and we'll do
// our best here to match this. There may be no solution, in which case we'll
// exit in error
// wfs.extnsubs should be set to the desired number of valid subapertures
if (wfs(ns).extnsubs) {
step = 1./subsize^2.;
step = step/2.; // for good measure
fracs = 0.;
while (numberof(gind)!=wfs(ns).extnsubs) {
fracs += step;
gind = where(fluxPerSub > fracs);
if (fracs>1.0) error,swrite(format="No solution to reach required wfs(%d).extnsubs\n",ns);
}
write,format="User requested nsub OK: Found wfs.fracIllum=%.3f\n",fracs;
} else if (wfs(ns).extern_validsubs) {
// User-defined validsubs (in that case, the responsibility of having the right number
// of elements, etc, is left to the user):
wfs(ns)._validsubs = wfs(ns).extern_validsubs;
}
// then out of these, we will only compute mesvec for the "valid":
tmp = fluxPerSub; tmp = tmp(gind);
if (!wfs_keep_valid) wfs(ns)._validsubs = &(int(tmp > fracsub));
// 20201104: not sure what wfs_keep_valid would be use for, but leaving in there.
istart = istart(gind);
jstart = jstart(gind);
xsub = xsub(gind);
ysub = ysub(gind);
fluxPerSub = fluxPerSub(gind);
// Let's deal with the shift and rotation:
subsize_m = subsize * tel.diam/sim.pupildiam;
xsub += wfs(ns).shift(1)/subsize*subsize_m;
ysub += wfs(ns).shift(2)/subsize*subsize_m;
xy = transpose([xsub,ysub]);
xyr = mrot(wfs(ns).rotation)(+,)*xy(+,);
xsub = xyr(1,);
ysub = xyr(2,);
// stuff some of wfs structure for WFS "ns":
wfs(ns)._istart = &(int(istart-1)); // -1n 'cause C is 0 based
wfs(ns)._jstart = &(int(jstart-1));
wfs(ns)._x = &(xsub);
wfs(ns)._y = &(ysub);
wfs(ns)._nsub4disp = int(numberof(gind));
wfs(ns)._nsub = int(sum(*wfs(ns)._validsubs));
// compute other setup variables for _shwfs:
//================================
// SUBAPERTURE SIZE AND PIXEL SIZE
//================================
wfs_check_pixel_size,ns,sdim,rebinFactor,actualPixelSize,\
printheader=0,silent=1;
sdimpow2 = int(log(sdim)/log(2));
// 2004mar22: added a guard pixel for each subaperture for the display
// 2009oct06: removed it, in the process of implementing the optical
// coupling between subapertures
// extended field of view stuff, work out npb:
// we want to pad wfs.npixels by a integer number of pixel on each side
// to get as close as possible to the requested extfield:
//~ if (!wfs(ns)._npixels) wfs(ns)._npixels = wfs(ns).npixels;
tmp = (wfs(ns).extfield-wfs(ns).npixels*wfs(ns).pixsize)/wfs(ns).pixsize;
wfs(ns)._npb = clip(2*lround(tmp/2.),0,); // pixel to add as "b"order for extended fov, binned pixels
wfs(ns)._npixels = wfs(ns).npixels+wfs(ns)._npb; // [binned pixels, extended image]
wfs(ns)._nx = wfs(ns)._npixels*rebinFactor; // [small pixels]
// note that nx can actually be smaller than sdim, as we are xfering into the
// ximage and the xfer is bound checked.
wfs(ns).extfield = wfs(ns)._npixels*wfs(ns).pixsize;
// now let's find if there are better dimension for the fft:
if ((wfs(ns)._npb>0)&&(wfs(ns).shmethod==2)&&(optimize_nx)) {
// determine prime factors for _nx and above. take first integer which
// prime factors are all <= 7:
_nx = wfs(ns)._nx-1;
do pf = prime_factors(++_nx); while (anyof(pf>7));
wfs(ns)._nx4fft = _nx;
if (sim.verbose) {
write,format="FFTW: Best dim for ximage = %d, up from %d\n", \
wfs(ns)._nx4fft,wfs(ns)._nx;
}
} else wfs(ns)._nx4fft = wfs(ns)._nx;
// call optimizer for this size FFTW:
if (wfs(ns).shmethod==2) {
_init_fftw_plan,int(wfs(ns)._nx4fft);
if (_export_wisdom(expand_path(fftw_wisdom_file))) \
write,format=" Warning: Can't export FFTW wisdom to %s\n", \
expand_path(fftw_wisdom_file);
}
// now compute _shwfs C routine internal array size:
// for bimage (trimmed and rebinned simage):
wfs(ns)._rebinfactor = rebinFactor;
nbigpixels = long(wfs(ns)._nx/rebinFactor);
// check eveness of nbigpixels is same as wfs.npixels:
if (even(wfs(ns)._npixels)!=even(nbigpixels)) nbigpixels--;
// subsize of sdim that we will use in bimage:
rdim = long(wfs(ns)._nx);
xy = long(indices(rdim)-1.);
tmp = xy(,,1)/rebinFactor + xy(,,2)/rebinFactor*nbigpixels;
// what's the rebinned pixels size (in small fft pixels)?
// answer -> rebinFactor
// how many integer big pixels can we fit in sdim (which ought to be
// a power of 2)?
// answer = long ( sdim/rebinFactor )
// the number of rebinned pixels in the final subaperture is wfs.npixels
// (1) if wfs.npixels is even, the spot has to be in the center of the subap
// image
// (2) if wfs.npixel is odd, the spot has to be in the center of the center
// rebinned pixel.
// remember the spot is shifted by one half fft pixels left and down,
// so it can fall in between original pixels hence in between rebinned
// pixels. thus by playing here we can only accomodate:
// (1) wfs.npixel even, both rebinfactor odd and even
// (2) wfs.npixel odd, only rebinfactor even.
// (3) with wfs.npixel odd and rebinfactor odd, the spot would have to
// be centered on the central rebinned pixel, which has and odd number
// of fft pixels, thus would have to be centered on a fft pixel, which is
// not originally the case. will have to modify tiltsh for that.
// for now let's take care of how to dimension binindices for all those
// cases. after the fft, and 1/2 pixel shift, the spot is centered on
// the 2^n x 2^n fft array.
binindices = array(-1l,[2,wfs(ns)._nx4fft,wfs(ns)._nx4fft]);
binindices(1:rdim,1:rdim) = tmp;
ss = ceil((wfs(ns)._nx-rdim)/2.);
//~ binindices = roll(binindices,[ss,ss]);
//~ binindices = int(eclat(binindices));
// stuff some more of wfs structure for WFS "ns":
wfs(ns)._binindices = &(int(binindices));
// checked, it seems to work.
wfs(ns)._binxy = nbigpixels;
if (stop_at==43) error;
// centroid reference vector, after final extraction of subimage:
centroidw = indgen(wfs(ns)._npixels)-1.-(wfs(ns)._npixels/2.-0.5);
// we might as well express it in arcsec:
centroidw = float(centroidw*actualPixelSize);
wfs(ns)._centroidw = ¢roidw;
//~ write,format="nbigpixels = %d, wfs._npixels = %d, wfs._npb=%d\n",\
//~ nbigpixels,wfs(ns)._npixels,wfs(ns)._npb;
// just for print out to screen if needed:
wfs_check_pixel_size,ns,sdim,rebinFactor,actualPixelSize,\
printheader=(ns==1),silent=silent;
wfs(ns)._sdim = sdim;
if (wfs(ns).spotpitch==0) wfs(ns).spotpitch = wfs(ns)._npixels;
imistart = (istart-min(istart))/subsize*(wfs(ns).spotpitch);
imjstart = (jstart-min(jstart))/subsize*(wfs(ns).spotpitch);
wfs(ns)._imistart = &(int(imistart));
wfs(ns)._imjstart = &(int(imjstart));
wfs(ns)._imistart2 = &(int(imistart));
wfs(ns)._imjstart2 = &(int(imjstart));
//~ fimdim = long(nxsub*wfs(ns)._npixels+(nbigpixels-wfs(ns)._npixels)+wfs(ns)._npb);
fimdim = long((nxsub-1)*wfs(ns).spotpitch+wfs(ns)._npixels);
wfs(ns)._fimage = &(array(float,[2,fimdim,fimdim]));
wfs(ns)._dispimage = &(array(float,[2,fimdim,fimdim]));
wfs(ns)._fimnx = int(fimdim);
wfs(ns)._fimny = int(fimdim);
if (stop_at==44) error;
// This is the tilt to add to the input phase so that
// the individual subaperture images fall in between
// the pixels of the quadcell
xy = indices(sim._size);
wfs(ns)._tiltsh = &(float((-64.)*0.098174773*(xy(,,1)+xy(,,2))* \
0.5/sdim*wfs(ns).lambda/(2*pi)*(wfs(ns).shmethod == 2)));
// This tilt array is intended to bring the spot back inbetween 4 pixels
// instead of centered on dim/2+1 as a result of the regular FFT.
// In other words, added to the subaperture phase, it will shift the
// image 1/2 FFT pixel left and down.
// this is an achromatic factor of course that just depends on the
// dimension of the array.
// the lambda/2pi factor is thus to compensate the x by 2pi/lambda
// in _shwfs, making tiltsh achromatic.
// If the number of (rebinned) pixels (wfs.npixels) is odd,
// and if the rebinFactor (number of small FFT pixels in a rebinned one)
// is also odd, then the spot should be centered on a small FFT pixel,
// not in between 4 of them.
if (odd(rebinFactor) && odd(wfs(ns).npixels) && (wfs(ns).shmethod==2)) {
*wfs(ns)._tiltsh *= 0;
}
//=====================================
// CONVOLUTION KERNELS INITIALIZATIONS:
//=====================================
// if there is no explicit request for an extended kernel
// and we are not using LGS (or the depth = 0) then we disable
// the kernel convolution is _shwfs to gain time (and accuracy)
// this behavior is overriden in MultWfsIntMat anyway for the purpose
// of computing the iMat with the correct kernel (to simulate for
// the extended "seeing" spot
wfs(ns)._kernelconv = 1n;
if ((wfs(ns).kernel==0) && (wfs(ns)._gsdepth==0)) wfs(ns)._kernelconv = 0n;
if (wfs(ns).shmethod==1) wfs(ns)._kernelconv = 0n;
//=======================================================================
// INITIALIZE COMMON KERNEL TO CONVOLVE _SHWFS IMAGE FOR IMAT CALIBRATION
//=======================================================================
shwfs_init_common_kernel,ns,imat=imat;
//==============================
// UPLINK SEEING INITIALIZATIONS
//==============================
if (wfs(ns).LLT_uplink_turb) comp_turb_lgs_kernel,ns,init=1;
//=============================================================================
// INITIALIZE WFS IMAGE KERNELS: SUBAPERTURE DEPENDENT. USED FOR LGS ELONGATION
//=============================================================================
// if kernelconv is 0, then the _shwfs routine does not use wfs._kernels:
shwfs_init_lgs_kernels,ns;
//=================================================
// INITIALIZE RAYLEIGH STUFF: SUBAPERTURE DEPENDENT
//=================================================
if (wfs(ns).rayleighflag) {
shwfs_init_rayleigh,ns;
// remove subapertures where the Rayleigh is too high relative to the sodium flux
if (wfs(ns).rayleighthresh) {
ratio = *wfs(ns)._rayleighflux/(*wfs(ns)._sodiumflux+1e-6); // avoid division by 0
*wfs(ns)._validsubs *= (ratio < wfs(ns).rayleighthresh);
wfs(ns)._nsub = int(sum(*wfs(ns)._validsubs));
}
} else wfs(ns)._rayleigh = &([0.0f]); // to avoid type conv. error in _shwfs
//================================
// FIELD STOP / AMPLITUDE MASK
//================================
if (sim.debug>1) \
write,format="Dimension for optional amplitude mask: %d\n",wfs(ns)._nx;
// reads out the amplitude mask for the subaperture:
if (wfs(ns).fsname) {
// read the amplitude image
tmp = yao_fitsread(YAO_SAVEPATH+wfs(ns).fsname);
// check that dims are OK:
if (anyof(dimsof(tmp)!=[2,wfs(ns)._nx,wfs(ns)._nx])) {
error,swrite(format="Bad dimensions for %s. Should be %d, found %d\n",
wfs(ns).fsname,wfs(ns)._nx,dimsof(tmp)(2));
}
// check of mask is centered (can be a common cause of mistake):
f1x = sum(tmp(1:wfs(ns)._nx/2,));
f2x = sum(tmp(wfs(ns)._nx/2+1:,));
f1y = sum(tmp(,1:wfs(ns)._nx/2));
f2y = sum(tmp(,wfs(ns)._nx/2+1:));
if ((f1x!=f2x)||(f1y!=f2y)) {
write,format="%s\n","\nWARNING!";
write,format="%s\n","The SHWFS amplitude mask is not centered. This can create";
write,format="%s\n","a bias in the slope calculation. A centered mask should be";
write,format="%s\n","centered on the 4 central pixels of the mask, not on";
write,format="%s\n","the (0,0) of the FFT transform. If you did not do that on ";
write,format="%s\n\n","purpose, you should correct your mask.";
}
// modify as required:
tmp4fft = array(0.0f,[2,wfs(ns)._nx4fft,wfs(ns)._nx4fft]);
tmp4fft(1:wfs(ns)._nx,1:wfs(ns)._nx) = tmp;
wfs(ns)._submask = &(float(tmp4fft));
wfs(ns)._domask = 1l;
} else if (strlen(wfs(ns).fstop)>0) {
// make the field stop with wfs.fstop, wfs.fssize and wfs.fsoffset
make_fieldstop,ns;
wfs(ns)._domask = 1l;
} else wfs(ns)._domask = 0l;
// compute # of photons from the sky as above for guide star.
// skymag is per arcsec, so we have to convert for
// the subaperture size computed in wfs_check_pixel_size.;
// changed on 2009oct12: now _skynphotons is normalized
// *per rebinned pixel*.
subsize = sim.pupildiam/wfs(ns).shnxsub(0);
if (wfs(ns).npixpersub) subsize = wfs(ns).npixpersub;
// subsize in meters:
subsize_m = subsize * tel.diam/sim.pupildiam;
wfs(ns)._skynphotons = wfs(ns)._zeropoint*10^(-0.4*wfs(ns).skymag)* // #photons/tel/sec/arcsec^2
subsize_m^2./telSurf* // -> per full subaperture
loop.ittime* // -> per iteration
wfs(ns).optthroughput* // -> include throughput to WFS
wfs(ns).pixsize^2.; // -> per rebinned pixel
if ( wfs(ns).skymag == 0) { wfs(ns)._skynphotons = 0.; } // if skymag not set
if (sim.verbose == 2) {
write,format="wfs(%d)._skynphotons = %f\n\n",ns,wfs(ns)._skynphotons;
}
// for guide star, total "useful" signal per subap.
wfs(ns)._fluxpersub = &(float(fluxPerSub*wfs(ns)._nphotons));
if (sim.verbose > 0) {
gstype = ( (wfs(ns).gsalt>0)?"LGS":"NGS" );
tmp = fluxPerSub(where(*wfs(ns)._validsubs))*wfs(ns)._nphotons;
if (min(tmp)>10) fmt="%.0f"; else fmt="%.1f";
write,format="%s#%d flux varies between "+fmt+" and "+fmt+
" photon/subap/it\n",gstype,ns,min(tmp),max(tmp);
}
// for rayleigh, if any:
if (wfs(ns).rayleighflag) {
wfs(ns)._raylfluxpersub = &(*wfs(ns)._fluxpersub* \
float(*wfs(ns)._rayleighflux / *wfs(ns)._sodiumflux));
} else wfs(ns)._raylfluxpersub = &float(*wfs(ns)._fluxpersub*0.0f+1.0f);
// for sky (see above, in photon/subap/it/rebinned pixel)
wfs(ns)._skyfluxpersub = &(float(fluxPerSub*wfs(ns)._skynphotons));
// changed 2009oct13: now compute bias and flat for entire _fimage:
wfs(ns)._bias = &(wfs(ns).biasrmserror *
gaussdev([2,wfs(ns)._fimnx,wfs(ns)._fimny]));
wfs(ns)._flat = &(1.0f + wfs(ns).flatrmserror *
gaussdev([2,wfs(ns)._fimnx,wfs(ns)._fimny]));
//same here, take background calib image for entire _fimage
wfs(ns)._bckgrdcalib = &(array(float,[2,wfs(ns)._fimnx,wfs(ns)._fimny]));
if (sim.verbose == 2) {
write,format="Dark current wfs#%d / iter / pixel=%f\n",ns,
float(wfs(ns).darkcurrent*loop.ittime);
}
// CALIBRATE BACKGROUND IMAGES (have to run sh_wfs for that):
bckgrdsub = wfs(ns)._bckgrdsub;
wfs(ns)._bckgrdsub = 0; // it doesn't matter
wfs(ns)._bckgrdinit = 1;
// call sh_wfs for calibration of the background
// remove the noise when calculating the origins
noiseOrig = wfs.noise;
wfs.noise *= 0;
// first sync if needed (svipc)
if (wfs(ns).svipc>1) status = sync_wfs_forks();
for (i=1;i<=wfs(ns).nintegcycles;i++) sh_wfs,pupsh,pupsh*0.0f,ns;
wfs.noise=noiseOrig;
wfs(ns)._bckgrdinit = 0;
wfs(ns)._bckgrdsub = bckgrdsub;
// the following fixes a bug we have since 4.7.1:
// wfs(ns)._bckgrdcalib = &(*wfs(ns)._fimage);
// here we need to re-sync to restore bckgrd properties to forks:
if (wfs(ns).svipc>1) status = sync_wfs_forks();
if (show_background) {
fma;
plsys,1;
pli,*wfs(ns)._bckgrdcalib;
pltitle,swrite(format="Calibrated background for WFS#%d",ns);
hitReturn;
}
// DISPLAY OF WFS CONFIG (put that somewhere else so it can be
// called independently)
if ( (sim.debug>=1) && (!silent) && (wfs(ns).shmethod==2) ){
sh_wfs,pupsh,pupsh*0.0f,ns;
fma;
plsys,2;
pli,*wfs(ns)._fimage;
// limits;
cn = 80;
for (i=1;i<=wfs(ns)._nsub4disp;i++) {
if ((*wfs(ns)._validsubs)(i)==0) continue;
x1 = (*wfs(ns)._imistart2)(i)+wfs(ns)._npb/2;
y1 = (*wfs(ns)._imjstart2)(i)+wfs(ns)._npb/2;
l1 = wfs(ns).npixels;
plg,_(y1,y1,y1+l1,y1+l1,y1),_(x1,x1+l1,x1+l1,x1,x1),color=[cn,cn,cn],marks=0;
plt,swrite(format="%d",i),x1,y1,tosys=1,color=[cn,cn,cn],height=lround(pltitle_height*0.75);
}
// display the full extent of this example subap FoV
// to show the user how it overlaps with neightbors
// first let's highlight the subaperture we're talking about here:
i = where(*wfs(ns)._validsubs)(1);
x1 = (*wfs(ns)._imistart2)(i);
y1 = (*wfs(ns)._imjstart2)(i);
l1 = wfs(ns)._npixels;
plg,_(y1,y1,y1+l1,y1+l1,y1),_(x1,x1+l1,x1+l1,x1,x1),color="green",width=3;
// then display the whole subaperture field of view
x1 = (*wfs(ns)._imistart)(i);
y1 = (*wfs(ns)._imjstart)(i);
l1 = wfs(ns)._binxy; //*wfs(ns)._rebinfactor;
plg,_(y1,y1,y1+l1,y1+l1,y1),_(x1,x1+l1,x1+l1,x1,x1),color="red";
// field stop:
if (*wfs(ns)._submask!=[]) {
// fs = roll(*wfs(ns)._submask);
fs = *wfs(ns)._submask;
xyc = indices(dimsof(fs));
xyc = (xyc-1.)/(dimsof(fs)(2)-1)*(wfs(ns)._binxy)+0.;
xyc(,,1) += x1+0.5;
xyc(,,2) += y1+0.5;
plc,fs,xyc(,,2),xyc(,,1),levs=[0.001],color="magenta",width=3;
}
require,"plvp.i"; // for plmargin
plmargin;
xytitles_vp,"pixels","pixels",[0.015,0.015];
pltitle_vp,escapechar(swrite(format="wfs(%d)._fimage",ns)),0.005;
limits;
plsys,0;
ybase = 0.90;
deltay = 0.03;
deltayt = 0.005;
x1 = 0.04;
x2 = x1 + 0.03;
x3 = x2 + 0.01;
plg,_(ybase,ybase),_(x1,x2),color=[cn,cn,cn],width=3;
plt,"Valid subapertures",x3,ybase-deltayt,tosys=0
ybase -= deltay;
plg,_(ybase,ybase),_(x1,x2),color="green",width=3;
plt,"Highlighted subap.",x3,ybase-deltayt,tosys=0
ybase -= deltay;
plg,_(ybase,ybase),_(x1,x2),color="red",width=3;
plt,"Highlighted subap. total FoV (overlap)",x3,ybase-deltayt,tosys=0
ybase -= deltay;
if (*wfs(ns)._submask!=[]) {
plg,_(ybase,ybase),_(x1,x2),color="magenta",width=3;
plt,"Highlighted subap. field stop",x3,ybase-deltayt,tosys=0;
} else {
plt,"NO field stop defined",x3,ybase-deltayt,tosys=0
}
plsys,2;
redraw;
if (sim.debug>1) {
write,"Hit return to continue...";
hitReturn;
}
}
// and let's just re-sync for good measure:
if (anyof(wfs.svipc>1)) status = sync_wfs_forks();
return 1;
}
//----------------------------------------------------
func shwfs_init_common_kernel(ns,imat=)
{
extern wfs;
if (is_set(imat)) { // we are in iMat computation. we want
// the kernel FWHM = seeing + requested kernel fwhm (quadratically)
// factor 1.5 to crudely compensate for the fact that the spot is
// tilt compensated at the focus of the lenslet
dr0 = atm.dr0at05mic*(0.5/wfs(ns).lambda)^1.2/cos(gs.zenithangle*dtor)^0.6;
fwhmseeing = wfs(ns).lambda/
(tel.diam/sqrt(wfs(ns).shnxsub^2.+(dr0*wfs(ns).shcalibseeing)^2.))/4.848;
kernelfwhm = sqrt(fwhmseeing^2.+wfs(ns).kernel^2.);
} else {
// we are in regular aoloop. no further convolution to account for seeing.
// However, we want to avoid dividing by zero in makegaussian,
// so we floor fwhm:
kernelfwhm = clip(wfs(ns).kernel,1e-8,);
}
if ( (sim.verbose >= 1) && (!is_set(silent)) ) {
write,format="Kernel FWHM for the iMat calibration = %f\n",kernelfwhm;
}
quantumPixelSize = wfs(ns).lambda/(tel.diam/sim.pupildiam)/4.848/wfs(ns)._sdim;
tmp = eclat(makegaussian(wfs(ns)._nx4fft,kernelfwhm/quantumPixelSize,
xc=wfs(ns)._nx4fft/2.+1,yc=wfs(ns)._nx4fft/2.+1));
tmp(1,1) = 1.; // this insures that even with fwhm=0, the kernel is a dirac
tmp = tmp/sum(tmp);
wfs(ns)._kernel = &(float(tmp));
wfs(ns)._nkernels = 1;
}
//----------------------------------------------------
func shwfs_init_lgs_kernels(ns)
/* DOCUMENT shwfs_init_lgs_kernels(ns)
* COMPUTE WFS IMAGE KERNELS: SUBAPERTURE DEPENDENT.
* USED FOR LGS ELONGATION
*/
{
extern wfs;
quantumPixelSize = wfs(ns).lambda/(tel.diam/sim.pupildiam)/4.848/wfs(ns)._sdim;
// coordinate array in arcsec:
xy = (indices(wfs(ns)._nx4fft)-wfs(ns)._nx4fft/2.-1)*quantumPixelSize;
if (sim.verbose >= 1) write,format="%s\n","Pre-computing Kernels for the SH WFS";
kall = [];
gui_progressbar_frac,0.;
gui_progressbar_text,swrite(format="Precomputing subaperture kernels, WFS#%d",ns);
for (l=1; l<=wfs(ns)._nsub4disp; l++) {
// for each subaperture, we have to find the elongation and the angle.
xsub = (*wfs(ns)._x)(l); ysub = (*wfs(ns)._y)(l);
xllt = wfs(ns).LLTxy(1); yllt = wfs(ns).LLTxy(2);
d = sqrt((xsub-xllt)^2. +(ysub-yllt)^2.);
if (d == 0) {
elong = ang = 0.;
} else {
elong = atan((wfs(ns)._gsalt+wfs(ns)._gsdepth)/d)-atan(wfs(ns)._gsalt/d);
elong /= 4.848e-6; // now in arcsec
ang = atan(ysub-yllt,xsub-xllt); // fixed 2004aug02
}
angp90 = ang+pi/2.;
expo = 4.;
alpha = elong/(2.*log(2)^(1/expo));
beta = 2*quantumPixelSize/(2.*log(2)^(1/expo));
alpha = clip(alpha,0.5*quantumPixelSize,);
beta = clip(beta,0.5*quantumPixelSize,alpha);
tmp = exp(-((cos(ang)*xy(,,1)+sin(ang)*xy(,,2))/alpha)^expo);
tmp *= exp(-((cos(angp90)*xy(,,1)+sin(angp90)*xy(,,2))/beta)^expo);
tmp = tmp/sum(tmp);
if (kall==[]) {
kall = array(0.0f,[2,numberof(tmp),wfs(ns)._nsub4disp]);
}
kall(,l) = float((eclat(tmp))(*));
if (wfs(ns)._gsalt==0) {
// then we are dealing with a NGS, not subaperture dependent:
kall = array(kall(,1),wfs(ns)._nsub4disp);
if (sim.debug) write,"Dealing with NGS, no subap dependent elongation";
break;
}
s2 = tel.diam/wfs(ns).shnxsub*0.9/2.;
gui_progressbar_frac,float(l)/wfs(ns)._nsub4disp;
}
clean_progressbar;
kall = kall(*);
wfs(ns)._kernels = &(float(kall));
wfs(ns)._kerfftr = &(float(kall*0.0f));
wfs(ns)._kerffti = &(float(kall*0.0f));
kall = [];
wfs(ns)._initkernels = 1n;
}
//----------------------------------------------------
func shwfs_init_rayleigh(ns)
{
extern wfs;
if (sim.verbose > 0) {write,format="%s\n","Pre-computing Rayleigh for the SH WFS";}
rayleighflux = array(0.0f,wfs(ns)._nsub4disp);
sodiumflux = array(1.0f,wfs(ns)._nsub4disp);
quantumPixelSize = wfs(ns).lambda/(tel.diam/sim.pupildiam)/4.848/wfs(ns)._sdim;
// coordinate array in arcsec
xy = (indices(wfs(ns)._nx4fft)-wfs(ns)._nx4fft/2.-1)*quantumPixelSize;
kall = [];
rayfname = parprefix+"-rayleigh-wfs"+swrite(format="%d",ns)+"-zen"+
swrite(format="%d",long(gs.zenithangle))+".fits";
isthere = fileExist(YAO_SAVEPATH+rayfname);
fov = quantumPixelSize*wfs(ns)._nx4fft;
aspp = quantumPixelSize;
kall = [];
if ( (isthere) && (!clean) ) {
kall = yao_fitsread(YAO_SAVEPATH+rayfname)*1e6;
rayleighflux = yao_fitsread(YAO_SAVEPATH+rayfname,hdu=1);
sodiumflux = yao_fitsread(YAO_SAVEPATH+rayfname,hdu=2);
} else {
for (l=1; l<=wfs(ns)._nsub4disp; l++) {
xsub = (*wfs(ns)._x)(l); ysub = (*wfs(ns)._y)(l);
// note xsub, ysub are switched on purpose!
tmp = mcao_rayleigh(ns,ysub,xsub,fov,aspp,gs.zenithangle);
rayleighflux(l) = sum(tmp(,,1));
sodiumflux(l) = sum(tmp(,,2));
tmp = transpose(tmp(,,1));
// the switch of xsub <-> ysub and transpose are to accomodate the
// C vs yorick 0 vs 1 start array index.
if (kall==[]) {
kall = array(0.0f,[2,numberof(tmp),wfs(ns)._nsub4disp]);
}
kall(,l) = float((eclat(tmp))(*));
}
yao_fitswrite,YAO_SAVEPATH+rayfname,kall;
yao_fitswrite,YAO_SAVEPATH+rayfname,rayleighflux,append=1,exttype="image";
yao_fitswrite,YAO_SAVEPATH+rayfname,sodiumflux,append=1,exttype="image";
}
if (sim.verbose > 0) {
write,"From Rayleigh calculations:";
write,format="Rayleigh / Sodium ratio in worse/best subapertures: %f, %f\n",
max(rayleighflux/sodiumflux),min(rayleighflux/sodiumflux);
write,format="Rayleigh flux varies between %f and %f /cm2/looptime\n",
min(rayleighflux),max(rayleighflux);
write,format="Sodium flux varies between %f and %f /cm2/looptime\n",
min(sodiumflux),max(sodiumflux);
}
kall = kall(*);
wfs(ns)._rayleigh = &(float(kall));
wfs(ns)._rayleighflux = &float(rayleighflux);
wfs(ns)._sodiumflux = &float(sodiumflux);
kall = [];
}
func subimage_disp(image_cube,ref_image){
/* DOCUMENT subimage_disp(image_cube,ref_image)
Finds the displacement of the images in the image cube relative to the reference image. Used to implement the correlation algorithm instead of the centroid in a Shack-Hartmann WFS.
SEE ALSO:
*/
dims = (dimsof(image_cube));
npix = dims(2);
nsub = dims(4);
fft_ref_image=conj(fft(ref_image,1));
fft_ref_image(1,1)=0. ;// remove the DC term so that the maximum correlation is DC independent (it doesn't affect the slope estimates which are already background independent).
fft_image_cube = fft(image_cube,[1,1,0]);
results = array(float,2*nsub);
for (n1=1;n1<=nsub;n1++){
ccft = fft_ref_image*fft_image_cube(,,n1);
cc = float(fft(ccft,-1));
maxloc2 = (where2(cc == max(cc)))(:,1);
xloc = maxloc2(1);
yloc = maxloc2(2);
xloc = xloc % npix;
yloc = yloc % npix;
// find the maximum using a quadratic fit
cc0 = cc(xloc,yloc);
ccm1x = cc(xloc-1,yloc);
ccp1x = cc(xloc+1,yloc);
ccm1y = cc(xloc,yloc-1);
ccp1y = cc(xloc,yloc+1);
delx = -0.5*(ccm1x-ccp1x)/(ccm1x+ccp1x-2.0*cc0+1e-6);
dely = -0.5*(ccm1y-ccp1y)/(ccm1y+ccp1y-2.0*cc0+1e-6);
estx = xloc-1-delx;
esty = yloc-1-dely;
if (estx > npix - estx){estx = estx - npix;}
if (esty > npix - esty){esty = esty - npix;}
results(n1) = estx;
results(n1+nsub) = esty;
}
return results;
}
//----------------------------------------------------
func wfs_check_pixel_size(ns,&sdim,&rebinFactor,&actualPixelSize,printheader=,silent=)
/* DOCUMENT wfs_check_pixel_size(ns,&sdim,&rebinFactor,&actualPixelSize,printheader=,silent=)
Finds the pixel size for the requested WFS configuration.
There are constraints:
- First, the pixel size cannot be arbitrary.
It is defined by lambda_wfs/pixel_size_in_pupil_space/sdim.
- Second, the max subaperture size is lambda_wfs/pixel_size_in_pupil_space
I could have preserved wfs.npixels as a strong constraint, but it lead to
complicated algorithms. Instead, I am finding the closest pixel size to
wfs.pixsize and then derive the number of pixel and subaperture size.
In addition, I only allow an even number of pixels in the subaperture
(otherwise I have to check many more things, as for instance an odd
number of pixels in the subaperture combined with a odd rebinFactor
cause problems. < now solved (2009oct07)
This routine fills and returns binindices and centroidw (now located in
shwfs_init, 2009oct07)
SEE ALSO: sh_wfs
*/
{
extern wfs;
//~ if (wfs(ns).shmethod==1) return;
pupd = sim.pupildiam;
nxsub = wfs(ns).shnxsub(0);
subsize = pupd/nxsub;
if (wfs(ns).npixpersub) subsize = wfs(ns).npixpersub;
// sdim is the dimension of "simage" in _shwfs(),
// i.e. if 2^l is the smallest array size that can contains the subaperture
// sdim is 2^(l+1) unless wfs(ns).pad_simage is set
sdim = long(2^ceil(log(subsize)/log(2)+wfs(ns).pad_simage));
err = 0;
desiredPixelSize = wfs(ns).pixsize;
desiredNpixels = wfs(ns).npixels;
quantumPixelSize = wfs(ns).lambda/(tel.diam/sim.pupildiam)/4.848/sdim;
rebinFactor = long(round(desiredPixelSize/quantumPixelSize));
if ( rebinFactor == 0 ) {rebinFactor = 1l;}
actualPixelSize = rebinFactor*quantumPixelSize;
wfs(ns).pixsize = actualPixelSize;
while ( (rebinFactor*wfs(ns).npixels) > sdim ) {
wfs(ns).npixels -= 2;
err = 1;
}
if (!is_set(silent)) {
f = open(YAO_SAVEPATH+parprefix+".res","a+");
if (is_set(printheader)) {
write,"WFS# | Pixel sizes | Subaperture size | Numb of pixels | #photons";
write," | Desired Quantum Actual | Max Actual Extd | Desired Actual | /sub/iter";
write,f,"\nWFS# | Pixel sizes | Subaperture size | Numb of pixels | #photons";
write,f," | Desired Quantum Actual | Max Actual Extd | Desired Actual | /sub/iter";
}
npext = max([wfs(ns).npixels,wfs(ns)._npixels]);
write,format="%2d %.4f %.4f %.4f %4.2f %4.2f %4.2f %2dx%2d %2dx%2d %.1f\n",
ns,wfs(ns)._origpixsize,quantumPixelSize,actualPixelSize,quantumPixelSize*sdim,
actualPixelSize*wfs(ns).npixels,actualPixelSize*npext,wfs(ns)._orignpixels,
wfs(ns)._orignpixels,wfs(ns).npixels,wfs(ns).npixels,wfs(ns)._nphotons;
write,f,format="%2d %.4f %.4f %.4f %4.2f %4.2f %4.2f %2dx%2d %2dx%2d %.1f\n",
ns,wfs(ns)._origpixsize,quantumPixelSize,actualPixelSize,quantumPixelSize*sdim,
actualPixelSize*wfs(ns).npixels,actualPixelSize*npext,wfs(ns)._orignpixels,
wfs(ns)._orignpixels,wfs(ns).npixels,wfs(ns).npixels,wfs(ns)._nphotons;
close,f;
}
// if (err == 1) {
// write,format=" WARNING: #pixel/subaperture reduced to %d\n",wfs(ns).npixels;
// }
if (wfs(ns).npixels == 0) {
write,format="\nWFS#%2d: The desired pixel size is too large.\n",ns;
write," I cannot even fit 2x2 pixels.";
write," Reduce pixel size in parfile or use a larger sim.pupildiam.\n";
exit;
}
// write,format=" Final config: %dx%d pixels, pixsize = %f\","+
// " updated in RAM but not in parfile.\n",
// wfs(ns).npixels,wfs(ns).npixels,wfs(ns).pixsize;
return err;
}
//----------------------------------------------------
func sh_wfs(pupsh,phase,ns)
/* DOCUMENT func sh_wfs(pupsh,phase,ns)
pupsh: pupil (dimension sim._size, 0 or 1). Must be of type "float"
phase: phase. same dim as pupil. Must be of type "float"
ns: WFS# (for multi WFS systems, default to 1)
SEE ALSO: shwfs_init
*/
{
if (is_void(ns)) {ns=1;} // default to wfs#1 for one WFS work.
// bail out if bad type (otherwise error in C function call)
if (typeof(pupsh) != "float") {error,"pupsh was not float !";}
if (typeof(phase) != "float") {error,"Phase was not float !";}
spha = phase(_n1:_n2,_n1:_n2)*pupsh(_n1:_n2,_n1:_n2);
spha = (spha-min(spha))*pupsh(_n1:_n2,_n1:_n2);
wfs(ns)._phase = &spha;
// shorthand
pupd = sim.pupildiam;
size = sim._size;
nxsub = wfs(ns).shnxsub(0);
subsize = int(pupd/nxsub);
if (wfs(ns).npixpersub) subsize = wfs(ns).npixpersub;
// first rotate/translate if needed:
// pupsh = yao_wfs_rotate_shift(pupsh,wfs(ns).rotation,wfs(ns).shift,integer=1);
phase = yao_wfs_rotate_shift(phase,wfs(ns).rotation,wfs(ns).shift);
// The phase is in microns. this scaling factor restore it in radian
// at the wfs lambda
phasescale = float(2*pi/wfs(ns).lambda); // wfs.lambda in microns
// fast method (geometrical SHWFS)
if (wfs(ns).shmethod == 1) {
toarcsec = float(wfs(ns).lambda/2.0/pi/(tel.diam/sim.pupildiam)/4.848);
// define mesvec (alloc space for C function)
current_mes = array(float,2*wfs(ns)._nsub);
err = _shwfs_simple(pupsh, phase, phasescale, *wfs(ns)._tiltsh,
int(size), int(size),
*wfs(ns)._istart, *wfs(ns)._jstart, int(subsize),
int(subsize), wfs(ns)._nsub, toarcsec, current_mes);