8
8
import matplotlib as mpl
9
9
mpl .use ('agg' )
10
10
import matplotlib .pyplot as plt
11
+ import pickle
11
12
12
13
from .FastResponseAnalysis import PriorFollowup
13
14
from .reports import GravitationalWaveReport
@@ -47,17 +48,13 @@ def run_background_trials(self, month=None, ntrials=1000):
47
48
from scipy import sparse
48
49
current_rate = self .llh .nbackground / (self .duration * 86400. ) * 1000.
49
50
50
- #TODO: replace here once done
51
- #closest_rate = sensitivity_utils.find_nearest(np.linspace(6.0, 7.2, 7), current_rate)
52
- rates = [6.0 ,6.2 ,6.4 ,6.8 ,7.0 ]
53
- closest_rate = sensitivity_utils .find_nearest (rates , current_rate )
51
+ closest_rate = sensitivity_utils .find_nearest (np .linspace (6.0 , 7.2 , 7 ), current_rate )
54
52
print (f'Loading 2 week bg trials, rate: { closest_rate } ' )
55
53
56
- #bg_trial_dir = '/data/ana/analyses/NuSources/' \
57
- # + '2023_realtime_gw_analysis/fast_response/' \
58
- # + 'precomputed_background/'
59
- #TODO: change to permanent storage once assigned
60
- bg_trial_dir = '/data/user/jthwaites/FastResponseAnalysis/output/trials/glob_trials/'
54
+ bg_trial_dir = '/data/ana/analyses/NuSources/' \
55
+ + '2023_realtime_gw_analysis/fast_response/' \
56
+ + 'precomputed_background/'
57
+
61
58
pre_ts_array = sparse .load_npz (
62
59
bg_trial_dir
63
60
+ 'gw_precomputed_trials_delta_t_'
@@ -188,7 +185,60 @@ def initialize_llh(self, skipped=None, scramble=False):
188
185
llh .set_temporal_model (box )
189
186
190
187
return llh
188
+
189
+ def get_best_fit_contour (self , proportions = [0.5 ,0.9 ]):
190
+ '''Get a contour for the error around the best-fit point
191
+ proportions = confidence levels to calculate
192
+ -------
193
+ Makes a zoomed skymap of the ts-space with contours
194
+ '''
195
+ if self .tsd is None : return
196
+
197
+ from . import plotting_utils
198
+ #import meander
199
+ import seaborn as sns
200
+
201
+ print ('Calculating contour around best-fit TS' )
202
+
203
+ #get threshold TS value for that level in the bg distribution
204
+ levels = [np .percentile (self .tsd , 100 * (1 - proportion )) for proportion in proportions ]
205
+ sample_points = np .array (hp .pix2ang (self .nside , np .arange (len (self .skymap )))).T
206
+ loc = np .array ((np .pi / 2 - self .ts_scan ['dec' ], self .ts_scan ['ra' ])).T
207
+ contours_by_level = meander .spherical_contours (loc , self .ts_scan ['TS_spatial_prior_0' ], levels )
208
+ #print(contours_by_level)
209
+
210
+ thetas = []; phis = []
211
+ for contours in contours_by_level :
212
+ for contour in contours :
213
+ theta , phi = contour .T
214
+ phi [phi < 0 ] += 2.0 * np .pi
215
+ thetas .append (theta )
216
+ phis .append (phi )
217
+
218
+ #norm_ts = self.ts_scan['TS_spatial_prior_0'] / sum(self.ts_scan['TS_spatial_prior_0'])
219
+ #thetas, phis = plotting_utils.plot_contours(proportions, norm_ts)
220
+
221
+ #make the plot
222
+ pdf_palette = sns .color_palette ("Blues" , 500 )
223
+ cmap = mpl .colors .ListedColormap (pdf_palette )
224
+
225
+ plotting_utils .plot_zoom (self .ts_scan ['TS_spatial_prior_0' ], self .skymap_fit_ra , self .skymap_fit_dec ,
226
+ "" , range = [0 ,10 ], reso = 3. , cmap = cmap )
227
+
228
+ plotting_utils .plot_color_bar (range = [0 ,6 ], cmap = cmap , col_label = r"TS" ,offset = - 50 )
229
+ cont_ls = ['solid' , 'dashed' ]* (int (len (proportions )/ 2 ))
230
+ cont_labels = [f'{ proportion * 100 :.0f} /% CL' for proportion in proportions ]
231
+
232
+ for i in range (len (thetas )):
233
+ hp .projplot (thetas [i ], phis [i ], linewidth = 2. , c = 'k' )#, ls=cont_ls[i], label=cont_labels[i])
191
234
235
+ plt .scatter (0 ,0 , marker = '*' , c = 'k' , s = 130 , label = "Scan Hot Spot" )
236
+ plt .legend (loc = 2 , ncol = 1 , fontsize = 16 , framealpha = 0.95 )
237
+
238
+ plt .savefig (self .analysispath + '/' + self .analysisid + 'ts_contours.png' ,bbox_inches = 'tight' )
239
+ plt .savefig (self .analysispath + '/' + self .analysisid + 'ts_contours.pdf' ,bbox_inches = 'tight' , dpi = 300 )
240
+ plt .close ()
241
+
192
242
def plot_ontime (self , with_contour = True , contour_files = None ):
193
243
return super ().plot_ontime (with_contour = True , contour_files = contour_files )
194
244
@@ -410,15 +460,22 @@ def ps_sens_range(self):
410
460
--------
411
461
low: float
412
462
lowest sensitivity within dec range
413
- high: floaot
463
+ high: float
414
464
highest sensitivity wihtin dec range
415
465
'''
416
- dec_range = np .linspace (- 85 ,85 ,35 )
417
- sens = [1.15 , 1.06 , .997 , .917 , .867 , .802 , .745 , .662 ,
418
- .629 , .573 , .481 , .403 , .332 , .250 , .183 , .101 ,
419
- .035 , .0286 , .0311 , .0341 , .0361 , .0394 , .0418 ,
420
- .0439 , .0459 , .0499 , .0520 , .0553 , .0567 , .0632 ,
421
- .0679 , .0732 , .0788 , .083 , .0866 ]
466
+ sens_dir = '/data/ana/analyses/NuSources/2023_realtime_gw_analysis/' \
467
+ + 'fast_response/ps_sensitivities'
468
+
469
+ with open (f'{ sens_dir } /ps_sensitivities_deltaT_{ self .duration * 86400. :.2e} s.pkl' ,'rb' ) as f :
470
+ saved_sens = pickle .load (f )
471
+ dec_range = saved_sens ['dec' ]
472
+ sens = saved_sens ['sens_flux' ]
473
+ #dec_range = np.linspace(-85,85,35)
474
+ #sens = [1.15, 1.06, .997, .917, .867, .802, .745, .662,
475
+ # .629, .573, .481, .403, .332, .250, .183, .101,
476
+ # .035, .0286, .0311, .0341, .0361, .0394, .0418,
477
+ # .0439, .0459, .0499, .0520, .0553, .0567, .0632,
478
+ # .0679, .0732, .0788, .083, .0866]
422
479
423
480
src_theta , src_phi = hp .pix2ang (self .nside , self .ipix_90 )
424
481
src_dec = np .pi / 2. - src_theta
@@ -477,13 +534,19 @@ def make_dec_pdf(self):
477
534
478
535
sinDec_bins = np .linspace (- 1 ,1 ,30 )
479
536
bin_centers = (sinDec_bins [:- 1 ] + sinDec_bins [1 :]) / 2
480
-
481
- dec_range = np .linspace (- 1 ,1 ,35 )
482
- sens = [1.15 , 1.06 , .997 , .917 , .867 , .802 , .745 , .662 ,
483
- .629 , .573 , .481 , .403 , .332 , .250 , .183 , .101 ,
484
- .035 , .0286 , .0311 , .0341 , .0361 , .0394 , .0418 ,
485
- .0439 , .0459 , .0499 , .0520 , .0553 , .0567 , .0632 ,
486
- .0679 , .0732 , .0788 , .083 , .0866 ]
537
+ sens_dir = '/data/ana/analyses/NuSources/2023_realtime_gw_analysis/' \
538
+ + 'fast_response/ps_sensitivities'
539
+ with open (f'{ sens_dir } /ps_sensitivities_deltaT_{ self .duration * 86400. :.2e} s.pkl' ,'rb' ) as f :
540
+ saved_sens = pickle .load (f )
541
+ dec_range = np .sin (saved_sens ['dec' ]* np .pi / 180 )
542
+ sens = saved_sens ['sens_flux' ]
543
+
544
+ #dec_range = np.linspace(-1,1,35)
545
+ #sens = [1.15, 1.06, .997, .917, .867, .802, .745, .662,
546
+ # .629, .573, .481, .403, .332, .250, .183, .101,
547
+ # .035, .0286, .0311, .0341, .0361, .0394, .0418,
548
+ # .0439, .0459, .0499, .0520, .0553, .0567, .0632,
549
+ # .0679, .0732, .0788, .083, .0866]
487
550
sens = np .array (sens )
488
551
489
552
pixels = np .arange (len (self .skymap ))
@@ -530,5 +593,8 @@ def generate_report(self):
530
593
r'''Generates report using class attributes
531
594
and the ReportGenerator Class'''
532
595
report = GravitationalWaveReport (self )
596
+ if self .duration > 1. :
597
+ report ._figure_list = [('decPDF' , 'decPDF.png' ),('ts_contours' , 'ts_contours.png' )]
598
+
533
599
report .generate_report ()
534
600
report .make_pdf ()
0 commit comments