Schedule

Struct Schedule 

Source
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>

Source

pub const fn new(sched: Array<bool, Dim>) -> Schedule<Dim>

Create a new schedule from a list of booleans

Source

pub fn into_inner(self) -> Array<bool, Dim>

Unwrap the inner list of bools

Source

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.

Source

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,
);
Source

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>

Source

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.

Source

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§

Source§

impl<Dim: Clone + Dimension> Clone for Schedule<Dim>

Source§

fn clone(&self) -> Schedule<Dim>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Dim: Dimension> Debug for Schedule<Dim>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Dim: Dimension> Deref for Schedule<Dim>

Source§

type Target = ArrayBase<OwnedRepr<bool>, Dim>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<Dim: Dimension> DerefMut for Schedule<Dim>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<Dim: Dimension> Display for Schedule<Dim>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Dim: PartialEq + Dimension> PartialEq for Schedule<Dim>

Source§

fn eq(&self, other: &Schedule<Dim>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Dim: Eq + Dimension> Eq for Schedule<Dim>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> TraceOutput for T
where T: Any + Debug + Display,