Skip to content

Commit

Permalink
add --provided-chan-ranges to fix #149
Browse files Browse the repository at this point in the history
  • Loading branch information
d3v-null committed Sep 28, 2024
1 parent bc273ae commit 2d0b128
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ INPUT:
SELECTION:
--no-sel-autos [WIP] Deselect autocorrelations
--no-sel-flagged-ants [WIP] Deselect flagged antennas
--provided-chan-ranges Only consider provided channels
--sel-ants <ANTS>... [WIP] Antenna to select
--sel-chan-ranges <RANGES> Select separate channel ranges
--sel-time <MIN> <MAX> Timestep index range (inclusive) to select
Expand Down
49 changes: 33 additions & 16 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,8 @@ impl ChannelRanges {
Ok(Self { ranges })
}

/// Create a new `ChannelRanges` object spanning all available channels in the metafits context
pub fn all(context: &CorrelatorContext) -> Self {
let coarse_chan_indices = &(0..context.num_coarse_chans).collect_vec();
/// create coarse channel ranges from a slice of indices
pub fn from_idxs(context: &CorrelatorContext, coarse_chan_indices: &[usize]) -> Self {
// get the first value in the vector
let mut range_start_idx = coarse_chan_indices[0];
let mut range_end_idx = range_start_idx;
Expand All @@ -226,6 +225,17 @@ impl ChannelRanges {
ranges.push((range_start_idx, range_end_idx));
Self { ranges }
}

/// Create a new `ChannelRanges` object spanning all available channels in the metafits context
pub fn all(context: &CorrelatorContext) -> Self {
let coarse_chan_indices = &(0..context.num_coarse_chans).collect_vec();
Self::from_idxs(context, coarse_chan_indices)
}

/// Create a new `ChannelRanges` object spanning all available channels in the metafits context
pub fn provided(context: &CorrelatorContext) -> Self {
Self::from_idxs(context, &context.provided_coarse_chan_indices)
}
}

impl Display for BirliContext<'_> {
Expand Down Expand Up @@ -659,6 +669,9 @@ impl<'a> BirliContext<'a> {
arg!(--"sel-chan-ranges" <RANGES> "Select separate channel ranges")
.help_heading("SELECTION")
.required(false),
arg!(--"provided-chan-ranges" "Only consider provided channels")
.help_heading("SELECTION")
.required(false),

// resource limit options
arg!(--"time-chunk" <STEPS> "Process observation in chunks of <STEPS> timesteps.")
Expand Down Expand Up @@ -876,19 +889,23 @@ impl<'a> BirliContext<'a> {
corr_ctx: &CorrelatorContext,
matches: &clap::ArgMatches,
) -> Result<ChannelRanges, BirliError> {
let sel_chan_ranges = ChannelRanges::all(corr_ctx);
if matches.is_present("sel-chan-ranges") {
#[allow(clippy::option_if_let_else)]
match matches.value_of("sel-chan-ranges") {
Some(range_str) => ChannelRanges::new(range_str),
None => Err(BirliError::CLIError(InvalidCommandLineArgument {
option: "--sel-chan-ranges <RANGES>".into(),
expected: "comma-separated ranges indexing the metafits coarse channels, e.g. 0-10,20-30".into(),
received: "no value".into(),
})),
}
} else {
Ok(sel_chan_ranges)
let all_chan_ranges = ChannelRanges::all(corr_ctx);
let provided_chan_ranges = ChannelRanges::provided(corr_ctx);
match (matches.is_present("sel-chan-ranges"), matches.is_present("provided-chan-ranges")) {
(true, true) => panic!("can't use both --provided-chan-ranges and --sel-chan-ranges"),
(true, _) => {
#[allow(clippy::option_if_let_else)]
match matches.value_of("sel-chan-ranges") {
Some(range_str) => ChannelRanges::new(range_str),
None => Err(BirliError::CLIError(InvalidCommandLineArgument {
option: "--sel-chan-ranges <RANGES>".into(),
expected: "comma-separated ranges indexing the metafits coarse channels, e.g. 0-10,20-30".into(),
received: "no value".into(),
})),
}
},
(_, true) => Ok(provided_chan_ranges),
(_, _) => Ok(all_chan_ranges),
}
}

Expand Down

0 comments on commit 2d0b128

Please sign in to comment.