diff --git a/signalgen.py b/signalgen.py index efe3d8a..1777952 100755 --- a/signalgen.py +++ b/signalgen.py @@ -28,6 +28,7 @@ LOG_MIN_DM = 2.5 LOG_MAX_DM = 3.5 LOG_MIN_WIDTH = 0 LOG_MAX_WIDTH = 3 #in ms +MAX_BURSTS = 4 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. @@ -130,43 +131,53 @@ def addBurst(values): 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 - if values.rsamp: - #generate the values AND save the values to file for comparison later - dm, pWidth = randomDMandWidth() - with open(values.thisRunName, "a") as file: - file.write(f"{str(round(dm)).ljust(6)} pc/cc {str(round(pWidth,3))} s {basename}\n") - else: - dm = values.dm - pWidth = 0.001 + #check if this is part of a rng run + if values.rsamp: + #generate the values AND save the values to file for comparison later + dm, pWidth = randomDMandWidth() + with open(values.thisRunName, "a") as file: + file.write(f"{str(round(dm)).ljust(6)} pc/cc {str(round(pWidth,3))} s {basename}\n") + else: + dm = values.dm + pWidth = 0.001 - #first version is very simple, plan on adding more complex injections in future - pulseObj = create.SimpleGaussPulse( - sigma_time=pWidth, - sigma_freq=350, - center_freq = filterbankObj.your_header.center_freq, - dm = dm, - tau = 20, - phi=np.pi / 3, #does nothing if nscint = 0 - spectral_index_alpha=0, - chan_freqs = filterbankObj.chan_freqs, - tsamp = filterbankObj.your_header.tsamp, - nscint=0, - bandpass = bpWeights - ) - pulse = pulseObj.sample_pulse(nsamp=values.nsamp) #30000 by default - - logger.info("Injecting pulse") - #inject pulse - injectedSpectra = inject.inject_constant_into_file( - yr_input = filterbankObj, - pulse = pulse, - start = samples // 3 - ) + #first version is very simple, plan on adding more complex injections in future + pulseObj = create.SimpleGaussPulse( + sigma_time=pWidth, + sigma_freq=350, + center_freq = filterbankObj.your_header.center_freq, + dm = dm, + tau = 20, + phi=np.pi / 3, #does nothing if nscint = 0 + spectral_index_alpha=0, + chan_freqs = filterbankObj.chan_freqs, + tsamp = filterbankObj.your_header.tsamp, + nscint=0, + bandpass = bpWeights + ) + pulse = pulseObj.sample_pulse(nsamp=values.nsamp) #30000 by default + + logger.info("Injecting pulse and saving file.") + #inject pulse + inject.inject_constant_into_file( + yr_input = filterbankObj, + pulse = pulse, + 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" sigprocObj = make_sigproc_object( rawdatafile=newName, #d @@ -194,7 +205,7 @@ def addBurst(values): sigprocObj.append_spectra(injectedSpectra, newName) logger.info(f"{newName} successfully written.") 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.") """