Skip to content

Commit

Permalink
Use a blocks/samples-per-block scheme in make_raw
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjjennings committed Oct 26, 2023
1 parent b32426a commit 047c279
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions cycspec_simulator/make_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from .metadata import ObservingMetadata
from .guppi_raw import write

def make_raw(template_file, polyco_file, out_file, n_samples, chan_bw,
nchan, obsfreq, scattering_time, start_mjd, start_second):
def make_raw(template_file, polyco_file, out_file, samples_per_block, blocks, overlap,
chan_bw, nchan, obsfreq, scattering_time, start_mjd, start_second):
"""
Create a file with simulated data in GUPPI Raw format.
Expand Down Expand Up @@ -51,14 +51,15 @@ def make_raw(template_file, polyco_file, out_file, n_samples, chan_bw,
if start_second is None:
start_second = predictor.epoch.second
start_second += int(np.round(predictor.epoch.offset))
n_samples = samples_per_block*blocks + overlap
n_extra_samples = pattern.impulse_response.shape[-1] - 1
t_start = Time(start_mjd, start_second, -n_extra_samples/chan_bw)
data = model.sample(n_samples + n_extra_samples, t_start=t_start)
data = pattern.scatter(data)

metadata = ObservingMetadata.from_file(template_file)
metadata.observer = "cycspec-simulator"
write(out_file, data, metadata=metadata)
write(out_file, data, samples_per_block, overlap=overlap, metadata=metadata)

def main():
import argparse
Expand All @@ -67,7 +68,9 @@ def main():
parser.add_argument('-t', '--template-file', type=str, help="Template file (PSRFITS format)")
parser.add_argument('-p', '--polyco-file', type=str, help="TEMPO Polyco file")
parser.add_argument('-o', '--out-file', type=str, help="Output file name")
parser.add_argument('-n', '--n-samples', type=int, help="Number of samples to simulate")
parser.add_argument('-n', '--samples-per-block', type=int, help="Number of samples per block")
parser.add_argument('-B', '--blocks', type=int, help="Number of blocks")
parser.add_argument('-O', '--overlap', type=int, default=0, help="Number of overlap samples per block")
parser.add_argument('-c', '--nchan', type=int, default=1, help="Number of channels to simulate")
parser.add_argument('-b', '--bandwidth', type=float, help="Channel bandwidth (MHz)")
parser.add_argument('-f', '--obsfreq', type=float, help="Observing frequency (MHz)")
Expand All @@ -80,7 +83,9 @@ def main():
args.template_file,
args.polyco_file,
args.out_file,
args.n_samples,
args.samples_per_block,
args.blocks,
args.overlap,
args.bandwidth*1e6,
args.nchan,
args.obsfreq*1e6,
Expand Down

0 comments on commit 047c279

Please sign in to comment.