/
NX01_master.py
executable file
·8560 lines (7303 loc) · 344 KB
/
NX01_master.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
#!/usr/bin/env python
"""
Created by stevertaylor
Copyright (c) 2014 Stephen R. Taylor
Code contributions by Rutger van Haasteren (piccard) and Justin Ellis (PAL/PAL2).
"""
from __future__ import division
import os, math, optparse, time, cProfile
import json, sys, glob
import cPickle as pickle
from time import gmtime, strftime
from collections import OrderedDict
import h5py as h5
import numpy as np
from numpy import *
from numpy import random
from scipy import integrate
from scipy import optimize
from scipy import constants as sc
from scipy import special as ss
from scipy import stats as scistats
from scipy import linalg as sl
from scipy.interpolate import interp1d
import numexpr as ne
import ephem
from ephem import *
import libstempo as T2
import NX01_AnisCoefficients as anis
import NX01_utils as utils
import NX01_psr
import rankreduced as rr
try:
import NX01_jitter as jitter
except ImportError:
print "You do not have NX01_jitter.so. " \
"Trying to make the .so file now..."
import pyximport
pyximport.install(setup_args={"include_dirs":np.get_include()},
reload_support=True)
try:
import NX01_jitter as jitter
except ImportError:
error_warning = """\
_____ __ __ _____ ____ _____ _______ ______ _____ _____ ____ _____ _ _
|_ _| \/ | __ \ / __ \| __ \__ __| | ____| __ \| __ \ / __ \| __ \| | |
| | | \ / | |__) | | | | |__) | | | | |__ | |__) | |__) | | | | |__) | | |
| | | |\/| | ___/| | | | _ / | | | __| | _ /| _ /| | | | _ /| | |
_| |_| | | | | | |__| | | \ \ | | | |____| | \ \| | \ \| |__| | | \ \|_|_|
|_____|_| |_|_| \____/|_| \_\ |_| |______|_| \_\_| \_\\____/|_| \_(_|_)
_____ ____ __ __ _____ _____ _ ______ _ _____ _______ _______ ______ _____
/ ____/ __ \| \/ | __ \_ _| | | ____| | |_ _|__ __|__ __| ____| __ \
| | | | | | \ / | |__) || | | | | |__ | | | | | | | | | |__ | |__) |
| | | | | | |\/| | ___/ | | | | | __| _ | | | | | | | | | __| | _ /
| |___| |__| | | | | | _| |_| |____| |____ | |__| |_| |_ | | | | | |____| | \ \
\_____\____/|_| |_|_| |_____|______|______| \____/|_____| |_| |_| |______|_| \_\
"""
print error_warning
print "You need to run: " \
"python setup-cython.py build_ext --inplace"
sys.exit()
try:
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
except ImportError:
print 'Do not have mpi4py package.'
import nompi4py as MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
f1yr = 1.0/(365.25*86400.0)
parser = optparse.OptionParser(description = "NX01 - It's been a long road, getting from there to here...")
############################
############################
parser.add_option('--jsonModel', dest='jsonModel', action='store', type=str, default = None,
help='Do you want to provide model arguments from a JSON file? (default = None)')
parser.add_option('--from-h5', dest='from_h5', action='store_true', default = False,
help='Do you want to read in pulsars from hdf5 files instead of directly via libstempo? (default = False)')
parser.add_option('--psrlist', dest='psrlist', action='store', type=str, default = None,
help='Provide path to file containing list of pulsars and their respective par/tim paths')
parser.add_option('--sysflag_target', dest='sysflag_target', action='store', type=str, default = 'f',
help='If you are supplying pulsar noise files, then specify which system flag you want to target (default = f)')
parser.add_option('--parfile', dest='parfile', action='store', type=str, default = None,
help='Provide path to a pulsar par file for single-pulsar analysis (default = None)')
parser.add_option('--timfile', dest='timfile', action='store', type=str, default = None,
help='Provide path to a pulsar tim file for single-pulsar analysis (default = None)')
parser.add_option('--jitterbin', dest='jitterbin', action='store', type=float, default = 1.0,
help='Provide size of jitter binning for single-pulsar analysis (default = 1 second)')
parser.add_option('--ephem', dest='ephem', action='store', type=str, default = None,
help='Choose ephemeris for single-pulsar analysis (default = None)')
parser.add_option('--svdDesign', dest='svdDesign', action='store_true', default = False,
help='Stablize the timing-model design matrix with an SVD for single-pulsar analysis (default = False)')
parser.add_option('--fitIters', dest='fitIters', action='store', type=int, default = 5,
help='Number of fitting iterations for single-pulsar analysis (default = 5)')
parser.add_option('--grab_planets', dest='grab_planets', action='store_true', default=False,
help='Do you want to grab the planetary position vectors in your single-pulsar analysis (default = False)')
parser.add_option('--nmodes', dest='nmodes', action='store', type=int, default=None,
help='Number of linear-spaced modes in low-rank time-frequency approximation')
parser.add_option('--nmodes_log', dest='nmodes_log', action='store', type=int, default=0,
help='Number of log-spaced modes in low-rank time-frequency approximation')
parser.add_option('--logmode', dest='logmode', action='store', type=int, default=0,
help='The index of the linear mode at which to transition to log-spacing (default = 0)')
parser.add_option('--fmin', dest='fmin', action='store', type=float, default=10.0,
help='Frequency down to which the log-spaced modes are sampled (default = 10.0, i.e. 1/10T)')
parser.add_option('--cadence', dest='cadence', action='store', type=float,
help='Instead of nmodes, provide the observational cadence in days.')
parser.add_option('--incDM', dest='incDM', action='store_true', default=False,
help='Search for DM variations in the data as a Gaussian process (False)? (default=False)')
parser.add_option('--varyWhite', dest='varyWhite', action='store_true', default=False,
help='Search for per-pulsar white-noise parameters? (default=False)')
parser.add_option('--sampler', dest='sampler', action='store', type=str, default='ptmcmc',
help='Which sampler do you want to use: PTMCMC (ptmcmc), MultiNest (mnest), or Polychord (pchord) (default = ptmcmc)')
parser.add_option('--ins', dest='ins', action='store_true', default=False,
help='Switch on importance nested sampling for MultiNest (default = False)')
parser.add_option('--nlive', dest='nlive', action='store', type=int, default=500,
help='Number of live points for MultiNest or Polychord (default = 500)')
parser.add_option('--sampleEff', dest='sampleEff', action='store', type=float, default=0.3,
help='Sampling efficiency for MultiNest (default = 0.3)')
parser.add_option('--constEff', dest='constEff', action='store_true', default=False,
help='Run MultiNest in constant efficiency mode? (default = False)')
parser.add_option('--nchords', dest='nchords', action='store', type=int, default=1,
help='Number of chords for Polychord (default = 1)')
parser.add_option('--resume', dest='resume', action='store_true', default=False,
help='Do you want to resume the sampler (default = False)')
parser.add_option('--niter', dest='niter', action='store', type=float, default=5e6,
help='Number of MCMC iterations for PTMCMC sampler (default = 5e6)')
parser.add_option('--writeHotChains', dest='writeHotChains', action='store_true', default=False,
help='Given a PTMCMC sampler, do you want to write out the hot chain samples? (default = False)')
parser.add_option('--hotChain', dest='hotChain', action='store_true', default=False,
help='Given a PTMCMC sampler, do you want to use a T=1e80 hot chain? (default = False)')
parser.add_option('--softParam', dest='softParam', action='store', type=float, default=1.0,
help='Artifical temperature by which to soften likelihood (default = 1.0)')
parser.add_option('--shortFileTag', dest='shortFileTag', action='store', type=str, default=None,
help='Provide a shorter file tag for MultiNest runs? (default = None)')
parser.add_option('--TmaxType', dest='TmaxType', action='store', type=str, default='pta',
help='Which type of Tmax to use to set frequencies: pta (longest baseline over the array), or pulsar (longest pulsar in array) (default = pta)')
parser.add_option('--incGWB', dest='incGWB', action='store_true', default=False,
help='Do you want to search for a GWB? (default = False)')
parser.add_option('--gwbSpecModel', dest='gwbSpecModel', action='store', type=str, default='powerlaw',
help='What kind of spectral model do you want for the GWB?: powerlaw, spectrum, turnover, gpEnvInterp (default = powerlaw)')
parser.add_option('--fix_gwbTurnKappa', dest='fix_gwbTurnKappa', action='store', type=float, default=None,
help='Do you want to fix kappa in the turnover GWB spectral model to a particular value? (stars=10/3, gas=7/3) (default = \'None\')')
parser.add_option('--gwb_fb2env', dest='gwb_fb2env', action='store', type=str, default=None,
help='In GWB turnover model, do you want to map the environmental parameters directly? (stars, gas, etc.) (default = \'None\')')
parser.add_option('--gpPickle', dest='gpPickle', action='store', type=str, default='/Users/staylor/Research/PapersInProgress/NPDE/gp4ptas/ecc_gp.pkl',
help='Provide the pickle file storing the list of GP objects for when gwbSpecModel is gpEnvInterp or when gwbPrior is gaussProc. Must contain either ecc, stars, or acc in an underscore delimited filename (default = /Users/staylor/Research/PapersInProgress/NPDE/gp4ptas/stars_gaussproc.pkl)')
parser.add_option('--gpKernel', dest='gpKernel', action='store', type=str, default='expsquared',
help='What type of kernel to use in the GP emulator? (default = expsquared)')
parser.add_option('--userOrf', dest='userOrf', action='store', type=str, default=None,
help='Provide your own ORF in a numpy array of shape (npsr,npsr) or (nfreqs,npsr,npsr) (default = None)')
parser.add_option('--pshift', dest='pshift', action='store_true', default=False,
help='Do you want to include random phase shifts in the Fourier design matrices? (default = False)')
parser.add_option('--incCosVar', dest='incCosVar', action='store_true', default=False,
help='Do you want to include GP interpolation uncertainties or cosmic variance in your gpEnvInterp model? (default = False)')
parser.add_option('--incCorr', dest='incCorr', action='store_true', default=False,
help='Do you want to include cross-correlations in the GWB model? (default = False)')
parser.add_option('--gwbTypeCorr', dest='gwbTypeCorr', action='store', type=str, default='spharmAnis',
help='What type of correlated GW signal do you want to model?: custom, spharmAnis, dipoleOrf, modelIndep, pointSrc, clock, gwDisk, psrlocsVary (default = spharmAnis)')
parser.add_option('--gwbModelSelect', dest='gwbModelSelect', action='store_true', default=False,
help='Perform model selection between correlated and uncorrelated GWB model? (default = False)')
parser.add_option('--gwbCorrModWgt', dest='gwbCorrModWgt', action='store', type=float, default=1.0,
help='Provide estimate of Bayes factor in favor of correlated model to get better model mixing (default = 1.0)')
parser.add_option('--corrJacobian', dest='corrJacobian', action='store', type=str, default='simple',
help='What type of Jacobian do you want for the modelIndep ORF element search: simple, full (default = simple)')
parser.add_option('--psrlocsPrior', dest='psrlocsPrior', action='store', type=str, default='normal',
help='What type of prior do you want on the pulsar locations in the psrlocsVary correlation model: normal, uniform (default = normal)')
parser.add_option('--fixPointSrcPhi', dest='fixPointSrcPhi', action='store', type=float, default=None,
help='Fix the azimuthal sky-location (phi) of a stochastic point-source to a particular value (default = \'None\')')
parser.add_option('--fixPointSrcTheta', dest='fixPointSrcTheta', action='store', type=float, default=None,
help='Fix the polar sky-location (theta) of a stochastic point-source to a particular value (default = \'None\')')
parser.add_option('--redSpecModel', dest='redSpecModel', action='store', type=str, default='powerlaw',
help='What kind of spectral model do you want for red timing-noise?: powerlaw, spectrum (default = powerlaw)')
parser.add_option('--dmSpecModel', dest='dmSpecModel', action='store', type=str, default='powerlaw',
help='What kind of spectral model do you want for DM variations?: powerlaw, spectrum (default = powerlaw)')
parser.add_option('--nmodes_dm', dest='nmodes_dm', action='store', type=int, default=0,
help='Number of DM-variation modes in low-rank time-frequency approximation')
parser.add_option('--incEph', dest='incEph', action='store_true', default=False,
help='Do you want to search for solar system ephemeris errors? (default = False)')
parser.add_option('--jplBasis', dest='jplBasis', action='store_true', default=False,
help='Do you want to use the JPL GP basis? (default = False)')
parser.add_option('--ephSpecModel', dest='ephSpecModel', action='store', type=str, default='powerlaw',
help='What kind of spectral model do you want for the solar system ephemeris errors?: powerlaw, spectrum (default = powerlaw)')
parser.add_option('--nmodes_eph', dest='nmodes_eph', action='store', type=int, default=0,
help='Number of ephemeris modes in low-rank time-frequency approximation')
parser.add_option('--ephFreqs', dest='ephFreqs', action='store', type=str, default=None,
help='Provide the ephemeris-error model frequencies [Hz] as a comma delimited string (default = None)')
parser.add_option('--incClk', dest='incClk', action='store_true', default=False,
help='Do you want to search for clock errors? (default = False)')
parser.add_option('--clkDesign', dest='clkDesign', action='store_true', default=False,
help='Do you want to model clock errors in a separate basis from the red-noise and GWB? (default = False)')
parser.add_option('--clkSpecModel', dest='clkSpecModel', action='store', type=str, default='powerlaw',
help='What kind of spectral model do you want for the clock errors?: powerlaw, spectrum (default = powerlaw)')
parser.add_option('--incDip', dest='incDip', action='store_true', default=False,
help='Do you want to search for a cosinusoidal-correlated red process? (default = False)')
parser.add_option('--dipSpecModel', dest='dipSpecModel', action='store', type=str, default='powerlaw',
help='What kind of spectral model do you want for the cosinusoidal process?: powerlaw, spectrum (default = powerlaw)')
parser.add_option('--incBand', dest='incBand', action='store_true', default=False,
help='Do you want to search for radio-band-dependent red-noise? (default = False)')
parser.add_option('--bandSpecModel', dest='bandSpecModel', action='store', type=str, default='powerlaw',
help='What kind of spectral model do you want for the radio-band-dependent red-noise?: powerlaw, spectrum (default = powerlaw)')
parser.add_option('--nmodes_band', dest='nmodes_band', action='store', type=int, default=0,
help='Number of band modes in low-rank time-frequency approximation')
parser.add_option('--bands', dest='bands', action='store', type=str, default=None,
help='Provide the radio-bands for band-noise as a comma delimited string (e.g. [0.0,1.0,2.0,3.0] gives 3 bands) (default = None)')
parser.add_option('--incCm', dest='incCm', action='store_true', default=False,
help='Do you want to search for a common uncorrelated noise process? (default = False)')
parser.add_option('--cmSpecModel', dest='cmSpecModel', action='store', type=str, default='powerlaw',
help='What kind of spectral model do you want for the common noise process?: powerlaw, spectrum (default = powerlaw)')
parser.add_option('--dirExt', dest='dirExt', action='store', type=str, default='./chains_nanoAnalysis/',
help='What master directory name do you want to put this run into? (default = ./chains_nanoAnalysis/)')
parser.add_option('--nwins', dest='nwins', action='store', type=int, default=1,
help='Number windows to split the band into (useful for evolving anisotropy searches (default = 1 windows)')
parser.add_option('--lmax', dest='LMAX', action='store', type=int, default=0,
help='Maximum multipole in anisotropic search (default = 0, i.e. isotropic-search)')
parser.add_option('--noPhysPrior', dest='noPhysPrior', action='store_true', default=False,
help='Switch off test for physicality of anisotropic coefficient sampling (default = False)')
parser.add_option('--use_gpu', dest='use_gpu', action='store_true', default=False,
help='Do you want to use the GPU for accelerated linear algebra? (default = False)')
parser.add_option('--sparse_cholesky', dest='sparse_cholesky', action='store_true', default=False,
help='Do you want to use a sparse cholesky solver? (default = False)')
parser.add_option('--fix_slope', dest='fix_slope', action='store', type=float, default=None,
help='Do you want to fix the slope of the GWB spectrum? (default = None)')
parser.add_option('--gwbAmpRange', dest='gwbAmpRange', action='store', type=str, default=None,
help='Provide a lower and upper log_10(Agwb) range as a comma delimited string (default = None)')
parser.add_option('--gwbAlphaRange', dest='gwbAlphaRange', action='store', type=str, default='7.0,9.0',
help='Provide a lower and upper alpha range as a comma delimited string (default = None)')
parser.add_option('--gwbStarsRange', dest='gwbStarsRange', action='store', type=str, default='1.0,4.0',
help='Provide a lower and upper log_10(rho_stars) range as a comma delimited string (default = None)')
parser.add_option('--gwbEccRange', dest='gwbEccRange', action='store', type=str, default='0.0,0.95',
help='Provide a lower and upper e0 range as a comma delimited string (default = None)')
parser.add_option('--gwbGmuRange', dest='gwbGmuRange', action='store', type=str, default='-25.0,-8.0',
help='Provide a lower and upper log10-Gmu range as a comma delimited string (default = None)')
parser.add_option('--gwbStringProbRange', dest='gwbStringProbRange', action='store', type=str, default='-3.0,0.0',
help='Provide a lower and upper log10-stringprob range as a comma delimited string (default = None)')
parser.add_option('--gwbPrior', dest='gwbPrior', action='store', type=str, default='uniform',
help='Do you want to use a uniform prior on log_10(amplitude) for detection [loguniform], on amplitudes themselves for limits [uniform], an astrophysical prior (only when the amplitude is Agwb: for powerlaw, turnover, gpEnvInterp models) [s13, s16_shankar, s16_korho, mop14, sbs16_mcma, sbs16_korho], or a gaussian process prior [gaussProc] (default=\'uniform\')?')
parser.add_option('--gwbHyperPrior', dest='gwbHyperPrior', action='store', type=str, default='uniform',
help='When gwbPrior=gaussProc, do you want to use a uniform prior on log_10(Agwb) for detection [loguniform], on Agwb itself for limits [uniform], or an astrophysical prior [s13, s16_shankar, s16_korho, mop14, sbs16_mcma, sbs16_korho] (default=\'uniform\')?')
parser.add_option('--gwbGmuPrior', dest='gwbGmuPrior', action='store', type=str, default='uniform',
help='Prior for Gmu in cosmic string GP model: uniform prior on log_10(Gmu) for detection [loguniform], on Gmu itself for limits [uniform] (default=\'uniform\')?')
parser.add_option('--redPrior', dest='redPrior', action='store', type=str, default='uniform',
help='Do you want to use a uniform prior on log_10(Ared) for detection [loguniform], on Ared itself for limits [uniform] (default=\'uniform\')?')
parser.add_option('--dmPrior', dest='dmPrior', action='store', type=str, default='uniform',
help='Do you want to use a uniform prior on log_10(Adm) for detection [loguniform], on Adm itself for limits [uniform] (default=\'uniform\')?')
parser.add_option('--ephPrior', dest='ephPrior', action='store', type=str, default='uniform',
help='Do you want to use a uniform prior on log_10(Aephx,y,z) for detection [loguniform], on Aephx,y,z themselves for limits [uniform] (default=\'uniform\')?')
parser.add_option('--clkPrior', dest='clkPrior', action='store', type=str, default='uniform',
help='Do you want to use a uniform prior on log_10(Aclk) for detection [loguniform], on Aclk itself for limits [uniform] (default=\'uniform\')?')
parser.add_option('--bandPrior', dest='bandPrior', action='store', type=str, default='uniform',
help='Do you want to use a uniform prior on log_10(Aband) for detection [loguniform], on Aband itself for limits [uniform] (default=\'uniform\')?')
parser.add_option('--cmPrior', dest='cmPrior', action='store', type=str, default='uniform',
help='Do you want to use a uniform prior on log_10(Acm) for detection [loguniform], on Acm itself for limits [uniform] (default=\'uniform\')?')
parser.add_option('--dipPrior', dest='dipPrior', action='store', type=str, default='uniform',
help='Do you want to use a uniform prior on log_10(Adip) for detection [loguniform], on Adip itself for limits [uniform] (default=\'uniform\')?')
parser.add_option('--anis_modefile', dest='anis_modefile', action='store', type=str, default = None,
help='Do you want to provide an anisotropy modefile to split band into frequency windows?')
parser.add_option('--noEcorr', dest='noEcorr', action='store_true', default=False,
help='Do you want to ignore correlated white noise terms in noise matrix? (default = False)')
parser.add_option('--fixRed', dest='fixRed', action='store_true', default=False,
help='Do you want to perform a fixed power-law red-noise analysis? (default = False)')
parser.add_option('--fixDM', dest='fixDM', action='store_true', default=False,
help='Do you want to perform a fixed power-law DM-variations analysis? (default = False)')
parser.add_option('--psrStartIndex', dest='psrStartIndex', action='store', type=int, default=0,
help='From your pulsar list, which pulsar index do you want to start with? (default = 0)')
parser.add_option('--psrEndIndex', dest='psrEndIndex', action='store', type=int, default=18,
help='From your pulsar list, which pulsar index do you want to end with? (default = 18)')
parser.add_option('--psrIndices', dest='psrIndices', action='store', type=str, default=None,
help='Provide a sequence of indices from your pulsar list as a comma delimited string (default = None)')
parser.add_option('--det_signal', dest='det_signal', action='store_true', default=False,
help='Do you want to search for a deterministic GW signal? (default = False)')
parser.add_option('--bwm_search', dest='bwm_search', action='store_true', default=False,
help='Do you want to search for GW burst with memory (BWM)? (default = False)')
parser.add_option('--bwm_antenna', dest='bwm_antenna', action='store', type=str, default='quad',
help='What kind of antenna pattern do you want to use for a BWM? (default = quad)')
parser.add_option('--bwm_model_select', dest='bwm_model_select', action='store_true', default=False,
help='Do you want to compute the Bayes Factor for BWM+noise versus noise-only? (default = False)')
parser.add_option('--cgw_search', dest='cgw_search', action='store_true', default=False,
help='Do you want to search for a single continuous GW signal? (default = False)')
parser.add_option('--cgwFreqRange', dest='cgwFreqRange', action='store', type=str, default=None,
help='Provide a lower and upper log_10(f_orb) range as a comma delimited string (default = None)')
parser.add_option('--cgwModelSelect', dest='cgwModelSelect', action='store_true', default=False,
help='Do you want to compute the Bayes factor for CGW+noise versus noise-only? (default = False)')
parser.add_option('--ecc_search', dest='ecc_search', action='store_true', default=False,
help='Do you want to search for an eccentric binary? (default = False)')
parser.add_option('--epochTOAs', dest='epochTOAs', action='store_true', default=False,
help='Do you want to compute CGW waveforms with the averaged TOAs? (default = False)')
parser.add_option('--psrTerm', dest='psrTerm', action='store_true', default=False,
help='Do you want to include the pulsar term in the continuous wave search? (default = False)')
parser.add_option('--periEv', dest='periEv', action='store_true', default=False,
help='Do you want to model the binary periapsis evolution? (default = False)')
parser.add_option('--cgwPrior', dest='cgwPrior', action='store', type=str, default='uniform',
help='By default this puts a [uniform] prior on the strain amplitude, but can also choose [loguniform] on strain amplitude, or [mdloguniform] which puts separate loguniform priors on mass and distance (default = \'uniform\')')
parser.add_option('--fixcgwFreq', dest='fixcgwFreq', action='store', type=float, default=None,
help='Fix the cgw orbital frequency to a particular log10 value (default = \'None\')')
parser.add_option('--fixcgwEcc', dest='fixcgwEcc', action='store', type=float, default=None,
help='Fix the cgw eccentricity to a particular value (default = \'None\')')
parser.add_option('--fixcgwPhi', dest='fixcgwPhi', action='store', type=float, default=None,
help='Fix the cgw azimuthal sky-location (phi) to a particular value (default = \'None\')')
parser.add_option('--fixcgwTheta', dest='fixcgwTheta', action='store', type=float, default=None,
help='Fix the cgw polar sky-location (theta) to a particular value (default = \'None\')')
parser.add_option('--noEccEvolve', dest='noEccEvolve', action='store_true', default=False,
help='Do not allow eccentricity to evolve between pulsar- and Earth-term (default = \'False\')')
parser.add_option('--eph_quadratic', dest='eph_quadratic', action='store_true', default=False,
help='Do you want to include a deterministic quadratic in the ephemeris model? (default = False)')
parser.add_option('--eph_planetdelta', dest='eph_planetdelta', action='store_true', default=False,
help='Do you want to include a deterministic planetary-property perturbation in the ephemeris model? (default = False)')
parser.add_option('--eph_planetmass', dest='eph_planetmass', action='store_true', default=False,
help='Perturb the planetary masses in the Roemer delay correction? (default = False)')
parser.add_option('--which_ephs', dest='which_ephs', action='store', type=str, default='all',
help='Which ephemerides do you want to use in the ephemeris-perturbation models? [fitted, all, DE421, etc.] (default = all)')
parser.add_option('--eph_planetnums', dest='eph_planetnums', action='store', type=str, default=None,
help='Which planets to include in planetary perturbation model [Mercury=1, Venus=2, etc.] (default = None)')
parser.add_option('--eph_planetmassprior', dest='eph_planetmassprior', action='store', type=str, default='official',
help='What kind fo prior do you want to place on the planet masses being perturbed [official, loguniform] (default = official)')
parser.add_option('--eph_planetoffset', dest='eph_planetoffset', action='store_true', default=False,
help='Do you want to search for x,y,z displacements in each planetary orbit? (default = False)')
parser.add_option('--eph_roemermix', dest='eph_roemermix', action='store_true', default=False,
help='Do you want to include a mixture of Roemer delays in the model? (default = False)')
parser.add_option('--eph_roemerwgts_fix', dest='eph_roemerwgts_fix', action='store', type=str, default=None,
help='Manually define the weights of the ephemerides (default = None)')
parser.add_option('--eph_dirichlet_alpha', dest='eph_dirichlet_alpha', action='store', type=float, default=1.0,
help='What value of the dirichlet concentration do you want to use? (default = 1.0)')
parser.add_option('--eph_physmodel', dest='eph_physmodel', action='store_true', default=False,
help='Do you want to use frame rotation, Jupiter+Saturn+Uranus+Neptune mass perturbations, and Jupiter orbit perturbation? (default = False)')
parser.add_option('--incJuporb', dest='incJuporb', action='store_true', default=False,
help='Include Jupiter orbital perturbations in solar-system ephemeris physical model? (default = False)')
parser.add_option('--jup_orbmodel', dest='jup_orbmodel', action='store', type=str, default='orbelements',
help='Which Jupiter orbit perturbation model do you want to use [angles, orbelements]? (default = orbelements)')
parser.add_option('--incSatorb', dest='incSatorb', action='store_true', default=False,
help='Include Saturn orbital perturbations in solar-system ephemeris physical model? (default = False)')
parser.add_option('--sat_orbmodel', dest='sat_orbmodel', action='store', type=str, default='orbelements',
help='Which Saturn orbit perturbation model do you want to use [orbelements]? (default = orbelements)')
parser.add_option('--eph_priorjpl', dest='eph_priorjpl', action='store_true', default=False,
help='Include JPL constraints on Jupiter PCA orbital elements? (default = False)')
parser.add_option('--ephpriorjpl_efac', dest='ephpriorjpl_efac', action='store', type=float, default=1.0,
help='Fudge factor for scaling JPL ephemeris uncertainties (default = 1.0)')
parser.add_option('--eph_roemermix_dx', dest='eph_roemermix_dx', action='store_true', default=False,
help='Do you want to include an arbitrarily-weighted mixture of Roemer delay offsets from the mean? (default = False)')
parser.add_option('--eph_de_rotated', dest='eph_de_rotated', action='store_true', default=False,
help='Do you want to use the rotated ephemerides for consistent ICRF? (default = False)')
parser.add_option('--incGWline', dest='incGWline', action='store_true', default=False,
help='Do you want to include a single-frequency line in the GW spectrum? (default = False)')
parser.add_option('--gwlinePrior', dest='gwlinePrior', action='store', type=str, default='uniform',
help='Do you want to use a uniform prior on log_10(rho_line) for detection [loguniform], on rho_line itself for limits [uniform] (default=\'uniform\')?')
parser.add_option('--constLike', dest='constLike', action='store_true', default=False,
help='Do you want to set the likelihood to a constant and thus sample from the prior? (default = False)')
(args, x) = parser.parse_args()
if args.jsonModel is not None:
with open(args.jsonModel) as json_file:
json_data = json.load(json_file)
json_file.close()
args.from_h5 = json_data['from_h5']
args.psrlist = json_data['psrlist']
args.nmodes = json_data['nmodes']
args.cadence = json_data['cadence']
args.incDM = json_data['incDM']
args.sampler = json_data['sampler']
args.writeHotChains = json_data['writeHotChains']
args.resume = json_data['resume']
args.incGWB = json_data['incGWB']
args.gwbSpecModel = json_data['gwbSpecModel']
args.gpPickle = json_data['gpPickle']
args.userOrf = json_data['userOrf']
args.pshift = json_data['pshift']
args.incCosVar = json_data['incCosVar']
args.incCorr = json_data['incCorr']
args.gwbTypeCorr = json_data['gwbTypeCorr']
args.redSpecModel = json_data['redSpecModel']
args.dmSpecModel = json_data['dmSpecModel']
args.dirExt = json_data['dirExt']
args.nwins = json_data['nwins']
args.LMAX = json_data['LMAX']
args.noPhysPrior = json_data['noPhysPrior']
args.use_gpu = json_data['use_gpu']
args.fix_slope = json_data['fixSlope']
args.gwbPrior = json_data['gwbPrior']
args.gwbHyperPrior = json_data['gwbHyperPrior']
args.redPrior = json_data['redPrior']
args.dmPrior = json_data['dmPrior']
args.ephPrior = json_data['ephPrior']
args.clkPrior = json_data['clkPrior']
args.cmPrior = json_data['cmPrior']
args.anis_modefile = json_data['anis_modefile']
args.noEcorr = json_data['noEcorr']
args.fixRed = json_data['fixRed']
args.fixDM = json_data['fixDM']
args.incEph = json_data['incEph']
args.ephSpecModel = json_data['ephSpecModel']
args.incClk = json_data['incClk']
args.clkSpecModel = json_data['clkSpecModel']
args.incCm = json_data['incCm']
args.cmSpecModel = json_data['cmSpecModel']
args.psrStartIndex = json_data['psrStartIndex']
args.psrEndIndex = json_data['psrEndIndex']
args.psrIndices = json_data['psrIndices']
args.det_signal = json_data['det_signal']
args.bwm_search = json_data['bwm_search']
args.bwm_antenna = json_data['bwm_antenna']
args.bwm_model_select = json_data['bwm_model_select']
args.cgw_search = json_data['cgw_search']
args.ecc_search = json_data['ecc_search']
args.epochTOAs = json_data['epochTOAs']
args.psrTerm = json_data['psrTerm']
args.periEv = json_data['periEv']
args.cgwPrior = json_data['cgwPrior']
args.fixcgwFreq = json_data['fixcgwFreq']
args.fixcgwEcc = json_data['fixcgwEcc']
args.fixcgwPhi = json_data['fixcgwPhi']
args.fixcgwTheta = json_data['fixcgwTheta']
args.noEccEvolve = json_data['noEccEvolve']
args.incGWline = json_data['incGWline']
args.gwlinePrior = json_data['gwlinePrior']
args.constLike = json_data['constLike']
header = """\
/$$ /$$ /$$ /$$ /$$$$$$ /$$
| $$$ | $$| $$ / $$ /$$$_ $$ /$$$$ ________________ _
| $$$$| $$| $$/ $$/| $$$$\ $$|_ $$ \__(=======/_=_/____.--'-`--.___
| $$ $$ $$ \ $$$$/ | $$ $$ $$ | $$ \ \ `,--,-.___.----'
| $$ $$$$ >$$ $$ | $$\ $$$$ | $$ .--`\\--'../
| $$\ $$$ /$$/\ $$| $$ \ $$$ | $$ '---._____.|]
| $$ \ $$| $$ \ $$| $$$$$$/ /$$$$$$
|__/ \__/|__/ |__/ \______/ |______/
____ ____ ______ __ __ __ __ ___ ____ ____ _______
\ \ / / / __ \ | | | | | | | | / \ \ \ / / | ____|
\ \/ / | | | | | | | | | |__| | / ^ \ \ \/ / | |__
\_ _/ | | | | | | | | | __ | / /_\ \ \ / | __|
| | | `--' | | `--' | | | | | / _____ \ \ / | |____
|__| \______/ \______/ |__| |__| /__/ \__\ \__/ |_______|
.___________. __ __ _______ ______ ______ .__ __. .__ __.
| || | | | | ____| / | / __ \ | \ | | | \ | |
`---| |----`| |__| | | |__ | ,----'| | | | | \| | | \| |
| | | __ | | __| | | | | | | | . ` | | . ` |
| | | | | | | |____ | `----.| `--' | | |\ | | |\ |
|__| |__| |__| |_______| \______| \______/ |__| \__| |__| \__|
"""
if rank == 0:
print header
nxdir = os.path.realpath(__file__).split('/NX01_master.py')[0]
# Do you want to use GPU acceleration?
if args.use_gpu:
import pycuda.autoinit
from pycuda.compiler import SourceModule
import pycuda.gpuarray as gpuarray
import pycuda.driver as drv
import pycuda.elementwise as el
import pycuda.tools as tools
import scikits.cuda.linalg as culinalg
import scikits.cuda.misc as cumisc
culinalg.init()
if args.sparse_cholesky:
import scipy.sparse as sps
import sksparse.cholmod as sks
if args.sampler == 'mnest':
import pymultinest
elif args.sampler == 'pchord':
import pypolychord
elif args.sampler == 'ptmcmc':
import PTMCMCSampler
from PTMCMCSampler import PTMCMCSampler as ptmcmc
#########################################################################
# PASSING THROUGH TEMPO2 VIA libstempo
#########################################################################
if args.psrlist is not None:
# name, hdf5-path, par-path, tim-path
psr_pathinfo = np.genfromtxt(args.psrlist, dtype=str, skip_header=2)
if args.from_h5:
tmp_psr = []
if args.psrIndices is not None:
psr_inds = [int(item) for item in args.psrIndices.split(',')]
for ii,tmp_name in zip(psr_inds,psr_pathinfo[psr_inds,0]):
tmp_psr.append(h5.File(psr_pathinfo[ii,1], 'r')[tmp_name])
else:
for ii,tmp_name in enumerate(psr_pathinfo[args.psrStartIndex:args.psrEndIndex,0],
start=args.psrStartIndex):
tmp_psr.append(h5.File(psr_pathinfo[ii,1], 'r')[tmp_name])
psr = [NX01_psr.PsrObjFromH5(p) for p in tmp_psr]
else:
print 'Are you sure you do not want to use hdf5 files (recommended)?'
## Performing a single pulsar analysis
t2psr=[]
if args.parfile is not None and args.timfile is not None:
t2psr.append( T2.tempopulsar(parfile=args.parfile,
timfile=args.timfile,
maxobs=int(4e4), ephem=args.ephem) )
if args.fitIters > 0:
t2psr[0].fit(iters=args.fitIters)
if np.any(~np.isfinite(t2psr[0].residuals())):
t2psr[0] = T2.tempopulsar(parfile=args.parfile,
timfile=args.timfile,
maxobs=int(4e4), ephem=args.ephem)
else:
for ii in range(args.psrStartIndex,args.psrEndIndex):
t2psr.append( T2.tempopulsar( parfile=psr_pathinfo[ii,2],
timfile=psr_pathinfo[ii,3],
maxobs=int(4e4), ephem=args.ephem ) )
if args.fitIters > 0:
t2psr[ii].fit(iters=args.fitIters)
if np.any(~np.isfinite(t2psr[ii].residuals())):
t2psr[ii] = T2.tempopulsar( parfile=psr_pathinfo[ii,2],
timfile=psr_pathinfo[ii,3],
maxobs=int(4e4), ephem=args.ephem )
psr = [NX01_psr.PsrObj(p) for p in t2psr]
# Grab all the pulsar quantities
if args.psrlist is not None:
if args.varyWhite:
[p.grab_all_vars(rescale=False, sysflag_target=args.sysflag_target) for p in psr]
elif not args.varyWhite:
[p.grab_all_vars(rescale=True, sysflag_target=args.sysflag_target) for p in psr]
elif args.parfile is not None and args.timfile is not None:
[p.grab_all_vars(jitterbin=args.jitterbin, makeGmat=False,
fastDesign=not(args.svdDesign), planetssb=args.grab_planets) for p in psr]
# Now, grab the positions and compute the ORF basis functions
psr_positions = [np.array([psr[ii].psr_locs[0],
np.pi/2. - psr[ii].psr_locs[1]])
for ii in range(len(psr))]
positions = np.array(psr_positions).copy()
num_corr_params = 0
evol_corr_tag = ''
if args.incGWB and args.incCorr:
if args.gwbTypeCorr == 'modelIndep':
gwfreqs_per_win = int(1.*args.nmodes/(1.*args.nwins))
corr_modefreqs = np.arange(1,args.nmodes+1)
corr_modefreqs = np.reshape(corr_modefreqs,
(args.nwins,gwfreqs_per_win))
tmp_nwins = args.nwins
num_corr_params = tmp_nwins*int(len(psr)*(len(psr)-1)/2)
if tmp_nwins>1:
evol_corr_tag = '_evanis'
else:
evol_corr_tag = ''
elif args.gwbTypeCorr == 'pointSrc':
gwfreqs_per_win = int(1.*args.nmodes/(1.*args.nwins))
corr_modefreqs = np.arange(1,args.nmodes+1)
corr_modefreqs = np.reshape(corr_modefreqs,
(args.nwins,gwfreqs_per_win))
tmp_nwins = args.nwins
if args.fixPointSrcPhi is not None and args.fixPointSrcTheta is not None:
num_corr_params = 0
else:
num_corr_params = 2*tmp_nwins
if tmp_nwins>1:
evol_corr_tag = '_evanis'
else:
evol_corr_tag = ''
elif args.gwbTypeCorr == 'spharmAnis':
# Computing all the correlation basis-functions for the array.
CorrCoeff = np.array(anis.CorrBasis(positions,args.LMAX))
# Computing the values of the spherical-harmonics up to order
# LMAX on a pre-specified grid
harm_sky_vals = utils.SetupPriorSkyGrid(args.LMAX)
if args.anis_modefile is None:
# getting the number of GW frequencies per window
gwfreqs_per_win = int(1.*args.nmodes/(1.*args.nwins))
corr_modefreqs = np.arange(1,args.nmodes+1)
corr_modefreqs = np.reshape(corr_modefreqs,
(args.nwins,gwfreqs_per_win))
tmp_nwins = args.nwins
else:
tmp_modefreqs = np.loadtxt(args.anis_modefile, skiprows=2)
tmp_nwins = tmp_modefreqs.shape[0]
corr_modefreqs = []
for ii in range(tmp_nwins):
corr_modefreqs.append(np.arange(tmp_modefreqs[ii,0],
tmp_modefreqs[ii,1]+1))
num_corr_params = tmp_nwins*(((args.LMAX+1)**2)-1)
# Create a tag for evolving anisotropy searches
if (args.LMAX!=0) and (tmp_nwins > 1):
evol_corr_tag = '_evanis'
else:
evol_corr_tag = ''
elif args.gwbTypeCorr == 'dipoleOrf':
monoOrf = 2.0*np.sqrt(np.pi)*anis.CorrBasis(positions,0)[0]
gwfreqs_per_win = int(1.*args.nmodes/(1.*args.nwins))
corr_modefreqs = np.arange(1,args.nmodes+1)
corr_modefreqs = np.reshape(corr_modefreqs,
(args.nwins,gwfreqs_per_win))
tmp_nwins = args.nwins
num_corr_params = 3*tmp_nwins
if tmp_nwins>1:
evol_corr_tag = '_evanis'
else:
evol_corr_tag = ''
elif args.gwbTypeCorr == 'gwDisk':
tmp_nwins = args.nwins
try:
import healpy as hp
import AnisCoefficients_pix as pixAnis
num_corr_params = 4*tmp_nwins
npsrs = len(positions)
pphi = positions[:,0]
ptheta = positions[:,1]
# Create the pixels
nside=32
npixels = hp.nside2npix(32)
pixels = hp.pix2ang(nside, np.arange(npixels), nest=False)
gwtheta = pixels[0]
gwphi = pixels[1]
# Create the signal response matrix
F_e = pixAnis.signalResponse_fast(ptheta, pphi, gwtheta, gwphi)
except ImportError:
print "ERROR: Could not import healpy!"
print "WARNING: Defaulting to H&D search..."
hp = None
monoOrf = 2.0*np.sqrt(np.pi)*anis.CorrBasis(positions,0)[0]
num_corr_params = 0
gwfreqs_per_win = int(1.*args.nmodes/(1.*args.nwins))
corr_modefreqs = np.arange(1,args.nmodes+1)
corr_modefreqs = np.reshape(corr_modefreqs,
(args.nwins,gwfreqs_per_win))
if tmp_nwins>1:
evol_corr_tag = '_evanis'
else:
evol_corr_tag = ''
elif args.gwbTypeCorr == 'custom':
if args.userOrf is None:
print "WARNING: You requested a custom ORF but" \
" didn't give me an array file!"
print "WARNING: Proceeding with Hellings and Downs..."
customOrf = 2.0*np.sqrt(np.pi)*anis.CorrBasis(positions,0)[0]
elif args.userOrf is not None:
if args.userOrf.split('.')[-1] != 'npy':
print "You are supplying custom pulsar positions, " \
"possibly scrambled!"
custom_positions = np.genfromtxt(args.userOrf,dtype=str,comments='#')
custom_positions = np.double(custom_positions[:,1:])
if len(custom_positions)!=len(psr):
print "ERROR: Number of custom pulsar positions does not match " \
"the number of hdf5 files you gave me!"
print "ERROR: Proceeding with Hellings and Downs instead!"
customOrf = 2.0*np.sqrt(np.pi)*anis.CorrBasis(positions,0)[0]
elif len(custom_positions)==len(psr):
customOrf = 2.0*np.sqrt(np.pi)*anis.CorrBasis(custom_positions,0)[0]
elif args.userOrf.split('.')[-1] == 'npy':
loadOrf = np.load(args.userOrf)
if np.atleast_3d(loadOrf.T).shape[-1]>1:
print "You have given me ORFs for all frequencies!"
else:
print "You have given me a broadband ORF!"
if (np.atleast_3d(loadOrf.T).shape[0]==len(psr) and
np.atleast_3d(loadOrf.T).shape[1]==len(psr)):
print "Dimensions match number of pulsars...OK!"
customOrf = loadOrf
else:
print "ERROR: Dimensions don't match number of pulsars!"
print "ERROR: Proceeding with Hellings and Downs instead!"
customOrf = 2.0*np.sqrt(np.pi)*anis.CorrBasis(positions,0)[0]
num_corr_params = 0
elif args.gwbTypeCorr == 'psrlocsVary':
gwfreqs_per_win = int(1.*args.nmodes/(1.*args.nwins))
corr_modefreqs = np.arange(1,args.nmodes+1)
corr_modefreqs = np.reshape(corr_modefreqs,
(args.nwins,gwfreqs_per_win))
tmp_nwins = args.nwins
num_corr_params = 2*len(psr)*tmp_nwins
if tmp_nwins>1:
evol_corr_tag = '_evanis'
else:
evol_corr_tag = ''
elif args.gwbTypeCorr == 'clock':
gwfreqs_per_win = args.nmodes
corr_modefreqs = np.arange(1,args.nmodes+1)
corr_modefreqs = np.reshape(corr_modefreqs,
(args.nwins,gwfreqs_per_win))
tmp_nwins = args.nwins
num_corr_params = 0
elif args.gwbTypeCorr == 'ssephem':
gwfreqs_per_win = args.nmodes
corr_modefreqs = np.arange(1,args.nmodes+1)
corr_modefreqs = np.reshape(corr_modefreqs,
(args.nwins,gwfreqs_per_win))
tmp_nwins = args.nwins
num_corr_params = 0
# Creating correlation matrix for Cosinusoidal process
if args.incDip and args.incCorr:
npsrs = len(positions)
psr_posvec = np.array([np.sin(positions[:,1]) * np.cos(positions[:,0]),
np.sin(positions[:,1]) * np.sin(positions[:,0]),
np.cos(positions[:,1])]).T
DipoleCorr = np.dot(psr_posvec, psr_posvec.T)
if DipoleCorr.shape != (npsrs,npsrs):
print "ERROR: Cosinusoidal-process correlation matrix is not the right shape!"
#############################################################################
# GETTING MAXIMUM TIME, COMPUTING FOURIER DESIGN MATRICES, AND GETTING MODES
#############################################################################
if args.TmaxType == 'pta':
Tmax = np.max([p.toas.max() for p in psr]) - \
np.min([p.toas.min() for p in psr])
Tmax *= 86400.0
else:
Tmax = np.max([p.toas.max() - p.toas.min() for p in psr])
Tmax *= 86400.0
### Define number of red noise modes and set sampling frequencies
if args.nmodes is not None:
nmodes_red = args.nmodes + args.nmodes_log
elif args.nmodes is None and args.cadence is not None:
nmodes_red = int(round(0.5 * Tmax / (args.cadence * 86400.0))) + args.nmodes_log
fqs_red, wgts_red = rr.linBinning(Tmax, args.logmode, 1 / args.fmin / Tmax,
nmodes_red-args.nmodes_log, args.nmodes_log)
### Define number of DM-variation modes and set sampling frequencies
nmodes_dm = args.nmodes_dm + args.nmodes_log
fqs_dm, wgts_dm = None, None
if args.incDM:
if args.nmodes_dm > 0:
nmodes_dm = args.nmodes_dm + args.nmodes_log
else:
nmodes_dm = nmodes_red
fqs_dm, wgts_dm = rr.linBinning(Tmax, args.logmode, 1 / args.fmin / Tmax,
nmodes_dm-args.nmodes_log, args.nmodes_log)
### Define number of ephemeris-error modes and set sampling frequencies
nmodes_eph = None
fqs_eph, wgts_eph = None, None
if args.incEph:
if args.jplBasis:
# No sampling frequencies here.
# Basis is in planet mass perturbations.
nmodes_eph = 7
ephPhivec = np.load(nxdir+'/data/jplephbasis/phivec.npy')
else:
nmodes_eph = args.nmodes_eph
if args.nmodes_eph > 0:
nmodes_eph = args.nmodes_eph + args.nmodes_log
else:
nmodes_eph = nmodes_red
##
if args.ephFreqs is None:
fqs_eph, wgts_eph = rr.linBinning(Tmax, args.logmode, 1 / args.fmin / Tmax,
nmodes_eph-args.nmodes_log, args.nmodes_log)
elif args.ephFreqs is not None:
fqs_eph = np.array([float(item) for item in args.ephFreqs.split(',')])
wgts_eph = np.ones(len(args.ephFreqs.split(',')))
### Define number of band-noise modes and set sampling frequencies
nmodes_band = args.nmodes_band
fqs_band, wgts_band = None, None
if args.incBand:
if args.nmodes_band > 0:
nmodes_band = args.nmodes_band + args.nmodes_log
else:
nmodes_band = nmodes_red
fqs_band, wgts_band = rr.linBinning(Tmax, args.logmode, 1 / args.fmin / Tmax,
nmodes_band-args.nmodes_log, args.nmodes_log)
if args.bands is None:
bands = np.array([0.0, 1.0, 2.0, 3.0])
elif args.bands is not None:
bands = np.array([float(item) for item in args.bands.split(',')])
#############################################################################
# DEFINING A UNIQUE FILE TAG FOR BOOK-KEEPING
#############################################################################
file_tag = 'pta'
if args.constLike:
file_tag += '_constLike'
if args.incGWB:
if args.gwbSpecModel == 'powerlaw':
if args.fix_slope is not None:
gamma_tag = '_gam'+str(args.fix_slope)
else:
gamma_tag = '_gamVary'
elif args.gwbSpecModel == 'spectrum':
gamma_tag = '_gwbSpec'
if args.gwbPrior == 'gaussProc':
gamma_tag += gwb_popparam+'Hyper{0}'.format(args.gwbHyperPrior)
elif args.gwbSpecModel == 'turnover':
gamma_tag = '_gwbTurn'
if args.gwb_fb2env is not None:
gamma_tag += 'fb2env'+args.gwb_fb2env
elif args.gwbSpecModel == 'gpEnvInterp':
gamma_tag = '_gwbGP'+gwb_popparam
if args.incCosVar:
gamma_tag += 'cosvar'
if args.incCorr:
if args.gwbTypeCorr == 'modelIndep':
file_tag += '_gwb{0}_miCorr{1}{2}'.format(args.gwbPrior,
evol_corr_tag,gamma_tag)
elif args.gwbTypeCorr == 'pointSrc':
if args.fixPointSrcPhi is not None and args.fixPointSrcTheta is not None:
dummy_fixpsrc = 'Fix'
else:
dummy_fixpsrc = ''
file_tag += '_gwb{0}_pntSrc{1}{2}{3}'.format(args.gwbPrior,dummy_fixpsrc,
evol_corr_tag,gamma_tag)
elif args.gwbTypeCorr == 'spharmAnis':
if args.noPhysPrior:
physprior_tag = '_noPhysPrior'
elif not args.noPhysPrior:
physprior_tag = ''
file_tag += '_gwb{0}_Lmax{1}{2}{3}{4}'.format(args.gwbPrior,
args.LMAX,physprior_tag,
evol_corr_tag,gamma_tag)
elif args.gwbTypeCorr == 'dipoleOrf':
file_tag += '_gwb{0}_dip{1}{2}'.format(args.gwbPrior,
evol_corr_tag,gamma_tag)
elif args.gwbTypeCorr == 'clock':
file_tag += '_gwb{0}_fulcorr{1}{2}'.format(args.gwbPrior,
evol_corr_tag,gamma_tag)
elif args.gwbTypeCorr == 'ssephem':
file_tag += '_gwb{0}_ssephem{1}{2}'.format(args.gwbPrior,
evol_corr_tag,gamma_tag)
elif args.gwbTypeCorr == 'custom':
file_tag += '_gwb{0}_cstmOrf{1}{2}'.format(args.gwbPrior,
evol_corr_tag,gamma_tag)
elif args.gwbTypeCorr == 'gwDisk':
file_tag += '_gwb{0}_gwDisk{1}{2}'.format(args.gwbPrior,
evol_corr_tag,gamma_tag)
elif args.gwbTypeCorr == 'psrlocsVary':
file_tag += '_gwb{0}_psrlocVar{1}{2}'.format(args.gwbPrior,
evol_corr_tag,gamma_tag)
if args.gwbModelSelect:
file_tag += 'ModSct'
else:
if args.gwbSpecModel == 'powerlaw':
if args.fix_slope is not None:
gamma_tag = '_gam'+str(args.fix_slope)
else:
gamma_tag = '_gamVary'
file_tag += '_gwb{0}_noCorr{1}'.format(args.gwbPrior,gamma_tag)
if args.pshift:
file_tag += '_pshift'
if args.incGWline:
if args.incCorr:
file_tag += '_gwline{0}'.format(args.gwlinePrior)
elif not args.incCorr:
file_tag += '_gwline{0}_noCorr'.format(args.gwlinePrior)
if args.det_signal:
if args.cgw_search:
cgwtag = ''
if args.fixcgwFreq is not None:
cgwtag += 'fixFreq'
if args.fixcgwPhi is not None:
cgwtag += 'fixPhi'
if args.fixcgwTheta is not None:
cgwtag += 'fixTheta'
if args.ecc_search:
if args.fixcgwEcc is not None:
cgwtag += 'fixEcc'
file_tag += '_ecgw'+args.cgwPrior+cgwtag
else:
file_tag += '_ccgw'+args.cgwPrior+cgwtag
if args.psrTerm:
file_tag += 'psrTerm'
if args.cgwModelSelect:
file_tag += 'ModSct'
if args.bwm_search:
file_tag += '_bwm'+args.bwm_antenna
if args.bwm_model_select:
file_tag += 'ModSct'
if args.eph_quadratic:
file_tag += '_ephquad'
if args.eph_planetdelta:
if args.eph_planetmass:
file_tag += '_ephplanetmass'+args.eph_planetmassprior
if args.eph_planetoffset:
file_tag += '_ephorbitoffset'
elif args.eph_roemermix:
if args.eph_roemerwgts_fix is None:
file_tag += '_ephroemermix'+str(args.eph_dirichlet_alpha)
elif args.eph_roemerwgts_fix is not None:
file_tag += '_ephroemermixFix'
if args.eph_de_rotated:
file_tag += '_derotate'
elif args.eph_physmodel:
file_tag += '_ephphysmodel'
if args.eph_priorjpl:
file_tag += 'priorJpl'+str(args.ephpriorjpl_efac)
elif args.eph_roemermix_dx:
file_tag += '_ephroemermix_dx'
if args.eph_de_rotated:
file_tag += '_derotate'
if args.fixRed:
red_tag = '_redFix'+'nm{0}'.format(nmodes_red)
elif not args.fixRed:
red_tag = '_red'+args.redPrior+args.redSpecModel+'nm{0}'.format(nmodes_red)
if args.incDM:
if args.fixDM:
dm_tag = 'dmFix'+'nm{0}'.format(nmodes_dm)
elif not args.fixDM:
dm_tag = '_dm'+args.dmPrior+args.dmSpecModel+'nm{0}'.format(nmodes_dm)
elif not args.incDM:
dm_tag = ''
if args.varyWhite:
file_tag += '_varyWhite'
if args.incBand:
band_tag = '_band'+args.bandPrior+args.bandSpecModel+'nm{0}'.format(nmodes_band)