multiple pulses in same file
This commit is contained in:
parent
7e6bdcb475
commit
2ef005ca70
81
signalgen.py
81
signalgen.py
|
@ -28,6 +28,7 @@ LOG_MIN_DM = 2.5
|
||||||
LOG_MAX_DM = 3.5
|
LOG_MAX_DM = 3.5
|
||||||
LOG_MIN_WIDTH = 0
|
LOG_MIN_WIDTH = 0
|
||||||
LOG_MAX_WIDTH = 3 #in ms
|
LOG_MAX_WIDTH = 3 #in ms
|
||||||
|
MAX_BURSTS = 4
|
||||||
rng = np.random.default_rng()
|
rng = np.random.default_rng()
|
||||||
|
|
||||||
#This function from https://josephwkania.github.io/will/examples/inject_pulse.html#Show-how-we-can-inject-a-pulse-into-a-GREENBURST-filterbank.
|
#This function from https://josephwkania.github.io/will/examples/inject_pulse.html#Show-how-we-can-inject-a-pulse-into-a-GREENBURST-filterbank.
|
||||||
|
@ -130,43 +131,53 @@ def addBurst(values):
|
||||||
|
|
||||||
logger.info(f"{basename} loaded. Sampling pulse {values.nsamp} times.")
|
logger.info(f"{basename} loaded. Sampling pulse {values.nsamp} times.")
|
||||||
|
|
||||||
#create pulse
|
pulseNum = rng.integers(1, high=MAX_BURSTS, endpoint=True)
|
||||||
|
starts = np.arange(samples//4, 3*(samples//4), num=pulseNum, dtype=int)
|
||||||
|
while pulseNum > 0:
|
||||||
|
start = starts[pulseNum]
|
||||||
|
#create pulse
|
||||||
|
|
||||||
#check if this is part of a rng run
|
#check if this is part of a rng run
|
||||||
if values.rsamp:
|
if values.rsamp:
|
||||||
#generate the values AND save the values to file for comparison later
|
#generate the values AND save the values to file for comparison later
|
||||||
dm, pWidth = randomDMandWidth()
|
dm, pWidth = randomDMandWidth()
|
||||||
with open(values.thisRunName, "a") as file:
|
with open(values.thisRunName, "a") as file:
|
||||||
file.write(f"{str(round(dm)).ljust(6)} pc/cc {str(round(pWidth,3))} s {basename}\n")
|
file.write(f"{str(round(dm)).ljust(6)} pc/cc {str(round(pWidth,3))} s {basename}\n")
|
||||||
else:
|
else:
|
||||||
dm = values.dm
|
dm = values.dm
|
||||||
pWidth = 0.001
|
pWidth = 0.001
|
||||||
|
|
||||||
#first version is very simple, plan on adding more complex injections in future
|
#first version is very simple, plan on adding more complex injections in future
|
||||||
pulseObj = create.SimpleGaussPulse(
|
pulseObj = create.SimpleGaussPulse(
|
||||||
sigma_time=pWidth,
|
sigma_time=pWidth,
|
||||||
sigma_freq=350,
|
sigma_freq=350,
|
||||||
center_freq = filterbankObj.your_header.center_freq,
|
center_freq = filterbankObj.your_header.center_freq,
|
||||||
dm = dm,
|
dm = dm,
|
||||||
tau = 20,
|
tau = 20,
|
||||||
phi=np.pi / 3, #does nothing if nscint = 0
|
phi=np.pi / 3, #does nothing if nscint = 0
|
||||||
spectral_index_alpha=0,
|
spectral_index_alpha=0,
|
||||||
chan_freqs = filterbankObj.chan_freqs,
|
chan_freqs = filterbankObj.chan_freqs,
|
||||||
tsamp = filterbankObj.your_header.tsamp,
|
tsamp = filterbankObj.your_header.tsamp,
|
||||||
nscint=0,
|
nscint=0,
|
||||||
bandpass = bpWeights
|
bandpass = bpWeights
|
||||||
)
|
)
|
||||||
pulse = pulseObj.sample_pulse(nsamp=values.nsamp) #30000 by default
|
pulse = pulseObj.sample_pulse(nsamp=values.nsamp) #30000 by default
|
||||||
|
|
||||||
logger.info("Injecting pulse")
|
logger.info("Injecting pulse and saving file.")
|
||||||
#inject pulse
|
#inject pulse
|
||||||
injectedSpectra = inject.inject_constant_into_file(
|
inject.inject_constant_into_file(
|
||||||
yr_input = filterbankObj,
|
yr_input = filterbankObj,
|
||||||
pulse = pulse,
|
pulse = pulse,
|
||||||
start = samples // 3
|
start = start,
|
||||||
)
|
out_fil = path.join("./", f"{basename}_injected.fil")
|
||||||
|
)
|
||||||
|
#reload into object
|
||||||
|
filterbankObj = Your(path.join("./", f"{basename}_injected.fil"))
|
||||||
|
pulseNum -= 1
|
||||||
|
os.remove(path.join("./", f"{basename}_trunc.fil")) #delete truncated file to save 2GB of disk space
|
||||||
|
logger.info(f"Truncated file removed.")
|
||||||
|
|
||||||
#now generate new filterbank file
|
""" #now generate new filterbank file
|
||||||
newName = f"{basename}_injected.fil"
|
newName = f"{basename}_injected.fil"
|
||||||
sigprocObj = make_sigproc_object(
|
sigprocObj = make_sigproc_object(
|
||||||
rawdatafile=newName, #d
|
rawdatafile=newName, #d
|
||||||
|
@ -194,7 +205,7 @@ def addBurst(values):
|
||||||
sigprocObj.append_spectra(injectedSpectra, newName)
|
sigprocObj.append_spectra(injectedSpectra, newName)
|
||||||
logger.info(f"{newName} successfully written.")
|
logger.info(f"{newName} successfully written.")
|
||||||
os.remove(path.join("./", f"{basename}_trunc.fil")) #delete truncated file to save 2GB of disk space
|
os.remove(path.join("./", f"{basename}_trunc.fil")) #delete truncated file to save 2GB of disk space
|
||||||
logger.info(f"Truncated file removed.")
|
logger.info(f"Truncated file removed.") """
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue