-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
executable file
·79 lines (65 loc) · 2.48 KB
/
main.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
#!/usr/bin/env python
# coding: utf-8
# importing all the used modules
import numpy as np
import matplotlib.pyplot as plt
import argparse
from pathlib import Path
from startscreen import startScreen
from folding import timeFolding
from flagging import flagData
from dispersionMeasure import dedispersion
from observation import Observation
from paramObj import Config
from makefitsfile import raw2fits
startScreen('1.1.0')
parser = argparse.ArgumentParser(description='Pulsar folding!')
parser.add_argument('paramfile', help='A parameter file containing all the necessary data. Overwrites any other arguments.')
args = parser.parse_args()
# Create an object containing all useful pulsar properties
print("Loading parameters")
cfg = Config(args.paramfile)
print("Loading data")
obs = Observation(cfg)
pulsar = obs.pulsar
twodarray = obs.data
# read the literature value of the period and the dispersion measure
period = pulsar.period
DM = pulsar.DM
# Time resolution of the telescope
dt = (512*64)/(70e6)
# Array with the bandwith
frequencyarray = obs.freq
# this part should be RFI flagging something like:
# noflag = flagging(twodarray)
if cfg.GrasMaaier:
print("Flagging bad data")
flagparams = dict()
flagparams['signific'] = cfg.GrasMaaier.STDCut
flagparams['filtertype'] = dict(pyramid=0, tophat=1)[cfg.GrasMaaier.FilterType]
flagparams['nwindow'] = cfg.GrasMaaier.FilterWindow
flagparams['badneighbors'] = cfg.GrasMaaier.BadNeighbors
flag = flagData(twodarray, **flagparams)
else:
flag = (obs.data) == 0
Path(cfg.Output.OutputDir).mkdir(parents=True, exist_ok=True)
# calculate the folded array
if cfg.Folding:
print("Folding")
foldedarray = timeFolding(twodarray, cfg.Folding.nbins, period, flagged = flag, corrected_times=obs.times)
print("Done folding")
# make a waterfall plot of the result
plt.matshow((foldedarray-foldedarray.mean(axis=0))/foldedarray.std(axis=0))
if cfg.Output.SavePlots:
plt.savefig(cfg.Output.OutputDir+"/waterfall.pdf")
plt.show()
print("Dedispersing")
# do the dedispersion
pulse_profile = dedispersion(foldedarray, obs, period, obs.pulsar.DM, freq_fold_bins=cfg.Folding.nbinsdedisp)
# plot the final pulse profile
plt.plot(pulse_profile)
if cfg.Output.SavePlots:
plt.savefig(cfg.Output.OutputDir+"/dedisp_pulse.pdf")
plt.show()
if obs.fileformat != 'fits' and cfg.Output.ConvertRaw:
raw2fits(obs.data, cfg.Output.OutputDir+"/"+Path(cfg.FileName).stem+".fits", **cfg.ObsMetaData)