-
Notifications
You must be signed in to change notification settings - Fork 0
/
ggly6.py
1221 lines (1014 loc) · 60.7 KB
/
ggly6.py
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
"""
-----------------------------
Functions to run GGL for Y6KP
-----------------------------
"""
import os
import sys
import numpy as np
import gc
from mpi4py import MPI
from astropy.io import fits
class GGL(object):
def __init__(self, input_dir=None):
" load the parameters/settings file "
if input_dir is not None:
if os.path.exists(input_dir):
sys.path.append(input_dir)
else:
errmsg = '!!!Error: The input directory %s does not exist'%input_dir
raise Exception(errmsg)
else:
errmsg = '!!!Error: Please provide the path to the input directory'
raise Exception(errmsg)
import params as par
self.par = par
" import the setup class "
import setup
self.ggl_setup = setup.GGL_setup(input_dir=input_dir)
return
def setup_run(self, source_cat=None, path=None, lens_file=None, source_file=None, source_file_bfd=None, response=None, randoms_file=None,
lens_bin=None, source_bin=None,
zl_lims=None, zs_lims=None):
"""
Setup the parameters to run code by reading files
"""
print( "Setting up things to run code:" )
# load lens data
print("Reading lens data for redshift bin [%.2f,%.2f] (index %d) from %s..."%(zl_lims[0],zl_lims[1],lens_bin+1,lens_file))
print ('lens_file', lens_file)
# read lens galaxy data
# self.ra_l, self.dec_l, self.weight_lens = self.ggl_setup.load_lens_Y6_maglim_all_bins(lens_file, zl_bin=lens_bin) #Loads all bins for psf test
self.ra_l, self.dec_l, self.weight_lens = self.ggl_setup.load_lens_Y6_maglim(lens_file, zl_bin=lens_bin)
# self.ra_l, self.dec_l, self.weight_lens = self.ggl_setup.load_lens_Y3_maglim(lens_file, zl_lims=zl_lims)
if not self.par.use_LSSweight:
print("Warning: Will not load LSS weights for lenses, setting them to 1")
self.weight_lens = np.ones(len(self.ra_l))
# load source data
if source_cat == 'metadetect':
print("Reading source data for source bin [%.2f,%.2f] (index %d) from %s..."%(zs_lims[0],zs_lims[1],source_bin+1,source_file))
print ('source_file', source_file)
# read source galaxy data
(self.ra_s, self.dec_s, self.e1_s, self.e2_s, self.R_g, self.w_g) = self.ggl_setup.load_source_metadetect_unblinded(source_file, response, zs_bin=source_bin)
# (self.ra_s, self.dec_s, self.e1_s, self.e2_s, self.R_g, self.w_g) = self.ggl_setup.load_source_metadetect(source_file, response, zs_bin=source_bin) #switch to old for psf test
# self.R_g, self.w_g) = self.ggl_setup.load_source_metacal_5sels(source_file, zs_bin=source_bin)
#self.R_g, self.w_g)
# file = fits.open(par.out_main+'/metadetect_bin{}.fits'.format(zs_bin))
if not self.par.use_response:
print("Warning: Will set metadetect response to 1")
self.R_g = 1.
if not self.par.use_shearweight:
print("Warning: Will not load metadetect weights, setting them to 1")
self.w_g = np.ones(len(self.ra_s))
elif source_cat == 'bfd':
print ('source_file_bfd', source_file_bfd)
(self.ra_s, self.dec_s,
self.e1_s, self.e2_s,
self.R_g, self.w_g) = self.ggl_setup.load_source_bfd(source_file_bfd, zs_bin=source_bin)
if not self.par.use_shearweight:
print("Warning: Will not load bfd weights, setting them to 1")
self.w_g = np.ones(len(self.ra_s))
else:
print ('Specify which source catalog you want to use in the params.py file! Exiting the program')
sys.exit(0)
# load random points data
if self.par.use_randoms or self.par.use_boosts:
print("Reading random-point data from %s..."%(randoms_file))
self.ra_rand, self.dec_rand = self.ggl_setup.load_randoms_Y6(randoms_file, zl_bin=lens_bin)
# self.ra_rand, self.dec_rand = self.ggl_setup.load_randoms_Y6_maglim(path)
# self.ra_rand, self.dec_rand = self.ggl_setup.load_randoms_Y3_maglim(randoms_file, zl_lims=zl_lims)
else:
print("Will not load randoms points data, as it is not needed in current run")
self.ra_rand = None
self.dec_rand = None
# load ellipticity data for response test
if self.par.calc_scale_dependant_response:
#print("zs lims:")
#print(zs_lims[0])
(self.ra1p_s, self.dec1p_s, self.ra1m_s, self.dec1m_s,
self.ra2p_s, self.dec2p_s, self.ra2m_s, self.dec2m_s,
self.w1p, self.w1m, self.w2p, self.w2m,
self.g1p_d, self.g1m_d, self.g2p_d, self.g2m_d,
self.g1p_nd, self.g1m_nd, self.g2p_nd, self.g2m_nd) = self.ggl_setup.load_mdet_with_sheared_ellipticities(source_file, zs_bin=source_bin)
#self.w1p = np.ones(len(self.ra1p_s))
#self.w1m = np.ones(len(self.ra1m_s))
#self.w2p = np.ones(len(self.ra2p_s))
#self.w2m = np.ones(len(self.ra2m_s))
print( "Done reading data" )
return
def run_gammat(self):
"""
Run code to get gamma_t
output
------
results are saved in file
"""
# output directory for gamma_t
path_out_gt = self.par.path_out_gt
if path_out_gt[-1] != '/': path_out_gt+='/'
if not os.path.exists(path_out_gt):
os.makedirs(path_out_gt)
# output directory for gamma_x
path_out_gx = self.par.path_out_gx
if path_out_gx[-1] != '/': path_out_gx+='/'
if not os.path.exists(path_out_gx):
os.makedirs(path_out_gx)
# output directory for boost factors
path_out_boost = self.par.path_out_boost
if path_out_boost[-1] != '/': path_out_boost+='/'
if not os.path.exists(path_out_boost):
os.makedirs(path_out_boost)
# setup output path for extra info
path_out_extra = self.par.path_out_extra_gt
if path_out_extra[-1] != '/': path_out_extra+='/'
if not os.path.exists(path_out_extra):
os.makedirs(path_out_extra)
# setup output path for randoms
path_out_rand = self.par.path_out_rand
if path_out_rand[-1] != '/': path_out_rand+='/'
if not os.path.exists(path_out_rand):
os.makedirs(path_out_rand)
#
path_out_gt_rand = self.par.path_out_gt_rand
if path_out_gt_rand[-1] != '/': path_out_gt_rand+='/'
if not os.path.exists(path_out_gt_rand):
os.makedirs(path_out_gt_rand)
#
path_out_gx_rand = self.par.path_out_gx_rand
if path_out_gx_rand[-1] != '/': path_out_gx_rand+='/'
if not os.path.exists(path_out_gx_rand):
os.makedirs(path_out_gx_rand)
# setup output path for gamma_t shot noise variance
path_out_shot_gt = self.par.path_out_shot_gt
if path_out_shot_gt[-1] != '/': path_out_shot_gt+='/'
if not os.path.exists(path_out_shot_gt):
os.makedirs(path_out_shot_gt)
# print feedback
print( "Working on gamma_t calculation with bin slop=%.3f and resolution=%d:"%(self.par.bin_slop,self.par.nside) )
print( "Running treecorr with theta=[%.1f,%.1f] over %d angular bins"%(self.par.theta_lims[0],self.par.theta_lims[1],self.par.ang_nbins) )
# run code to get gamma_t
for lzind in self.par.l_bins:
# lens redshift cuts
zl_min, zl_max = self.par.zl_bins[lzind]
for szind in self.par.s_bins:
# source redshift cuts
zs_min, zs_max = self.par.zs_bins[szind]
# give feedback on progress
print( " Doing: lens bin %d [%.2f,%.2f] x source bin %d [%.2f,%.2f]"%(lzind+1,zl_min,zl_max,szind+1,zs_min,zs_max) )
# gamma_t output directory
gammat_out = path_out_gt+'/gammat_l{0}_s{1}.txt'.format(lzind+1,szind+1)
gammax_out = path_out_gx+'/gammax_l{0}_s{1}.txt'.format(lzind+1,szind+1)
extra_out = path_out_extra+'/gammat_extra_l{0}_s{1}.txt'.format(lzind+1,szind+1)
extra_rand_out = path_out_extra+'/gammat_rand_extra_l{0}_s{1}.txt'.format(lzind+1,szind+1)
randoms_gt_out = path_out_gt_rand+'/gammat_rand_l{0}_s{1}.txt'.format(lzind+1,szind+1)
randoms_gx_out = path_out_gx_rand+'/gammax_rand_l{0}_s{1}.txt'.format(lzind+1,szind+1)
boosts_out = path_out_boost+'/boost_l{0}_s{1}.txt'.format(lzind+1,szind+1)
shot_gammat_out = path_out_shot_gt+'/shot_noise_gammat_l{0}_s{1}.txt'.format(lzind+1,szind+1)
# load data and setup current bin
# self.setup_run(lens_file=self.par.data_lens[lzind],
# randoms_file=self.par.data_randoms[lzind],
# source_file=self.par.data_source[szind],
# lens_bin=lzind, source_bin=szind, zl_lims=[zl_min,zl_max], zs_lims=[zs_min,zs_max])
self.setup_run(source_cat=self.par.source_cat,
path=self.par.out_main,
lens_file=self.par.data_lens,
randoms_file=self.par.data_randoms,
source_file=self.par.data_source,
source_file_bfd=self.par.data_source_bfd,
response=self.par.response[szind],
lens_bin=lzind, source_bin=szind,
zl_lims=[zl_min,zl_max], zs_lims=[zs_min,zs_max])
print('Number of lenses=',len(self.ra_l))
# random points
if self.par.use_randoms or self.par.use_boosts:
print('Number of randoms=',len(self.ra_rand))
else:
print('Will not use random points')
# parameters to parse to treecorr
params = [self.e1_s,self.e2_s,self.R_g,self.w_g]
# get gamma_t for defined parameters
(theta_res, gammat_total, gammat_res, gammat_rand,
shot_noise_gammat,
xi_im, xi_im_rand, xi_npairs, xi_npairs_rand, xi_weight, xi_weight_rand,
Rg, sum_w_l, sum_w_r,
boosts) = self.ggl_setup.get_gammat(self.ra_l, self.dec_l, self.ra_s, self.dec_s,
ra_rand=self.ra_rand, dec_rand=self.dec_rand,
params=params, low_mem=self.par.treecorr_low_mem, weights=self.weight_lens,
use_randoms=self.par.use_randoms, use_boosts=self.par.use_boosts)
# save gamma_x
np.savetxt(gammax_out, np.c_[theta_res,xi_im/Rg], header='theta, gamma_x')
# save shot noise
np.savetxt(shot_gammat_out, np.c_[theta_res,shot_noise_gammat], header='theta, gammat_shot_noise')
# save results in file
np.savetxt(randoms_gt_out, np.c_[theta_res,gammat_rand], header='theta, gamma_t')
np.savetxt(randoms_gx_out, np.c_[theta_res,xi_im_rand/Rg], header='theta, gamma_x')
np.savetxt(extra_rand_out, np.c_[xi_im_rand,xi_npairs_rand,xi_weight_rand,
Rg*np.ones(len(theta_res)),sum_w_l*np.ones(len(theta_res)),sum_w_r*np.ones(len(theta_res))],
header='xi_im, xi_npair, xi_weight, Rg, sum_w_l, sum_w_r')
# save results in file
np.savetxt(gammat_out, np.c_[theta_res,gammat_res], header='theta, gamma_t')
np.savetxt(extra_out, np.c_[xi_im,xi_npairs,xi_weight,Rg*np.ones(len(theta_res))], header='xi_im, xi_npair, xi_weight, Rg')
np.savetxt(boosts_out, np.c_[theta_res,boosts], header='theta, boost')
# piece together components to get gamma_t with RP subtraction and boost factors applied
if self.par.use_boosts or self.par.use_randoms:
if path_out_gt[-1]=='/':
path_out_gt_final = path_out_gt[:-1]
else:
path_out_gt_final = path_out_gt
if self.par.use_boosts:
path_out_gt_final += '_bf'
if self.par.use_randoms:
path_out_gt_final += '_rp'
path_out_gt_final += '/'
gammat_total_out = path_out_gt_final+'gammat_l{0}_s{1}.txt'.format(lzind+1,szind+1)
# setup output path
if not os.path.exists(path_out_gt_final):
os.makedirs(path_out_gt_final)
np.savetxt(gammat_total_out, np.c_[theta_res,gammat_total], header='theta, gamma_t')
else:
if not np.all(gammat_total/gammat_res==1.):
errmsg = '!!!Something is wrong, no boost or randoms, but final gammat is not equal to the basic gammat measurement'
raise Exception(errmsg)
# piece together components to get gamma_x with RP subtraction and boost factors applied
gammax_total = xi_im/Rg - xi_im_rand/Rg
if self.par.use_randoms:
if path_out_gx[-1]=='/':
path_out_gx_final = path_out_gx[:-1]
else:
path_out_gx_final = path_out_gx
path_out_gx_final += '_rp'
path_out_gx_final += '/'
gammax_total_out = path_out_gx_final+'gammax_l{0}_s{1}.txt'.format(lzind+1,szind+1)
if not os.path.exists(path_out_gx_final):
os.makedirs(path_out_gx_final)
np.savetxt(gammax_total_out, np.c_[theta_res,gammax_total], header='theta, gamma_x')
else:
if not np.all(gammax_total/(xi_im/Rg)==1.):
errmsg = '!!!Something is wrong, no randoms, but final gammax is not equal to the basic gammax measurement'
raise Exception(errmsg)
# give feedback on progress
print( " Results saved in: %s"%gammat_out )
print( "--Done\n" )
# clear up memory to avoid out-of-memory issues
del self.ra_l, self.dec_l, self.ra_s, self.dec_s
del self.ra_rand, self.dec_rand
del self.e1_s,self.e2_s,self.R_g,self.w_g
del self.weight_lens
print( "Done calculating gamma_t \n" )
return
def run_gammat_and_cov_parallel(self):
"""
Run code to get gamma_t and its covariance using only Treecorr
output
------
results are saved in file
"""
# output directory for gamma_t
path_out_gt = self.par.path_out_gt
# print ('path_out_gt ----------->', path_out_gt)
if path_out_gt[-1] != '/': path_out_gt+='/'
print ('path_out_gt ----------->', path_out_gt)
if not os.path.exists(path_out_gt):
os.makedirs(path_out_gt)
# output directory for gamma_x
path_out_gx = self.par.path_out_gx
if path_out_gx[-1] != '/': path_out_gx+='/'
if not os.path.exists(path_out_gx):
os.makedirs(path_out_gx)
# output directory for boost factors
path_out_boost = self.par.path_out_boost
if path_out_boost[-1] != '/': path_out_boost+='/'
if not os.path.exists(path_out_boost):
os.makedirs(path_out_boost)
# setup output path for extra info
path_out_extra = self.par.path_out_extra_gt
if path_out_extra[-1] != '/': path_out_extra+='/'
if not os.path.exists(path_out_extra):
os.makedirs(path_out_extra)
# setup output path for randoms
path_out_rand = self.par.path_out_rand
if path_out_rand[-1] != '/': path_out_rand+='/'
if not os.path.exists(path_out_rand):
os.makedirs(path_out_rand)
#
path_out_gt_rand = self.par.path_out_gt_rand
if path_out_gt_rand[-1] != '/': path_out_gt_rand+='/'
if not os.path.exists(path_out_gt_rand):
os.makedirs(path_out_gt_rand)
#
path_out_gx_rand = self.par.path_out_gx_rand
if path_out_gx_rand[-1] != '/': path_out_gx_rand+='/'
if not os.path.exists(path_out_gx_rand):
os.makedirs(path_out_gx_rand)
# setup output path for gamma_t Jackknife covariance
path_JK_cov_gt = self.par.path_JK_cov_gt
if path_JK_cov_gt[-1] != '/': path_JK_cov_gt+='/'
if not os.path.exists(path_JK_cov_gt):
os.makedirs(path_JK_cov_gt)
# setup output path for random-point gamma_t Jackknife covariance
path_JK_cov_gt_rand = self.par.path_JK_cov_gt_rand
if path_JK_cov_gt_rand[-1] != '/': path_JK_cov_gt_rand+='/'
if not os.path.exists(path_JK_cov_gt_rand):
os.makedirs(path_JK_cov_gt_rand)
# setup output path for gamma_t Jackknife covariance
path_JK_cov_gx = self.par.path_JK_cov_gx
if path_JK_cov_gx[-1] != '/': path_JK_cov_gx+='/'
if not os.path.exists(path_JK_cov_gx):
os.makedirs(path_JK_cov_gx)
# setup output path for gamma_t Jackknife covariance
path_JK_cov_bf = self.par.path_JK_cov_bf
if path_JK_cov_bf[-1] != '/': path_JK_cov_bf+='/'
if not os.path.exists(path_JK_cov_bf):
os.makedirs(path_JK_cov_bf)
# setup output path for gamma_t shot noise variance
path_out_shot_gt = self.par.path_out_shot_gt
if path_out_shot_gt[-1] != '/': path_out_shot_gt+='/'
if not os.path.exists(path_out_shot_gt):
os.makedirs(path_out_shot_gt)
# print feedback
print( "Working on gamma_t calculation with bin slop=%.3f and resolution=%d:"%(self.par.bin_slop,self.par.nside) )
print( "Running treecorr with theta=[%.1f,%.1f] over %d angular bins"%(self.par.theta_lims[0],self.par.theta_lims[1],self.par.ang_nbins) )
#================
# srun --nodes=4 --tasks-per-node=1 python run_ggl.py
#8n jobs ---
#evereything here is done by all processes
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()
jobs = []
for i in range(6):
for j in range(4):
jobs.append([i,j])
run_count = rank
# =================
# run code to get gamma_t
while run_count < len(jobs):
lzind,szind = jobs[run_count]
print ('lens bin {0}, source bin {1}'.format(lzind, szind), flush=True)
# lens redshift cuts
zl_min, zl_max = self.par.zl_bins[lzind]
# source redshift cuts
zs_min, zs_max = self.par.zs_bins[szind]
# source redshift cuts
# print ('self.par.zs_bins[szind]', self.par.zs_bins[szind])
# give feedback on progress
# print( "Doing: lens bin %d [%.2f,%.2f] x source bin %d [%.2f,%.2f]"%(lzind+1,zl_min,zl_max,szind+1,zs_min,zs_max) )
# gamma_t output directory
gammat_out = path_out_gt+'/gammat_l{0}_s{1}.txt'.format(lzind+1,szind+1)
gammax_out = path_out_gx+'/gammax_l{0}_s{1}.txt'.format(lzind+1,szind+1)
extra_out = path_out_extra+'/gammat_extra_l{0}_s{1}.txt'.format(lzind+1,szind+1)
extra_rand_out = path_out_extra+'/gammat_rand_extra_l{0}_s{1}.txt'.format(lzind+1,szind+1)
randoms_gt_out = path_out_gt_rand+'/gammat_rand_l{0}_s{1}.txt'.format(lzind+1,szind+1)
randoms_gx_out = path_out_gx_rand+'/gammax_rand_l{0}_s{1}.txt'.format(lzind+1,szind+1)
boosts_out = path_out_boost+'/boost_l{0}_s{1}.txt'.format(lzind+1,szind+1)
cov_gammat_out = path_JK_cov_gt+'/cov_gammat_l{0}_s{1}.txt'.format(lzind+1,szind+1)
cov_gammat_rand_out = path_JK_cov_gt_rand+'/cov_gammat_rand_l{0}_s{1}.txt'.format(lzind+1,szind+1)
cov_gammax_out = path_JK_cov_gx+'/cov_gammax_l{0}_s{1}.txt'.format(lzind+1,szind+1)
cov_boosts_out = path_JK_cov_bf+'/cov_boost_l{0}_s{1}.txt'.format(lzind+1,szind+1)
err_gammat_out = path_JK_cov_gt+'/err_gammat_l{0}_s{1}.txt'.format(lzind+1,szind+1)
shot_gammat_out = path_out_shot_gt+'/shot_noise_gammat_l{0}_s{1}.txt'.format(lzind+1,szind+1)
# print ('self.par.out_main', self.par.out_main)
# load data and setup current bin
self.setup_run(source_cat=self.par.source_cat,
path=self.par.out_main,
lens_file=self.par.data_lens,
randoms_file=self.par.data_randoms,
source_file=self.par.data_source,
source_file_bfd=self.par.data_source_bfd,
response=self.par.response[szind],
lens_bin=lzind, source_bin=szind,
zl_lims=[zl_min,zl_max], zs_lims=[zs_min,zs_max])
print('Number of lenses=',len(self.ra_l))
# random points
if self.par.use_randoms or self.par.use_boosts:
print('Number of randoms=',len(self.ra_rand))
else:
print('Will not use random points')
# parameters to parse to treecorr
params = [self.e1_s,self.e2_s,self.R_g,self.w_g]
print ('-------> params', params)
print ('-------> self.R_g', self.R_g)
print ('-------> self.w_g', self.w_g)
# get gamma_t for defined parameters
(theta_res, gammat_res, gammat_total, gammat_rand, gammax_res, gammax_total, gammax_rand,
cov_gammat, shot_noise_gammat, cov_boost, cov_gammax, cov_gammat_rand,
xi_im, xi_im_rand, xi_npairs, xi_npairs_rand, xi_weight, xi_weight_rand,
Rg, sum_w_l, sum_w_r,
boosts) = self.ggl_setup.get_gammat_and_covariance(self.ra_l, self.dec_l, self.ra_s, self.dec_s, ra_rand=self.ra_rand, dec_rand=self.dec_rand, params=params,low_mem=self.par.treecorr_low_mem, weights=self.weight_lens,use_randoms=self.par.use_randoms,use_boosts=self.par.use_boosts)
# save covariances
#---gamma_t
with open(cov_gammat_out,'wb') as f:
for line in cov_gammat.T:
np.savetxt(f, [line])
gt_err = np.sqrt(np.diag(cov_gammat))
np.savetxt(err_gammat_out, np.c_[theta_res,gt_err], header='theta, gammat_err')
np.savetxt(shot_gammat_out, np.c_[theta_res,shot_noise_gammat], header='theta, gammat_shot_noise')
#---boost factors
with open(cov_boosts_out,'wb') as f:
for line in cov_boost.T:
np.savetxt(f, [line])
#---gamma_x
with open(cov_gammax_out,'wb') as f:
for line in cov_gammax.T:
np.savetxt(f, [line])
#---randoms points
with open(cov_gammat_rand_out,'wb') as f:
for line in cov_gammat_rand.T:
np.savetxt(f, [line])
# save results in file
#---gamma_t
np.savetxt(gammat_out, np.c_[theta_res,gammat_res], header='theta, gamma_t')
np.savetxt(randoms_gt_out, np.c_[theta_res,gammat_rand], header='theta, gamma_t')
#---gamma_x
np.savetxt(gammax_out, np.c_[theta_res,gammax_res], header='theta, gamma_x')
np.savetxt(randoms_gx_out, np.c_[theta_res,gammax_rand], header='theta, gamma_x')
#---boost factors
np.savetxt(boosts_out, np.c_[theta_res,boosts], header='theta, boost')
#---extra stuff
np.savetxt(extra_out, np.c_[xi_im,xi_npairs,xi_weight,Rg*np.ones(len(theta_res))],
header='xi_im, xi_npair, xi_weight, Rg')
np.savetxt(extra_rand_out, np.c_[xi_im_rand,xi_npairs_rand,xi_weight_rand,
Rg*np.ones(len(theta_res)),sum_w_l*np.ones(len(theta_res)),sum_w_r*np.ones(len(theta_res))],
header='xi_im, xi_npair, xi_weight, Rg, sum_w_l, sum_w_r,')
# save results with RP subtraction and boost factors applied
#---gamma_t
if self.par.use_boosts or self.par.use_randoms:
if path_out_gt[-1]=='/':
path_out_gt_final = path_out_gt[:-1]
else:
path_out_gt_final = path_out_gt
if self.par.use_boosts:
path_out_gt_final += '_bf'
if self.par.use_randoms:
path_out_gt_final += '_rp'
path_out_gt_final += '/'
gammat_total_out = path_out_gt_final+'gammat_l{0}_s{1}.txt'.format(lzind+1,szind+1)
# setup output path
if not os.path.exists(path_out_gt_final):
os.makedirs(path_out_gt_final)
np.savetxt(gammat_total_out, np.c_[theta_res,gammat_total], header='theta, gamma_t')
else:
if not np.all(gammat_total/gammat_res==1.):
errmsg = '!!!Something is wrong, no boost or randoms, but final gammat is not equal to the basic gammat measurement'
raise Exception(errmsg)
#---gamma_x
if self.par.use_randoms:
if path_out_gx[-1]=='/':
path_out_gx_final = path_out_gx[:-1]
else:
path_out_gx_final = path_out_gx
path_out_gx_final += '_rp'
path_out_gx_final += '/'
gammax_total_out = path_out_gx_final+'gammax_l{0}_s{1}.txt'.format(lzind+1,szind+1)
if not os.path.exists(path_out_gx_final):
os.makedirs(path_out_gx_final)
np.savetxt(gammax_total_out, np.c_[theta_res,gammax_total], header='theta, gamma_x')
else:
if not np.all(gammax_total/(xi_im/Rg)==1.):
errmsg = '!!!Something is wrong, no randoms, but final gammax is not equal to the basic gammax measurement'
raise Exception(errmsg)
# give feedback on progress
print( " Results saved in: %s"%gammat_out )
print( "--Done\n" )
# clear up memory
del self.ra_l, self.dec_l, self.ra_s, self.dec_s
del self.e1_s,self.e2_s,self.R_g,self.w_g
del self.ra_rand, self.dec_rand
del self.weight_lens
gc.collect()
run_count += size
comm.Barrier()
# Save the content of params.py to a text file
params_dict = {key: value for key, value in vars(self.par).items() if not key.startswith('__') and not callable(value)}
with open(self.par.out_main+'/params_content.txt', 'w') as f:
for key, value in params_dict.items():
f.write(f"{key} = {value}\n")
if((len(self.par.l_bins) == 6) & (len(self.par.s_bins) == 4) & self.par.use_boosts & self.par.use_randoms):
print ("Saving 2pt file")
gammat_all = []
for l in self.par.l_bins:
for s in self.par.s_bins:
asd = np.loadtxt(self.par.out_main + '/gammat_bf_rp/gammat_l{0}_s{1}.txt'.format(l+1, s+1))
gammat_all.append(asd[:,1])
gammat_all = np.concatenate(gammat_all)
dv = fits.open(self.par.dv_input)
dv[4].data['VALUE'] = gammat_all
dv.writeto(self.par.dv_output, overwrite=True)
print( "2pt file saved in: %s"%self.par.dv_output )
print( "Done calculating gamma_t \n" )
return
def run_gammat_and_cov(self):
"""
Run code to get gamma_t and its covariance using only Treecorr
output
------
results are saved in file
"""
# output directory for gamma_t
path_out_gt = self.par.path_out_gt
# print ('path_out_gt ----------->', path_out_gt)
if path_out_gt[-1] != '/': path_out_gt+='/'
print ('path_out_gt ----------->', path_out_gt)
if not os.path.exists(path_out_gt):
os.makedirs(path_out_gt)
# output directory for gamma_x
path_out_gx = self.par.path_out_gx
if path_out_gx[-1] != '/': path_out_gx+='/'
if not os.path.exists(path_out_gx):
os.makedirs(path_out_gx)
# output directory for boost factors
path_out_boost = self.par.path_out_boost
if path_out_boost[-1] != '/': path_out_boost+='/'
if not os.path.exists(path_out_boost):
os.makedirs(path_out_boost)
# setup output path for extra info
path_out_extra = self.par.path_out_extra_gt
if path_out_extra[-1] != '/': path_out_extra+='/'
if not os.path.exists(path_out_extra):
os.makedirs(path_out_extra)
# setup output path for randoms
path_out_rand = self.par.path_out_rand
if path_out_rand[-1] != '/': path_out_rand+='/'
if not os.path.exists(path_out_rand):
os.makedirs(path_out_rand)
#
path_out_gt_rand = self.par.path_out_gt_rand
if path_out_gt_rand[-1] != '/': path_out_gt_rand+='/'
if not os.path.exists(path_out_gt_rand):
os.makedirs(path_out_gt_rand)
#
path_out_gx_rand = self.par.path_out_gx_rand
if path_out_gx_rand[-1] != '/': path_out_gx_rand+='/'
if not os.path.exists(path_out_gx_rand):
os.makedirs(path_out_gx_rand)
# setup output path for gamma_t Jackknife covariance
path_JK_cov_gt = self.par.path_JK_cov_gt
if path_JK_cov_gt[-1] != '/': path_JK_cov_gt+='/'
if not os.path.exists(path_JK_cov_gt):
os.makedirs(path_JK_cov_gt)
# setup output path for random-point gamma_t Jackknife covariance
path_JK_cov_gt_rand = self.par.path_JK_cov_gt_rand
if path_JK_cov_gt_rand[-1] != '/': path_JK_cov_gt_rand+='/'
if not os.path.exists(path_JK_cov_gt_rand):
os.makedirs(path_JK_cov_gt_rand)
# setup output path for gamma_t Jackknife covariance
path_JK_cov_gx = self.par.path_JK_cov_gx
if path_JK_cov_gx[-1] != '/': path_JK_cov_gx+='/'
if not os.path.exists(path_JK_cov_gx):
os.makedirs(path_JK_cov_gx)
# setup output path for gamma_t Jackknife covariance
path_JK_cov_bf = self.par.path_JK_cov_bf
if path_JK_cov_bf[-1] != '/': path_JK_cov_bf+='/'
if not os.path.exists(path_JK_cov_bf):
os.makedirs(path_JK_cov_bf)
# setup output path for gamma_t shot noise variance
path_out_shot_gt = self.par.path_out_shot_gt
if path_out_shot_gt[-1] != '/': path_out_shot_gt+='/'
if not os.path.exists(path_out_shot_gt):
os.makedirs(path_out_shot_gt)
# print feedback
print( "Working on gamma_t calculation with bin slop=%.3f and resolution=%d:"%(self.par.bin_slop,self.par.nside) )
print( "Running treecorr with theta=[%.1f,%.1f] over %d angular bins"%(self.par.theta_lims[0],self.par.theta_lims[1],self.par.ang_nbins) )
# run code to get gamma_t
for lzind in self.par.l_bins:
print ('lens bin ', lzind)
# lens redshift cuts
zl_min, zl_max = self.par.zl_bins[lzind]
for szind in self.par.s_bins:
print ('SZIND', szind)
# source redshift cuts
zs_min, zs_max = self.par.zs_bins[szind]
# source redshift cuts
print ('self.par.zs_bins[szind]', self.par.zs_bins[szind])
# give feedback on progress
print( " Doing: lens bin %d [%.2f,%.2f] x source bin %d [%.2f,%.2f]"%(lzind+1,zl_min,zl_max,szind+1,zs_min,zs_max) )
# gamma_t output directory
gammat_out = path_out_gt+'/gammat_l{0}_s{1}.txt'.format(lzind+1,szind+1)
gammax_out = path_out_gx+'/gammax_l{0}_s{1}.txt'.format(lzind+1,szind+1)
extra_out = path_out_extra+'/gammat_extra_l{0}_s{1}.txt'.format(lzind+1,szind+1)
extra_rand_out = path_out_extra+'/gammat_rand_extra_l{0}_s{1}.txt'.format(lzind+1,szind+1)
randoms_gt_out = path_out_gt_rand+'/gammat_rand_l{0}_s{1}.txt'.format(lzind+1,szind+1)
randoms_gx_out = path_out_gx_rand+'/gammax_rand_l{0}_s{1}.txt'.format(lzind+1,szind+1)
boosts_out = path_out_boost+'/boost_l{0}_s{1}.txt'.format(lzind+1,szind+1)
cov_gammat_out = path_JK_cov_gt+'/cov_gammat_l{0}_s{1}.txt'.format(lzind+1,szind+1)
cov_gammat_rand_out = path_JK_cov_gt_rand+'/cov_gammat_rand_l{0}_s{1}.txt'.format(lzind+1,szind+1)
cov_gammax_out = path_JK_cov_gx+'/cov_gammax_l{0}_s{1}.txt'.format(lzind+1,szind+1)
cov_boosts_out = path_JK_cov_bf+'/cov_boost_l{0}_s{1}.txt'.format(lzind+1,szind+1)
err_gammat_out = path_JK_cov_gt+'/err_gammat_l{0}_s{1}.txt'.format(lzind+1,szind+1)
shot_gammat_out = path_out_shot_gt+'/shot_noise_gammat_l{0}_s{1}.txt'.format(lzind+1,szind+1)
print ('self.par.out_main', self.par.out_main)
# load data and setup current bin
self.setup_run(source_cat=self.par.source_cat,
path=self.par.out_main,
lens_file=self.par.data_lens,
randoms_file=self.par.data_randoms,
source_file=self.par.data_source,
source_file_bfd=self.par.data_source_bfd,
response=self.par.response[szind],
lens_bin=lzind, source_bin=szind,
zl_lims=[zl_min,zl_max], zs_lims=[zs_min,zs_max])
print('Number of lenses=',len(self.ra_l))
# random points
if self.par.use_randoms or self.par.use_boosts:
print('Number of randoms=',len(self.ra_rand))
else:
print('Will not use random points')
# parameters to parse to treecorr
params = [self.e1_s,self.e2_s,self.R_g,self.w_g]
print ('-------> params', params)
print ('-------> self.R_g', self.R_g)
print ('-------> self.w_g', self.w_g)
# get gamma_t for defined parameters
(theta_res, gammat_res, gammat_total, gammat_rand, gammax_res, gammax_total, gammax_rand,
cov_gammat, shot_noise_gammat, cov_boost, cov_gammax, cov_gammat_rand,
xi_im, xi_im_rand, xi_npairs, xi_npairs_rand, xi_weight, xi_weight_rand,
Rg, sum_w_l, sum_w_r,
boosts) = self.ggl_setup.get_gammat_and_covariance(self.ra_l, self.dec_l, self.ra_s, self.dec_s, ra_rand=self.ra_rand, dec_rand=self.dec_rand, params=params,low_mem=self.par.treecorr_low_mem, weights=self.weight_lens,use_randoms=self.par.use_randoms,use_boosts=self.par.use_boosts)
# save covariances
#---gamma_t
with open(cov_gammat_out,'wb') as f:
for line in cov_gammat.T:
np.savetxt(f, [line])
gt_err = np.sqrt(np.diag(cov_gammat))
np.savetxt(err_gammat_out, np.c_[theta_res,gt_err], header='theta, gammat_err')
np.savetxt(shot_gammat_out, np.c_[theta_res,shot_noise_gammat], header='theta, gammat_shot_noise')
#---boost factors
with open(cov_boosts_out,'wb') as f:
for line in cov_boost.T:
np.savetxt(f, [line])
#---gamma_x
with open(cov_gammax_out,'wb') as f:
for line in cov_gammax.T:
np.savetxt(f, [line])
#---randoms points
with open(cov_gammat_rand_out,'wb') as f:
for line in cov_gammat_rand.T:
np.savetxt(f, [line])
# save results in file
#---gamma_t
np.savetxt(gammat_out, np.c_[theta_res,gammat_res], header='theta, gamma_t')
np.savetxt(randoms_gt_out, np.c_[theta_res,gammat_rand], header='theta, gamma_t')
#---gamma_x
np.savetxt(gammax_out, np.c_[theta_res,gammax_res], header='theta, gamma_x')
np.savetxt(randoms_gx_out, np.c_[theta_res,gammax_rand], header='theta, gamma_x')
#---boost factors
np.savetxt(boosts_out, np.c_[theta_res,boosts], header='theta, boost')
#---extra stuff
np.savetxt(extra_out, np.c_[xi_im,xi_npairs,xi_weight,Rg*np.ones(len(theta_res))],
header='xi_im, xi_npair, xi_weight, Rg')
np.savetxt(extra_rand_out, np.c_[xi_im_rand,xi_npairs_rand,xi_weight_rand,
Rg*np.ones(len(theta_res)),sum_w_l*np.ones(len(theta_res)),sum_w_r*np.ones(len(theta_res))],
header='xi_im, xi_npair, xi_weight, Rg, sum_w_l, sum_w_r,')
# save results with RP subtraction and boost factors applied
#---gamma_t
if self.par.use_boosts or self.par.use_randoms:
if path_out_gt[-1]=='/':
path_out_gt_final = path_out_gt[:-1]
else:
path_out_gt_final = path_out_gt
if self.par.use_boosts:
path_out_gt_final += '_bf'
if self.par.use_randoms:
path_out_gt_final += '_rp'
path_out_gt_final += '/'
gammat_total_out = path_out_gt_final+'gammat_l{0}_s{1}.txt'.format(lzind+1,szind+1)
# setup output path
if not os.path.exists(path_out_gt_final):
os.makedirs(path_out_gt_final)
np.savetxt(gammat_total_out, np.c_[theta_res,gammat_total], header='theta, gamma_t')
else:
if not np.all(gammat_total/gammat_res==1.):
errmsg = '!!!Something is wrong, no boost or randoms, but final gammat is not equal to the basic gammat measurement'
raise Exception(errmsg)
#---gamma_x
if self.par.use_randoms:
if path_out_gx[-1]=='/':
path_out_gx_final = path_out_gx[:-1]
else:
path_out_gx_final = path_out_gx
path_out_gx_final += '_rp'
path_out_gx_final += '/'
gammax_total_out = path_out_gx_final+'gammax_l{0}_s{1}.txt'.format(lzind+1,szind+1)
if not os.path.exists(path_out_gx_final):
os.makedirs(path_out_gx_final)
np.savetxt(gammax_total_out, np.c_[theta_res,gammax_total], header='theta, gamma_x')
else:
if not np.all(gammax_total/(xi_im/Rg)==1.):
errmsg = '!!!Something is wrong, no randoms, but final gammax is not equal to the basic gammax measurement'
raise Exception(errmsg)
# give feedback on progress
print( " Results saved in: %s"%gammat_out )
print( "--Done\n" )
# clear up memory
del self.ra_l, self.dec_l, self.ra_s, self.dec_s
del self.e1_s,self.e2_s,self.R_g,self.w_g
del self.ra_rand, self.dec_rand
del self.weight_lens
gc.collect()
# Save the content of params.py to a text file
params_dict = {key: value for key, value in vars(self.par).items() if not key.startswith('__') and not callable(value)}
with open(self.par.out_main+'/params_content.txt', 'w') as f:
for key, value in params_dict.items():
f.write(f"{key} = {value}\n")
if((len(self.par.l_bins) == 6) & (len(self.par.s_bins) == 4) & self.par.use_boosts & self.par.use_randoms):
print ("Saving 2pt file")
gammat_all = []
for l in self.par.l_bins:
for s in self.par.s_bins:
asd = np.loadtxt(self.par.out_main + '/gammat_bf_rp/gammat_l{0}_s{1}.txt'.format(l+1, s+1))
gammat_all.append(asd[:,1])
gammat_all = np.concatenate(gammat_all)
dv = fits.open(self.par.dv_input)
dv[4].data['VALUE'] = gammat_all
dv.writeto(self.par.dv_output, overwrite=True)
print( "2pt file saved in: %s"%self.par.dv_output )
print( "Done calculating gamma_t \n" )
return
def run_nk(self):
"""
Run code to get scale dependant ellipticities for the response test
output
------
results are saved in file
"""
# output directory for gamma_t
path_out_gt = self.par.path_out_gt
# print ('path_out_gt ----------->', path_out_gt)
if path_out_gt[-1] != '/': path_out_gt+='/'
print ('path_out_gt ----------->', path_out_gt)
if not os.path.exists(path_out_gt):
os.makedirs(path_out_gt)
# output directory for gamma_x
path_out_gx = self.par.path_out_gx
if path_out_gx[-1] != '/': path_out_gx+='/'
if not os.path.exists(path_out_gx):
os.makedirs(path_out_gx)
# output directory for boost factors
path_out_boost = self.par.path_out_boost
if path_out_boost[-1] != '/': path_out_boost+='/'
if not os.path.exists(path_out_boost):
os.makedirs(path_out_boost)
# setup output path for extra info
path_out_extra = self.par.path_out_extra_gt
if path_out_extra[-1] != '/': path_out_extra+='/'
if not os.path.exists(path_out_extra):
os.makedirs(path_out_extra)
# setup output path for randoms
path_out_rand = self.par.path_out_rand
if path_out_rand[-1] != '/': path_out_rand+='/'
if not os.path.exists(path_out_rand):
os.makedirs(path_out_rand)
#
path_out_gt_rand = self.par.path_out_gt_rand
if path_out_gt_rand[-1] != '/': path_out_gt_rand+='/'
if not os.path.exists(path_out_gt_rand):
os.makedirs(path_out_gt_rand)
#
path_out_gx_rand = self.par.path_out_gx_rand
if path_out_gx_rand[-1] != '/': path_out_gx_rand+='/'
if not os.path.exists(path_out_gx_rand):
os.makedirs(path_out_gx_rand)
# setup output path for gamma_t Jackknife covariance
path_JK_cov_gt = self.par.path_JK_cov_gt
if path_JK_cov_gt[-1] != '/': path_JK_cov_gt+='/'
if not os.path.exists(path_JK_cov_gt):
os.makedirs(path_JK_cov_gt)
# setup output path for random-point gamma_t Jackknife covariance
path_JK_cov_gt_rand = self.par.path_JK_cov_gt_rand
if path_JK_cov_gt_rand[-1] != '/': path_JK_cov_gt_rand+='/'
if not os.path.exists(path_JK_cov_gt_rand):
os.makedirs(path_JK_cov_gt_rand)
# setup output path for gamma_t Jackknife covariance
path_JK_cov_gx = self.par.path_JK_cov_gx
if path_JK_cov_gx[-1] != '/': path_JK_cov_gx+='/'
if not os.path.exists(path_JK_cov_gx):
os.makedirs(path_JK_cov_gx)
# setup output path for gamma_t Jackknife covariance
path_JK_cov_bf = self.par.path_JK_cov_bf
if path_JK_cov_bf[-1] != '/': path_JK_cov_bf+='/'
if not os.path.exists(path_JK_cov_bf):
os.makedirs(path_JK_cov_bf)
# setup output path for gamma_t shot noise variance
path_out_shot_gt = self.par.path_out_shot_gt
if path_out_shot_gt[-1] != '/': path_out_shot_gt+='/'
if not os.path.exists(path_out_shot_gt):
os.makedirs(path_out_shot_gt)
# print feedback
print( "Working on NK calculation with bin slop=%.3f and resolution=%d:"%(self.par.bin_slop,self.par.nside) )
print( "Running treecorr with theta=[%.1f,%.1f] over %d angular bins"%(self.par.theta_lims[0],self.par.theta_lims[1],self.par.ang_nbins) )
# run code to get gamma_t
for lzind in self.par.l_bins:
print ('lens bin ', lzind)
# lens redshift cuts
zl_min, zl_max = self.par.zl_bins[lzind]
for szind in self.par.s_bins:
print ('SZIND', szind)
# source redshift cuts
zs_min, zs_max = self.par.zs_bins[szind]
# source redshift cuts
print ('self.par.zs_bins[szind]', self.par.zs_bins[szind])
# give feedback on progress
print( " Doing: lens bin %d [%.2f,%.2f] x source bin %d [%.2f,%.2f]"%(lzind+1,zl_min,zl_max,szind+1,zs_min,zs_max) )
# output directories
g1p_d_out = path_out_gt+'/g1p_d_l{0}_s{1}.txt'.format(lzind+1,szind+1)
g1m_d_out = path_out_gt+'/g1m_d_l{0}_s{1}.txt'.format(lzind+1,szind+1)
g2p_d_out = path_out_gt+'/g2p_d_l{0}_s{1}.txt'.format(lzind+1,szind+1)
g2m_d_out = path_out_gt+'/g2m_d_l{0}_s{1}.txt'.format(lzind+1,szind+1)
g1p_nd_out = path_out_gt+'/g1p_nd_l{0}_s{1}.txt'.format(lzind+1,szind+1)
g1m_nd_out = path_out_gt+'/g1m_nd_l{0}_s{1}.txt'.format(lzind+1,szind+1)
g2p_nd_out = path_out_gt+'/g2p_nd_l{0}_s{1}.txt'.format(lzind+1,szind+1)
g2m_nd_out = path_out_gt+'/g2m_nd_l{0}_s{1}.txt'.format(lzind+1,szind+1)
print ('self.par.out_main', self.par.out_main)
# load data and setup current bin
self.setup_run(source_cat=self.par.source_cat,
path=self.par.out_main,
lens_file=self.par.data_lens,
randoms_file=self.par.data_randoms,
source_file=self.par.data_source,
source_file_bfd=self.par.data_source_bfd,
response=self.par.response[szind],
lens_bin=lzind, source_bin=szind,
zl_lims=[zl_min,zl_max], zs_lims=[zs_min,zs_max])
print('Number of lenses=',len(self.ra_l))
# random points
if self.par.use_randoms or self.par.use_boosts:
print('Number of randoms=',len(self.ra_rand))
else:
print('Will not use random points')
# parameters to parse to treecorr
params = [self.g1p_d,self.w1p]