forked from sPaMFouR/RedPipe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlotLightCurve_7.py
1305 lines (1061 loc) · 62.3 KB
/
PlotLightCurve_7.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
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx #
# xxxxxxxxxxxxxx--------------PLOT THE SUPERNOVA LIGHT CURVES FROM INPUT MAGNITUDE FILES--------------xxxxxxxxxxxxxxx #
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx #
# ------------------------------------------------------------------------------------------------------------------- #
# Import Required Libraries
# ------------------------------------------------------------------------------------------------------------------- #
import os
import re
import glob
import math
import pwlf
import numpy as np
import pandas as pd
from datetime import date
import matplotlib.pyplot as plt
from jdcal import jd2gcal, gcal2jd
from matplotlib.ticker import MultipleLocator
from scipy.optimize import curve_fit, minimize
from astropy.modeling.blackbody import blackbody_lambda
from scipy.interpolate import CubicSpline, UnivariateSpline
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Global Variables To Be Used In The Code
# ------------------------------------------------------------------------------------------------------------------- #
precision = 3
fmt_flt = '{0:>7.3f}'
fmt_exp = '{0:>7.4e}'
epoch_mjd = 2400000.5
solar_rad = 6.957e10
Rv = 3.1
wave_data = np.linspace(3100, 9200, 1000)
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Paths Of Directories
# ------------------------------------------------------------------------------------------------------------------- #
file_photvel = 'OUTPUT_PhotVel'
DIR_CURNT = os.getcwd()
DIR_SNe = "/home/avinash/Dropbox/SNData/IIP_Data/"
DIR_SPEC = '/home/avinash/Supernovae_Data/2016gfy/Spectroscopy/'
DIR_PHOT = "/home/avinash/Supernovae_Data/2016gfy/Photometry/"
DIR_CODE = "/home/avinash/Dropbox/PyCharm/Reduction_Pipeline/"
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Details Of The SNe In Study (2016gfy)
# ------------------------------------------------------------------------------------------------------------------- #
name_SN = '2016gfy'
EBV_mag = 0.21
EBV_err = 0.05
dist_val = 29.64
dist_err = 2.65
distmod_mag = 32.36
distmod_err = 0.18
redshift = 0.008059
JD_offset = 2457600
phase_nebstart = 115
date_explosion = 2457641.40
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Data Containing Information On FILTERS and Other Type II SNe
# Extinction Coefficients For Different Photometric Bands (For Rv = 3.1, Fitzpatrick(1999))
# ------------------------------------------------------------------------------------------------------------------- #
filter_df = pd.read_csv(DIR_CODE + 'FILTERS.dat', sep='\s+')
filter_df = filter_df.replace('INDEF', np.nan).set_index(['FILTER', 'Marker', 'Color']).astype('float64')
filter_df = filter_df.reset_index().set_index('FILTER')
list_filters = filter_df.index.tolist()
for index, row in filter_df.iterrows():
if len(index) == 3 and index[0:2] == 'uv':
name = index[-1].upper()
else:
name = index
if row['Offset'] > 0:
filter_df.loc[index, 'Label'] = name + ' + ' + str(row['Offset'])
elif row['Offset'] == 0:
filter_df.loc[index, 'Label'] = name
else:
filter_df.loc[index, 'Label'] = name + ' - ' + str(abs(row['Offset']))
sndata_df = pd.read_csv(DIR_SNe + 'LC_Data/TypeIISNe.dat', sep='\s+', comment='#')
sndata_df = sndata_df.replace('INDEF', np.nan).set_index(['Name', 'Marker', 'Color']).astype('float64')
sndata_df = sndata_df.reset_index().set_index('Name')
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Functions For File Handling
# ------------------------------------------------------------------------------------------------------------------- #
def group_similar_files(text_list, common_text, exceptions=''):
"""
Groups similar files based on the string 'common_text'. Writes the similar files
onto the list 'text_list' (only if this string is not empty) and appends the similar
files to a list 'python_list'.
Args:
text_list : Name of the output text file with names grouped based on the 'common_text'
common_text : String containing partial name of the files to be grouped
exceptions : String containing the partial name of the files that need to be excluded
Returns:
list_files : Python list containing the names of the grouped files
"""
list_files = glob.glob(common_text)
if exceptions != '':
list_exception = exceptions.split(',')
for file_name in glob.glob(common_text):
for text in list_exception:
test = re.search(text, file_name)
if test:
try:
list_files.remove(file_name)
except ValueError:
pass
list_files.sort()
if len(text_list) != 0:
with open(text_list, 'w') as f:
for file_name in list_files:
f.write(file_name + '\n')
return list_files
def display_text(text_to_display):
"""
Displays text mentioned in the string 'text_to_display'
Args:
text_to_display : Text to be displayed
Returns:
None
"""
print ("\n" + "# " + "-" * (12 + len(text_to_display)) + " #")
print ("# " + "-" * 5 + " " + str(text_to_display) + " " + "-" * 5 + " #")
print ("# " + "-" * (12 + len(text_to_display)) + " #" + "\n")
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Useful Functions For Calculating Luminosity, Absolute Magnitudes & Fluxes
# ------------------------------------------------------------------------------------------------------------------- #
def blackbody_flux(wave, amp, temp):
"""
Calculates blackbody flux as a function of wavelength (um) and temperature (K).
Args:
wave : Wavelength (In Angstroms)
amp : Amplitude of the blackbody flux
temp : Temperature (In Kelvin)
Returns:
units of erg/s/cm^2/Angstrom
"""
return amp * blackbody_lambda(in_x=np.asarray(wave), temperature=temp).value
def calc_radius(lum, temp):
return (lum / (4 * np.pi * 5.67e-5 * (temp ** 4))) ** 0.5
def calc_objlum(flux, name=name_SN):
if name != name_SN:
dval = sndata_df.loc[name, 'D']
derr = sndata_df.loc[name, 'DErr']
else:
dval = dist_val
derr = dist_err
val = float(flux) * 4 * np.pi * (3.086e24 ** 2)
lum = fmt_exp.format(val * dval ** 2)
lumerr = fmt_exp.format(val * ((dval + derr) ** 2 - dval ** 2))
return float(lum), float(lumerr)
def get_nickelmass(lum, phase):
hamuy_ni = 7.866e-44 * lum * np.exp((phase * (1 + redshift) - 6.1) / 111.26)
jerk_ni = (lum * 0.07 / 9.92e41) / (math.exp(-phase / 111.4) - math.exp(-phase / 8.8))
return hamuy_ni, jerk_ni
def calc_magflux(mag, err, band, name=name_SN):
mag = float(mag)
err = float(err)
zp = filter_df.loc[band, 'ZeroPoint']
rlambda = filter_df.loc[band, 'RLambda']
if name != name_SN:
dval = sndata_df.loc[name, 'D']
derr = sndata_df.loc[name, 'DErr']
ebvmag = sndata_df.loc[name, 'EBV']
ebverr = sndata_df.loc[name, 'EBVErr']
else:
dval = dist_val
derr = dist_err
ebvmag = EBV_mag
ebverr = EBV_err
distmod_mag = 5 * np.log10(dval * 1e6) - 5
distmod_err = 5 * np.log10((dval + derr) * 1e6) - 5 - distmod_mag
absmag = fmt_flt.format(mag - rlambda * ebvmag - distmod_mag)
abserr = fmt_flt.format((err ** 2 + (rlambda * ebverr) ** 2 + distmod_err ** 2) ** 0.5)
flux = float(fmt_exp.format(10 ** (-0.4 * (mag - rlambda * ebvmag + zp + 21.100))))
fluxerr = fmt_exp.format(abs(flux - 10 ** (-0.4 * (mag + err - rlambda * ebvmag + zp + 21.100))))
return float(absmag), float(abserr), float(flux), float(fluxerr)
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Function To Convert Julian Date Into Calendar Date In String Format & Vice Versa
# ------------------------------------------------------------------------------------------------------------------- #
def jd_to_cald(julian_day):
"""
Converts julian day into calendar day in string format.
Args:
julian_day : Julian day value to be converted to calendar day
Returns:
cal_date : Calendar date corresponding to input julian day
"""
time_tuple = jd2gcal(epoch_mjd, julian_day - epoch_mjd)
cal_date = date(*time_tuple[0:3]).strftime("%Y-%m-%d")
return cal_date
def cald_to_jd(cal_date):
"""
Converts calendar date into julian day.
Args:
cal_date : Calendar date corresponding to input julian day
Returns:
julian_day : Julian day value to be converted to calendar day
"""
date_comp = cal_date.split("-")
jd_tuple = gcal2jd(date_comp[0], date_comp[1], date_comp[2])
julian_day = jd_tuple[0] + jd_tuple[1]
return julian_day
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Functions For Manipulating Pandas DataFrame Containing Data Of Other Well Studied SNe
# ------------------------------------------------------------------------------------------------------------------- #
def multicol_to_fluxdf(name, input_df):
"""
Converts a column-wise magnitude Pandas DataFrame to a row-wise Pandas DataFrame with
the flux values and the absolute magnitudes.
Args:
name : Name of the SN whose data is read
input_df : Input Pandas DataFrame
Returns:
output_df : Output Pandas DataFrame
"""
input_df = input_df.set_index('JD')
for column in ['Date', 'Phase']:
if column in input_df.columns:
input_df = input_df.drop([column], axis=1)
data_arr = input_df.values
size = data_arr.shape
list_jd = np.repeat(input_df.index.values, (size[1] / 2))
list_filters = [x for x in input_df.columns.values if 'Err' not in x]
data_arr = np.reshape(data_arr, [size[0] * size[1] / 2, 2])
output_df = pd.DataFrame(data_arr, index=list_jd, columns=['FMAG', 'FERR'])
output_df.index.name = 'JD'
output_df = output_df.reset_index(drop=False)
output_df['FILTER'] = list_filters * size[0]
output_df['Date'] = output_df['JD'].apply(jd_to_cald)
output_df['Phase'] = output_df['JD'] - sndata_df.loc[name, 'DateExp']
output_df = output_df.replace('INDEF', np.nan).dropna(axis=0, how='any')
output_df = output_df[['Date', 'JD', 'Phase', 'FILTER', 'FMAG', 'FERR']].reset_index(drop=True)
output_df['ALambda'] = output_df['FILTER'].apply(lambda x: float(fmt_flt.format(
filter_df.loc[x, 'RLambda'] * sndata_df.loc[name, 'EBV'])))
for index, band in output_df['FILTER'].items():
magflux = calc_magflux(mag=output_df.loc[index, 'FMAG'], err=output_df.loc[index, 'FERR'],
band=band, name=name)
output_df.loc[index, 'AbsMag'] = magflux[0]
output_df.loc[index, 'AbsErr'] = magflux[1]
output_df.loc[index, 'Flux'] = magflux[2]
output_df.loc[index, 'FluxErr'] = magflux[3]
return output_df
def calc_boldf(name, input_df, flux='Flux', fluxerr='FluxErr', plot=False):
"""
Creates a Pandas DataFrame with Bolometric Fluxes.
Args:
name : Name of the SNe whose bolometric magnitudes are to be computed
input_df : Input Pandas DataFrame containing individual band fluxes
flux : Name of the Flux column in the Pandas DataFrame
fluxerr : Name of the Flux Error column in the Pandas DataFrame
plot : Whether the spline fits to the fluxes should be plotted
Returns:
output_df : Output Pandas DataFrame containing bolometric fluxes
"""
input_df = input_df.set_index('JD')
dict_val = {}
for index, row in input_df.iterrows():
if index not in dict_val.keys():
dict_val[index] = {}
if row['FILTER'] not in dict_val[index]:
dict_val[index][row['FILTER']] = []
dict_val[index][row['FILTER'] + 'Err'] = []
dict_val[index][row['FILTER']].append(row[flux])
dict_val[index][row['FILTER'] + 'Err'].append(row[fluxerr])
for (day, dict_date) in dict_val.items():
for (band, list_flux) in dict_date.items():
if 'Err' not in band:
dict_val[day][band] = np.mean(list_flux)
else:
dict_val[day][band] = np.sqrt(np.sum(np.square(list_flux)))
dict_flux = {}
for (day, dict_date) in dict_val.items():
if len(dict_date) > 2:
if day not in dict_flux.keys():
dict_flux[day] = {}
for (band, flux) in dict_date.items():
if 'Err' not in band:
dict_flux[day][filter_df.loc[band, 'CentreWave']] = flux
else:
dict_flux[day][str(filter_df.loc[band[:-3], 'CentreWave']) + 'Err'] = flux
flux_df = pd.DataFrame(dict_flux).T
flux_df.index.name = 'JD'
flux_df = flux_df.interpolate(method='polynomial', order=1, limit=3).T
dict_bolflux = {}
for jd in flux_df.columns.values:
series = flux_df[jd].dropna()
if len(series) < 3:
continue
mag = series.loc[[x for x in list(series.index) if type(x) != str]]
err = series.loc[[x for x in list(series.index) if type(x) == str]]
spline = CubicSpline(mag.index.values.tolist(), mag.values.tolist(), bc_type='natural', extrapolate=True)
if jd - sndata_df.loc[name, 'DateExp'] > 99:
wave_data = np.linspace(4000, 9200, 1000)
else:
wave_data = np.linspace(3100, 9200, 1000)
flux_data = spline(wave_data)
flux_data[flux_data < 0] = 0
netflux = np.trapz(flux_data, wave_data)
dict_bolflux[jd] = {}
dict_bolflux[jd]['Date'] = jd_to_cald(jd)
dict_bolflux[jd]['Phase'] = jd - sndata_df.loc[name, 'DateExp']
dict_bolflux[jd]['Flux'] = netflux
dict_bolflux[jd]['Lum'] = calc_objlum(netflux, name=name)[0]
dict_bolflux[jd]['LumErr'] = calc_objlum(netflux, name=name)[1]
if plot:
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(111)
ax.plot(series.index.values, series.values, 'o', label='Data Points')
ax.plot(wave_data, spline(wave_data), 'r-', label='CubicSpline Fit')
ax.legend()
ax.grid()
plt.show()
plt.close(fig)
if len(dict_bolflux) != 0:
output_df = pd.DataFrame(dict_bolflux).T
output_df.index.name = 'JD'
output_df = output_df.reset_index().set_index(keys='Date', drop=True)
else:
output_df = pd.DataFrame()
return output_df
def calc_swiftuvdf(file_name, name):
"""
Creates a Pandas DataFrame with SWIFT UVOT magnitudes arranged epoch-wise from a file 'file_name'.
Args:
file_name : Text file containing SWIFT UVOT magnitudes
name : Name of the supernova for which SWIFT UVOT magntiudes are to be plotted
Returns:
output_df : Pandas DataFrame containing organised SWIFT UVOT magnitudes
"""
input_df = pd.read_csv(file_name, sep='\s+', comment='#', usecols=[0, 1, 2, 3], header=None)
input_df = input_df.rename(columns={0: 'FILTER', 1: 'MJD', 2: 'FMAG', 3: 'FERR'}).replace('INDEF', np.nan)
input_df['FILTER'] = input_df['FILTER'].apply(lambda x: 'uv' + x.lower() if 'uv' not in x.lower() else x.lower())
output_df = input_df.set_index('FILTER').astype('float64').reset_index().copy()
output_df['JD'] = (output_df['MJD'] + epoch_mjd).round(1)
output_df['Date'] = output_df['JD'].apply(jd_to_cald)
output_df['Phase'] = (output_df['JD'] - sndata_df.loc[name, 'DateExp']).round(1)
for index, band in output_df['FILTER'].iteritems():
data_magflux = calc_magflux(mag=output_df.loc[index, 'FMAG'], err=output_df.loc[index, 'FERR'],
band=band, name=name)
output_df.loc[index, 'AbsMag'] = data_magflux[0]
output_df.loc[index, 'AbsErr'] = data_magflux[1]
output_df.loc[index, 'Flux'] = data_magflux[2]
output_df.loc[index, 'FluxErr'] = data_magflux[3]
output_df.loc[index, 'ALambda'] = float(fmt_flt.format(filter_df.loc[band, 'RLambda'] * EBV_mag))
return output_df
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Function For Manipulating Pandas DataFrames Containing Data From SN In Study
# ------------------------------------------------------------------------------------------------------------------- #
def organise_sndf(input_df, column):
"""
Creates a Pandas DataFrame with magnitudes arranged epoch-wise from a DataFrame with unorganised magnitudes.
Args:
input_df : Pandas DataFrame containing magnitudes
column : Column to be extracted from the Pandas DataFrame
Returns:
output_df : Pandas DataFrame containing organised broadband magnitudes
"""
dict_val = {}
for index, row in input_df.iterrows():
if index not in dict_val.keys():
dict_val[index] = {}
dict_val[index][row['FILTER']] = row[column]
output_df = pd.DataFrame(dict_val).T
output_df.index.name = 'Date'
output_df = output_df.reset_index()
output_df['Phase'] = output_df['Date'].apply(lambda x: input_df.loc[input_df.index == x, 'Phase'].iloc[0])
return output_df
def calc_snboldf(input_df, mag='FMAG', magerr='FERR', flux='Flux', fluxerr='FluxErr', tempsub=False, plot=False):
"""
Creates a Pandas DataFrame with bolometric luminosity arranged epoch-wise from a DataFrame
with unorganised magnitudes.
Args:
input_df : Pandas DataFrame containing magnitudes
mag : Name of the Magnitude column in the Pandas DataFrame
magerr : Name of tge Magnitude Error column in the Pandas DataFrame
flux : Name of the Flux column in the Pandas DataFrame
fluxerr : Name of the Flux Error column in the Pandas DataFrame
tempsub : Whether the magnitudes are template subtracted?
plot : Whether the spline fits to the fluxes should be plotted
Returns:
bolm_df : Pandas DataFrame containing organised
flux_df : Pandas DataFrame containing organised broadband fluxes
"""
if not tempsub:
add_text = ''
else:
add_text = 'Temp'
input_df = input_df.set_index('JD')
dict_mag = {}
for index, row in input_df.iterrows():
if index not in dict_mag.keys():
dict_mag[index] = {}
if row['FILTER'] not in dict_mag[index]:
dict_mag[index][row['FILTER']] = []
dict_mag[index][row['FILTER'] + 'Err'] = []
dict_mag[index][row['FILTER']].append(row['FMAG'])
dict_mag[index][row['FILTER'] + 'Err'].append(row['FERR'])
for (day, dict_date) in dict_mag.items():
for (band, list_mag) in dict_date.items():
dict_mag[day][band] = float(np.mean(list_mag))
mag_df = pd.DataFrame(dict_mag).T
mag_df.index.name = 'JD'
mag_df = mag_df.reset_index()
mag_df['Date'] = mag_df['JD'].apply(jd_to_cald)
mag_df['Phase'] = mag_df['JD'].apply(lambda x: x - date_explosion).round(int(precision))
mag_df.to_csv('OUTPUT_DateWiseSNAppMag' + add_text, sep=' ', index=True, na_rep='INDEF')
dict_val = {}
for index, row in input_df.iterrows():
if index not in dict_val.keys():
dict_val[index] = {}
if row['FILTER'] not in dict_val[index]:
dict_val[index][row['FILTER']] = []
dict_val[index][row['FILTER'] + 'Err'] = []
dict_val[index][row['FILTER']].append(row[flux])
dict_val[index][row['FILTER'] + 'Err'].append(row[fluxerr])
for (day, dict_date) in dict_val.items():
for (band, list_flux) in dict_date.items():
if 'Err' not in band:
dict_val[day][band] = np.mean(list_flux)
else:
dict_val[day][band] = np.sqrt(np.sum(np.square(list_flux)))
flux_df = pd.DataFrame(dict_val).T
flux_df.index.name = 'JD'
flux_df = flux_df.reset_index()
flux_df['Date'] = flux_df['JD'].apply(jd_to_cald)
flux_df['Phase'] = flux_df['JD'].apply(lambda x: x - date_explosion).round(int(precision))
flux_df.to_csv('OUTPUT_DateWiseSNAppFlux' + add_text, sep=' ', index=False, na_rep='INDEF')
dict_flux = {}
for (day, dict_date) in dict_val.items():
if len(dict_date) > 3:
if day not in dict_flux.keys():
dict_flux[day] = {}
for (band, flux) in dict_date.items():
if 'Err' not in band:
dict_flux[day][filter_df.loc[band, 'CentreWave']] = flux
else:
dict_flux[day][str(filter_df.loc[band.rstrip('Err'), 'CentreWave']) + 'Err'] = flux
bolm_df = pd.DataFrame(dict_flux).T
bolm_df.index.name = 'JD'
bolm_df = bolm_df.interpolate(method='polynomial', order=1, limit=3).T
dict_bolflux = {}
for caljd in bolm_df.columns.values:
series = bolm_df[caljd].dropna()
mag = series.loc[[x for x in list(series.index) if type(x) != str]]
err = series.loc[[x for x in list(series.index) if type(x) == str]]
spline = CubicSpline(mag.index.values.tolist(), mag.values.tolist(), bc_type='natural', extrapolate=True)
if caljd - date_explosion > 99:
wave_data = np.linspace(4000, 9200, 1000)
else:
wave_data = np.linspace(3100, 9200, 1000)
flux_data = spline(wave_data)
flux_data[flux_data < 0] = 0
netflux = np.trapz(flux_data, wave_data)
popt, pcov = curve_fit(blackbody_flux, mag.index.values.tolist(), mag.values.tolist(),
sigma=err.values.tolist(), p0=[1e-15, 10000])
# print ("Best-Fit Temperature[{0:.1f}]= {1:.2f}+/-{2:.2f}".format(caljd - date_explosion, popt[1],
# np.sqrt(np.diag(pcov)[1])))
lum, lumerr = calc_objlum(netflux, name=name_SN)
radius = calc_radius(lum, popt[1])
dict_bolflux[caljd] = {}
dict_bolflux[caljd]['Date'] = jd_to_cald(caljd)
dict_bolflux[caljd]['Phase'] = caljd - date_explosion
dict_bolflux[caljd]['Flux'] = netflux
dict_bolflux[caljd]['Lum'] = lum
dict_bolflux[caljd]['LumErr'] = lumerr
dict_bolflux[caljd]['Temp'] = popt[1]
dict_bolflux[caljd]['TempErr'] = np.sqrt(np.diag(pcov)[1])
dict_bolflux[caljd]['Rad'] = radius
dict_bolflux[caljd]['RadErr'] = (radius / 2) * ((lumerr / lum) - (4 * np.sqrt(np.diag(pcov)[1]) / popt[1]))
if plot:
fig_temp = plt.figure(figsize=(10, 8))
ax = fig_temp.add_subplot(111)
wave2_data = np.linspace(1600, 9200, 1000)
ax.plot(mag.index.values, mag.values, 'o', label='Data Points')
ax.plot(wave_data, flux_data, 'r-', label='CubicSpline Fit')
if len(mag.index.values) > 5:
ax.plot(wave2_data, blackbody_flux(wave2_data, *popt), 'k--', label='Blackbody Fit')
else:
ax.plot(wave_data, blackbody_flux(wave_data, *popt), 'k--', label='Blackbody Fit')
ax.set_ylabel(r'Apparent Flux [$\rm erg\ s^{-1}\ cm^{-2}\ \AA^{-1}$]')
ax.set_xlabel(r'Wavelength [$\rm \AA$]')
ax.set_title("Temperature = {0:.2f}+/- {1:.2f}".format(popt[1], np.sqrt(np.diag(pcov)[1])))
ax.legend()
ax.grid()
plt.show()
plt.close(fig_temp)
fbolm_df = pd.DataFrame(dict_bolflux).T
fbolm_df.index.name = 'JD'
fbolm_df.to_csv('OUTPUT_DateWiseSNBolFlux' + add_text, sep=' ', index=True)
for index, row in fbolm_df.iterrows():
if row['Phase'] > 150:
fbolm_df.loc[index, 'MNi'] = get_nickelmass(row['Lum'], phase=row['Phase'])[0]
fbolm_df.loc[index, 'MNi2'] = get_nickelmass(row['Lum'], phase=row['Phase'])[1]
fbolm_df.loc[index, 'MNiErr'] = get_nickelmass(row['LumErr'], phase=row['Phase'])[0]
return bolm_df, fbolm_df
def calc_snfluxdf(file_name, concat_df=pd.DataFrame(), tempsub=False):
"""
Creates a Pandas DataFrame with Individual Band Fluxes.
Args:
file_name : Name of the file which has the photometric magnitudes for the SNe
concat_df : Input Pandas DataFrame to be appended to the original data
tempsub : Boolean describing whether these magnitudes are template subtracted?
Returns:
output_df : Output Pandas DataFrame containing individual band fluxes
"""
if not tempsub:
add_text = ''
else:
add_text = 'Temp'
output_df = pd.read_csv(file_name, sep="\s+", engine='python')
if not concat_df.empty:
output_df = pd.concat([concat_df, output_df], axis=0)
output_df = output_df.sort_values(by=['FILTER', 'JD'], kind='mergesort')
output_df['Date'] = output_df['JD'].apply(lambda x: jd_to_cald(x))
output_df['Phase'] = output_df['JD'].apply(lambda x: x - date_explosion).round(int(precision))
output_df = output_df[['Date', 'JD', 'Phase', 'FILTER', 'FMAG', 'FERR']].reset_index(drop=True)
output_df.to_csv('OUTPUT_NetSNMag' + add_text, sep=' ', index=False)
for index, band in output_df['FILTER'].items():
data_magflux = calc_magflux(mag=output_df.loc[index, 'FMAG'], err=output_df.loc[index, 'FERR'], band=band)
output_df.loc[index, 'AbsMag'] = data_magflux[0]
output_df.loc[index, 'AbsErr'] = data_magflux[1]
output_df.loc[index, 'Flux'] = data_magflux[2]
output_df.loc[index, 'FluxErr'] = data_magflux[3]
output_df.loc[index, 'ALambda'] = float(fmt_flt.format(filter_df.loc[band, 'RLambda'] * EBV_mag))
output_df.to_csv('OUTPUT_NetSNFlux' + add_text, sep=' ', index=False)
return output_df
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Function For Setting Plot Parameters And Plotting
# ------------------------------------------------------------------------------------------------------------------- #
def set_plotparams(ax_obj):
"""
Sets plot parameters to the axes object 'ax_obj'.
Args:
ax_obj : Axes object to be used for plotting and setting plot parameters
Returns:
None
"""
ax_obj.yaxis.set_ticks_position('both')
ax_obj.xaxis.set_ticks_position('both')
ax_obj.xaxis.set_major_locator(MultipleLocator(100))
ax_obj.xaxis.set_minor_locator(MultipleLocator(10))
ax_obj.tick_params(axis='both', which='major', direction='in', length=8, width=1.4, labelsize=14)
ax_obj.tick_params(axis='both', which='minor', direction='in', length=4, width=0.8, labelsize=14)
ax_obj.set_xlabel('Time Since Explosion [Days]', fontsize=16)
def plot_uvband(ax_obj, name, data_df, band, label=True):
"""
Plot the SWIFT UVOT band to the axes object 'ax_obj'.
Args:
ax_obj : Axes object to be used for plotting and setting plot parameters
name : Name of Supernova whose magnitudes are to be plotted
data_df : Pandas DataFrame containing SWIFT UVOT magnitudes
band : SWIFT UVOT band to be plotted
label : Boolean stating whether the plot is to be labelled
Returns:
None
"""
plot_df = data_df[data_df['FILTER'] == band].copy()
if label:
ax_obj.plot(plot_df['Phase'], plot_df['AbsMag'], ls=':', markersize=8, c=sndata_df.loc[name, 'Color'],
marker=sndata_df.loc[name, 'Marker'], label=name)
else:
ax_obj.plot(plot_df['Phase'], plot_df['AbsMag'], ls=':', markersize=8, c=sndata_df.loc[name, 'Color'],
marker=sndata_df.loc[name, 'Marker'], label='_nolegend_')
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Read Other SNe Data From Archive Folder
# ------------------------------------------------------------------------------------------------------------------- #
list_files = group_similar_files('', DIR_SNe + 'LC_Data/*.asc', exceptions='SWIFT')
list_uvfiles = group_similar_files('', DIR_SNe + 'LC_Data/*SWIFT*.asc')
list_modnifiles = group_similar_files('', DIR_SNe + 'NiMix_Data/*.dat')
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Copy Pandas DataFrame Into Subset DataFrames Required For Various Plots
# ------------------------------------------------------------------------------------------------------------------- #
rawopt_df = calc_snfluxdf('OUTPUT_FinalSNMag', tempsub=False)
outputopt_df = calc_snfluxdf('OUTPUT_FinalSNMagTemp', tempsub=True)
max_epoch = outputopt_df['Phase'].max()
outputopt_df = outputopt_df[~((outputopt_df['Date'] == '2016-12-29') & (outputopt_df['FILTER'] == 'U'))]
outputopt_df = outputopt_df[~((outputopt_df['Date'] == '2017-10-01') & (outputopt_df['FILTER'] == 'U'))]
outputopt_df[['JD', 'Phase']] = outputopt_df[['JD', 'Phase']].round(1)
vabs_df = outputopt_df[outputopt_df['FILTER'] == 'V'].copy()
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Read SWIFT Data And Combine It With Optical Data To Calculate Bolometric Light Curve
# Read Photospheric Velocity For Determining Radius
# ------------------------------------------------------------------------------------------------------------------- #
outputuv_df = calc_swiftuvdf(DIR_PHOT + '2016gfy_SWIFT.dat', name=name_SN)
outputnet_df = pd.concat([outputopt_df, outputuv_df], sort=True)
outputuv_df = outputuv_df.set_index('JD').dropna(axis=0, how='any')
bolm_df, fbolm_df = calc_snboldf(outputopt_df)
# _, fbolm2_df = calc_snboldf(outputnet_df)
temprad_df = fbolm_df[fbolm_df['Phase'] < 120].copy()
temprad_df[['Temp', 'TempErr']] = temprad_df[['Temp', 'TempErr']] / 1000.
temprad_df[['Rad', 'RadErr']] = temprad_df[['Rad', 'RadErr']] / (1000 * solar_rad)
vel_df = pd.read_csv(DIR_SPEC + file_photvel, sep='\s+').replace('INDEF', np.nan).drop('Date', axis=1)
vel_df = vel_df.astype('float64')[['Phase', '5169', '5169Err']].dropna()
vel_df['Rad'] = vel_df['Phase'] * vel_df['5169'] * 86400e5 / (1000 * solar_rad)
vel_df['RadErr'] = vel_df['Phase'] * vel_df['5169Err'] * 86400e5 / (1000 * solar_rad)
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Fit Peacewise Polynomial To Bolometric Light Curve
# ------------------------------------------------------------------------------------------------------------------- #
x = np.array(fbolm_df['Phase'])
y = np.array(fbolm_df['Lum'].apply(lambda lum: np.log10(lum)))
number_segments = 5
myPWLF = pwlf.PiecewiseLinFit(x, y, sorted_data=True)
myPWLF.fit(number_segments)
xarr = np.linspace(np.min(x), np.max(x), num=1000)
xguess = np.zeros(number_segments - 1)
xguess[0:] = [8, 39, 91, 124]
myPWLF.fit_with_breaks([np.min(x)] + [8, 39, 91, 124] + [np.max(x)])
fit = myPWLF.predict(xarr)
fitsigma = np.sqrt(myPWLF.prediction_variance(xarr))
s1 = -(myPWLF.slopes)[1] * 100
s2 = -(myPWLF.slopes)[2] * 100
s3 = -(myPWLF.slopes)[4] * 100
print "Number of Parameters: {0}".format(myPWLF.n_parameters)
print "Best Fit: ", myPWLF.slopes * 100
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Tabulate The Photometric Data Epoch-Wise Onto An Output File
# ------------------------------------------------------------------------------------------------------------------- #
data_df = pd.read_csv('OUTPUT_FinalSNMagTemp', sep='\s+')
data_df['Date'] = data_df['JD'].apply(lambda x: jd_to_cald(x))
data_df['Phase'] = (data_df['JD'] - date_explosion).round(int(precision))
data_df['Mag'] = data_df['FMAG'].apply(lambda x: '{:.2f}'.format(x)) + r'$\pm$' + data_df['FERR'].apply(lambda x: '{:.2f}'.format(x))
tabular_df = data_df[['FILTER', 'Date', 'JD', 'Phase', 'Mag']]
tabular_df.to_csv('OUTPUT_FinalTabularSNMag', sep=' ', index=False)
display_text("HCT Magnitudes For SN {0} Have Been Tabulated Epoch-Wise".format(name_SN))
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Output The HCT Photometric Magnitudes Onto A Latex Table
# ------------------------------------------------------------------------------------------------------------------- #
data_df = data_df.set_index('Date')
tabopt_df = organise_sndf(data_df, column='Mag')
tabopt_df['Phase'] = tabopt_df['Date'].apply(lambda x: data_df.loc[data_df.index == x, 'Phase'].iloc[0])
tabopt_df['JD'] = np.round(tabopt_df['Phase'] + date_explosion - JD_offset, 2)
tabopt_df['Phase'] = tabopt_df['Phase'].apply(lambda x: "{:.2f}".format(x) if x < 0 else "+{:.2f}".format(x))
tabopt_df = tabopt_df[['Date', 'JD', 'Phase', 'U', 'B', 'V', 'R', 'I']].sort_values(by='JD')
tabopt_df = tabopt_df.rename(columns={'Phase': 'Phase$^*$', 'U': '$U$', 'B': '$B$', 'V': '$V$',
'R': '$R$', 'I': '$I$'}).dropna(how='all', axis=1)
tabopt_df = tabopt_df.replace(np.nan, '---', regex=True)
tabopt_df.to_latex('_PhotHCT.tex', escape=False, index=False)
display_text("HCT Magnitudes For SN {0} Have Been Logged Onto A Latex File".format(name_SN))
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Output The SWIFT Photometric Magnitudes Onto A Latex Table
# ------------------------------------------------------------------------------------------------------------------- #
outputuv_df['Mag'] = outputuv_df['FMAG'].apply(lambda x: "{:.2f}".format(x)) + r'$\pm$' + outputuv_df['FERR'].apply(lambda x: "{:.2f}".format(x))
outputuv_df = outputuv_df.set_index('Date', drop=False)
tabuv_df = organise_sndf(outputuv_df, column='Mag')
tabuv_df['Phase'] = tabuv_df['Date'].apply(lambda x: outputuv_df.loc[outputuv_df.index == x, 'Phase'].iloc[0])
tabuv_df['JD'] = tabuv_df['Phase'] + date_explosion - JD_offset
tabuv_df['Phase'] = tabuv_df['Phase'].apply(lambda x: "{:.2f}".format(x) if x < 0 else "+{:.2f}".format(x))
tabuv_df = tabuv_df[['Date', 'JD', 'Phase', 'uvw2', 'uvm2', 'uvw1', 'uvu', 'uvv']].sort_values(by='JD')
tabuv_df = tabuv_df.rename(columns={'Phase': 'Phase$^*$', 'uvw2': '$uvw2$', 'uvm2': '$uvm2$', 'uvw1': '$uvw1$',
'uvu': '$uvu$', 'uvv': '$uvv$'})
tabuv_df = tabuv_df.replace(np.nan, '---', regex=True).dropna(how='all', axis=1)
tabuv_df.to_latex('_PhotSWIFT.tex', escape=False, index=False)
display_text("SWIFT Magnitudes For SN {0} Have Been Logged Onto A Latex File".format(name_SN))
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Compute The Eeta_Ni For The SN In Study
# ------------------------------------------------------------------------------------------------------------------- #
mNi = 0.033
phase_nebbol = 124
platarr = np.arange(0, phase_nebbol, 0.1)
bollum = UnivariateSpline(fbolm_df['Phase'], fbolm_df['Lum'], k=1)
def calc_nilum(t):
return mNi * (6.45 * np.exp(-t / 8.8) + 1.45 * np.exp(-t / 111.3)) * 1e43
def calc_eeta():
return np.trapz(platarr * calc_nilum(platarr), platarr) / np.trapz(platarr * (bollum(platarr) - calc_nilum(platarr)), platarr)
def calc_deltae():
return bollum(25) * (80 ** 2) / np.trapz(platarr * (bollum(platarr) - calc_nilum(platarr)), platarr)
def calc_delta():
return bollum(25) * (80 ** 2) / np.trapz(platarr * (bollum(platarr)), platarr)
def calc_deltaM():
return -2.5 * np.log10(bollum(75) / bollum(25))
print calc_eeta()
print calc_deltae(), 2.5 * np.log10(calc_deltae()), 0.44 + 0.82 * 2.5 * np.log10(calc_delta())
print calc_delta(), 2.5 * np.log10(calc_delta())
print calc_deltaM()
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Plot The HCT Apparent Magnitude Light Curves
# ------------------------------------------------------------------------------------------------------------------- #
fig_app = plt.figure(figsize=(8, 8))
ax_app = fig_app.add_subplot(111)
for band, band_df in outputopt_df.groupby('FILTER'):
ax_app.scatter(band_df['Phase'], band_df['FMAG'] + filter_df.loc[band, 'Offset'], c=filter_df.loc[band, 'Color'],
marker=filter_df.loc[band, 'Marker'], s=30, alpha=0.6, label=filter_df.loc[band, 'Label'])
ax_app.plot(band_df['Phase'], band_df['FMAG'] + filter_df.loc[band, 'Offset'], c='k', markerfacecolor='None',
ls='', markeredgewidth=1, marker=filter_df.loc[band, 'Marker'], ms=6, alpha=0.6, label='_nolegend_')
ax_app.errorbar(band_df['Phase'], band_df['FMAG'] + filter_df.loc[band, 'Offset'], yerr=band_df['FERR'], fmt='',
c=filter_df.loc[band, 'Color'], ls='--', lw=0.5, capsize=2, capthick=1, label='_nolegend_')
handles, labels = ax_app.get_legend_handles_labels()
handles = [handles[3], handles[0], handles[4], handles[2], handles[1]]
labels = [labels[3], labels[0], labels[4], labels[2], labels[1]]
ax_app.legend(handles, labels, fontsize=12, markerscale=2, loc=1, frameon=False)
set_plotparams(ax_app)
ax_app.set_ylim(22.0, 14.5)
ax_app.set_xlim(-15, max_epoch + 20)
ax_app.yaxis.set_major_locator(MultipleLocator(1))
ax_app.yaxis.set_minor_locator(MultipleLocator(0.2))
ax_app.set_ylabel('Apparent Magnitude [mag]', fontsize=16)
fig_app.savefig('PLOT_ApparentLC.pdf', format='pdf', dpi=2000, bbox_inches='tight')
plt.show()
plt.close(fig_app)
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Plot The SWIFT Apparent Magnitude Light Curves
# ------------------------------------------------------------------------------------------------------------------- #
fig_swift = plt.figure(figsize=(8, 8))
ax_swift = fig_swift.add_subplot(111)
for band, band_df in outputuv_df.groupby('FILTER'):
ax_swift.scatter(band_df['Phase'], band_df['FMAG'] + filter_df.loc[band, 'Offset'], c=filter_df.loc[band, 'Color'],
marker=filter_df.loc[band, 'Marker'], s=35, label=filter_df.loc[band, 'Label'])
ax_swift.plot(band_df['Phase'], band_df['FMAG'] + filter_df.loc[band, 'Offset'], c='k', markerfacecolor='None',
ls='', markeredgewidth=1, marker=filter_df.loc[band, 'Marker'], ms=7, alpha=0.6, label='_nolegend_')
ax_swift.errorbar(band_df['Phase'], band_df['FMAG'] + filter_df.loc[band, 'Offset'], yerr=band_df['FERR'], fmt='',
c=filter_df.loc[band, 'Color'], ls='--', lw=1, capsize=2, capthick=1, label='_nolegend_')
handles, labels = ax_swift.get_legend_handles_labels()
handlesuv = [handles[5], handles[1], handles[4], handles[2], handles[0], handles[3]]
labelsuv = [labels[5], labels[1], labels[4], labels[2], labels[0], labels[3]]
ax_swift.legend(handlesuv, labelsuv, fontsize=11, markerscale=2, loc=4, frameon=False)
ax_swift.set_ylim(22.0, 14.5)
ax_swift.set_xlim(-1, 31)
ax_swift.yaxis.set_ticks_position('both')
ax_swift.xaxis.set_ticks_position('both')
ax_swift.yaxis.set_major_locator(MultipleLocator(1))
ax_swift.yaxis.set_minor_locator(MultipleLocator(0.2))
ax_swift.xaxis.set_major_locator(MultipleLocator(5))
ax_swift.xaxis.set_minor_locator(MultipleLocator(0.5))
ax_swift.set_ylabel('Apparent Magnitude [mag]', fontsize=16)
ax_swift.set_xlabel('Time Since Explosion [Days]', fontsize=16)
ax_swift.tick_params(axis='both', which='major', direction='in', length=8, width=1, labelsize=14)
ax_swift.tick_params(axis='both', which='minor', direction='in', length=4, width=1, labelsize=14)
fig_swift.savefig('PLOT_ApparentUVLC.pdf', format='pdf', dpi=2000, bbox_inches='tight')
plt.show()
plt.close(fig_swift)
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Plot The Apparent Magnitude Light Curves
# ------------------------------------------------------------------------------------------------------------------- #
fig_comb, (ax_opt, ax_uv) = plt.subplots(1, 2, figsize=(16, 8), sharey=True)
for band, band_df in outputopt_df.groupby('FILTER'):
ax_opt.scatter(band_df['Phase'], band_df['FMAG'] + filter_df.loc[band, 'Offset'], c=filter_df.loc[band, 'Color'],
marker=filter_df.loc[band, 'Marker'], s=30, alpha=0.6, label=filter_df.loc[band, 'Label'])
ax_opt.plot(band_df['Phase'], band_df['FMAG'] + filter_df.loc[band, 'Offset'], c='k', markerfacecolor='None',
ls='', markeredgewidth=0.7, marker=filter_df.loc[band, 'Marker'], ms=6, alpha=0.6, label='_nolegend_')
ax_opt.errorbar(band_df['Phase'], band_df['FMAG'] + filter_df.loc[band, 'Offset'], yerr=band_df['FERR'], fmt='',
c=filter_df.loc[band, 'Color'], ls='--', lw=0.5, capsize=2, capthick=1, label='_nolegend_')
handles, labels = ax_opt.get_legend_handles_labels()
handles = [handles[3], handles[0], handles[4], handles[2], handles[1]]
labels = [labels[3], labels[0], labels[4], labels[2], labels[1]]
ax_opt.legend(handles, labels, fontsize=16, markerscale=2, frameon=False, loc=1)
set_plotparams(ax_opt)
ax_opt.set_ylim(22.0, 14.5)
ax_opt.set_xlim(-15, max_epoch + 20)
ax_opt.yaxis.set_major_locator(MultipleLocator(1))
ax_opt.yaxis.set_minor_locator(MultipleLocator(0.2))
ax_opt.set_ylabel('Apparent Magnitude [mag]', fontsize=16)
ax_opt.set_title('HCT-HFOSC', fontsize=16)
for band, band_df in outputuv_df.groupby('FILTER'):
ax_uv.scatter(band_df['Phase'], band_df['FMAG'] + filter_df.loc[band, 'Offset'], c=filter_df.loc[band, 'Color'],
marker=filter_df.loc[band, 'Marker'], s=50, label=filter_df.loc[band, 'Label'])
ax_uv.plot(band_df['Phase'], band_df['FMAG'] + filter_df.loc[band, 'Offset'], c='k', markerfacecolor='None',
ls='', markeredgewidth=0.7, marker=filter_df.loc[band, 'Marker'], ms=7, alpha=0.6, label='_nolegend_')
ax_uv.errorbar(band_df['Phase'], band_df['FMAG'] + filter_df.loc[band, 'Offset'], yerr=band_df['FERR'], fmt='',
c=filter_df.loc[band, 'Color'], ls='--', lw=0.5, capsize=2, capthick=1, label='_nolegend_')
handles, labels = ax_uv.get_legend_handles_labels()
handlesuv = [handles[5], handles[1], handles[4], handles[2], handles[0], handles[3]]
labelsuv = [labels[5], labels[1], labels[4], labels[2], labels[0], labels[3]]
ax_uv.legend(handlesuv, labelsuv, fontsize=14, markerscale=2, loc=4)
ax_uv.set_title('SWIFT-UVOT', fontsize=16)
ax_uv.set_xlim(-0.5, 32)
# ax_uv.set_yticklabels([])
ax_uv.yaxis.set_ticks_position('both')
ax_uv.xaxis.set_ticks_position('both')
ax_uv.yaxis.set_major_locator(MultipleLocator(1))
ax_uv.yaxis.set_minor_locator(MultipleLocator(0.2))
ax_uv.xaxis.set_major_locator(MultipleLocator(5))
ax_uv.xaxis.set_minor_locator(MultipleLocator(0.5))
ax_uv.set_xlabel('Time Since Explosion [Days]', fontsize=16)
ax_uv.tick_params(axis='both', which='major', direction='in', length=8, width=1, labelsize=14)
ax_uv.tick_params(axis='both', which='minor', direction='in', length=4, width=1, labelsize=14)
fig_comb.subplots_adjust(wspace=0.01)
fig_comb.savefig('PLOT_ApparentCombLC.pdf', format='pdf', dpi=2000, bbox_inches='tight')
plt.show()
plt.close(fig_comb)
# ------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------------------------------------------- #
# Plot The Comparison Of The Template Subtracted Magnitudes With Original Magnitudes
# ------------------------------------------------------------------------------------------------------------------- #
fig_comp = plt.figure(figsize=(9, 6))
ax_comp = fig_comp.add_subplot(111)
for band, band_df in outputopt_df.groupby('FILTER'):
ax_comp.scatter(band_df['Phase'], band_df['FMAG'] + filter_df.loc[band, 'Offset'],
marker=filter_df.loc[band, 'Marker'],
c=filter_df.loc[band, 'Color'], s=10, label=filter_df.loc[band, 'Label'], alpha=0.5)
ax_comp.errorbar(band_df['Phase'], band_df['FMAG'] + filter_df.loc[band, 'Offset'], yerr=band_df['FERR'],
c=filter_df.loc[band, 'Color'], fmt='', ls='', lw=0.5, capsize=2, capthick=1,