pub struct Schedule<Dim: Dimension>(/* private fields */);Expand description
Represents a sampling schedule. Schedules are represented as a list of booleans, where true means to take the sample at the position of the index and false means to not take the sample.
Implementations§
Source§impl<Dim: Dimension> Schedule<Dim>
impl<Dim: Dimension> Schedule<Dim>
Sourcepub const fn new(sched: Array<bool, Dim>) -> Schedule<Dim>
pub const fn new(sched: Array<bool, Dim>) -> Schedule<Dim>
Create a new schedule from a list of booleans
Sourcepub fn into_inner(self) -> Array<bool, Dim>
pub fn into_inner(self) -> Array<bool, Dim>
Unwrap the inner list of bools
Sourcepub fn count(&self) -> usize
pub fn count(&self) -> usize
Count the number of samples in the schedule. Note that this is operation linear in the length of the schedule.
Sourcepub fn decode(
encoded: &str,
encoding_type: EncodingType,
dims_rule: impl FnOnce(Dim) -> Result<Dim, String>,
) -> Result<Schedule<Dim>, ScheduleDecodingError>
pub fn decode( encoded: &str, encoding_type: EncodingType, dims_rule: impl FnOnce(Dim) -> Result<Dim, String>, ) -> Result<Schedule<Dim>, ScheduleDecodingError>
Decodes a schedule from a string. The format is expected to be a list of line-break separated sample positions, where each sample position is a comma separated list of numbers for each index in each dimension.
len_rule is a function that takes the minimum possible length to contain all of the values and returns either a length for the schedule or an error message that will be propagated. This is necessary because it is not known how many false values there there should be after the last true value, and it allows rejecting input that could cause resource exhaustion of the software. It would make sense to configure this function to return an error above a maximum value because it is possible to make a “schedule bomb” that would consume the entire RAM when decoded:
0
100000000000000000000§Example
let sched = Schedule::new(Array::from_vec(vec![true, false, true, true, false, true, false, false]));
assert_eq!(
Schedule::<Ix1>::decode(
"0\n2\n3\n5",
EncodingType::ZeroBased,
|max| Ok(Ix1(max[0].next_power_of_two()))
).unwrap(),
sched
);
assert!(
Schedule::<Ix1>::decode(
"1\n3\n4\n6",
EncodingType::OneBased,
|max| if max[0] > 4 { Err("Too big!".to_owned()) } else { Ok(max) },
).is_err(),
);
let sched = Schedule::new(Array::from_shape_vec(IxDyn(&[8, 2]).strides(IxDyn(&[1, 8])), vec![
false, false, true, false, false, false, false, false,
true, false, false, true, false, true, false, false,
]).unwrap());
assert_eq!(
Schedule::<IxDyn>::decode(
"1, 2\n3, 1\n4, 2\n6, 2",
EncodingType::OneBased,
|max| Ok(IxDyn(&max.as_array_view().iter().map(|v| v.next_power_of_two()).collect::<Vec<_>>())),
).unwrap(),
sched,
);
let sched = Schedule::new(Array::from_vec(vec![true, false, true, true, false, true, false]));
assert_eq!(
Schedule::<Ix1>::decode(
"0\n2\n3\n5",
EncodingType::ZeroBased,
|_| Ok(Ix1(7)),
).unwrap(),
sched,
);Sourcepub fn encode(&self, encoding_type: EncodingType) -> String
pub fn encode(&self, encoding_type: EncodingType) -> String
Writes the schedule to a string using the same format as is understood by Schedule::decode.
§Example
let sched = Schedule::new(Array::from_vec(vec![true, false, false, true, true]));
assert_eq!(sched.encode(EncodingType::ZeroBased), "0\n3\n4");
assert_eq!(sched.encode(EncodingType::OneBased), "1\n4\n5");assert_eq!(
Schedule::decode(
"1, 2\n3, 4",
EncodingType::OneBased,
|v: Ix2| Ok(v),
)
.unwrap()
.encode(EncodingType::OneBased),
"1, 2\n3, 4",
);Source§impl Schedule<Ix1>
impl Schedule<Ix1>
Sourcepub fn point_spread(&self) -> PointSpread
pub fn point_spread(&self) -> PointSpread
Calculates the Point Spread Function of the schedule.
The PSF is calculated as the discrete fourier transform of the schedule where true is replaced with 1. and false is replaced with 0..
If you take uniformly sampled data and set every sample not taken to zero, the Convolution Theorem states that your true signal will be convolved with the schedule’s PSF. Therefore, it is preferable to generate schedules where the PSF has minimal spikes because that minimizes sampling noise.
The PSF can also be thought of as a plot of global bias towards sampling a particular frequency. For example, a PSF spike at wavenumber 1/3 indicates a bias towards sampling at positions that are at multiples of three, or some offset of a multiple of three, thereby undersampling frequencies that are out of phase with this bias. Therefore, the PSF can be thought of as a plot of how much a schedule undersamples different phases of a particular frequency.
Sourcepub fn rlc(&self, seq: impl AsRef<[bool]>) -> Vec<u64>
pub fn rlc(&self, seq: impl AsRef<[bool]>) -> Vec<u64>
Calculate the Repeat Length Curve of the schedule for a given pattern.
This metric can be used to determine the number of repeating patterns in the sampling schedule. Schedules with fewer patterns are more condusive to signal reconstruction because patterns represent a local bias against sampling particular frequencies.
The first argument is the pattern to be searched for. The function returns a list where the element at index i is number of places in the schedule where seq is repeated i + 1 times followed by the first element of seq.
§Example
let sched = Schedule::new(Array::from_vec(vec![true, false, true, false, true, false, false, true, false, true]));
// The schedule has 3 instances of `T F T` and 1 instance of `T F T F T`
assert_eq!(sched.rlc([true, false]), vec![3, 1]);L. E. Cullen, A. Marchiori, D. Rovnyak, Magn Reson Chem 2023, 61(6), 337. https://doi.org/10.1002/mrc.5340
Trait Implementations§
impl<Dim: Eq + Dimension> Eq for Schedule<Dim>
impl<Dim: Dimension> StructuralPartialEq for Schedule<Dim>
Auto Trait Implementations§
impl<Dim> Freeze for Schedule<Dim>where
Dim: Freeze,
impl<Dim> RefUnwindSafe for Schedule<Dim>where
Dim: RefUnwindSafe,
impl<Dim> Send for Schedule<Dim>
impl<Dim> Sync for Schedule<Dim>
impl<Dim> Unpin for Schedule<Dim>where
Dim: Unpin,
impl<Dim> UnwindSafe for Schedule<Dim>where
Dim: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more