Skip to content

Commit

Permalink
Added calc_max_nsub script
Browse files Browse the repository at this point in the history
  • Loading branch information
NickSwainston committed Feb 2, 2024
1 parent a39d418 commit d685301
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
52 changes: 52 additions & 0 deletions meerpipe/calc_max_nsub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import math
import numpy as np

def calc_max_nsub(
sn,
nchan,
duration,
input_nsub,
sn_desired=12.,
minimum_duration=480.,
):
"""
Calculate the maximum number of time subintegrations of sensitive ToAs for an archive.
Parameters
----------
sn : float
The signal-to-noise ratio of the archive.
nchan : int
The number of frequency channels in the decimated archive.
duration : float
The duration of the archive in seconds.
input_nsub : int
The number of subintegrations of the input archive.
sn_desired : float
The desired signal-to-noise ratio (default: 12.).
minimum_duration : float
The minimum duration of the archive in seconds (default: 480.).
Returns
-------
nsub : int
The estimated number of subintegrations that will create the maximum number of sensitive ToAs.
"""
# Calc estimated sn when channelised
sn_chan = sn / np.sqrt(nchan)

# Calc duration estimate to get desired sn
estimated_duration = duration * ( sn_desired / sn_chan ) **2

if estimated_duration < minimum_duration:
# estimated duration is less than minimum so us minimum
estimated_duration = minimum_duration

# Work out nsub using math.floor to round down
nsub = math.floor( duration / estimated_duration )

if nsub > input_nsub:
# nsub is greater than input so use input
nsub = input_nsub

return nsub
60 changes: 60 additions & 0 deletions meerpipe/scripts/calc_max_nsub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import argparse

from meerpipe.calc_max_nsub import calc_max_nsub

def main():
parser = argparse.ArgumentParser(description="Calculate maximum number of time subintegratons of sensitive ToAs for an archive")
parser.add_argument(
"--sn",
type=float,
required=True
help="The signal-to-noise ratio of the archive",
)
parser.add_argument(
"--nchan",
type=int,
required=True
help="The number of frequency channels in the decimated archive",
)
parser.add_argument(
"--duration",
type=float,
required=True
help="The duration of the archive in seconds",
)
parser.add_argument(
"--input_nsub",
type=float,
required=True
help="The number of subintegrations of the input archive",
)
parser.add_argument(
"--sn_desired",
type=float,
default=12.,
help="The desired signal-to-noise ratio (default: 12.)",
)
parser.add_argument(
"--minimum_duration",
type=float,
default=480.,
help="The minimum duration of the archive in seconds (default: 480.)",
)
args = parser.parse_args()

nsub = calc_max_nsub(
sn,
nchan,
duration,
input_nsub,
sn_desired=12.,
minimum_duration=480,
)
if nsub = 1:
print("1")
else:
print(f"1 {nsub}")


if __name__ == '__main__':
main()

0 comments on commit d685301

Please sign in to comment.