Skip to main content

Normalizer

Struct Normalizer 

Source
pub struct Normalizer { /* private fields */ }
Expand description

Maps raw FITS array values onto the 0.0..=1.0 range.

A FITS data array stores raw values that have to be shifted and scaled into physical units before they mean anything:

physical = BZERO + BSCALE * raw

Normalising additionally needs to know which physical values correspond to black and white. Those come from the DATAMIN and DATAMAX cards when the file carries them, and otherwise from the full representable range of BITPIX — for example BITPIX = 16 with BZERO = 32768 describes unsigned 16-bit samples, so physical 0 maps to 0.0 and physical 65535 maps to 1.0.

Floating point images have no representable range to fall back on, so they require DATAMIN and DATAMAX; see Normalizer::from_header.

An integer image may also mark pixels as carrying no value at all, with a BLANK card naming the raw value that means “undefined”. Such pixels have no physical value and no place on the 0.0..=1.0 scale, so both physical and normalize answer NaN for them — the same way FITS itself spells an undefined floating point sample.

Implementations§

Source§

impl Normalizer

Source

pub fn new(zero_offset: f64, scale: f64, minimum: f64, maximum: f64) -> Self

Builds a normaliser from explicit black and white points, given in physical units.

Source

pub fn with_blank(self, blank: Option<i64>) -> Self

Marks blank as the raw value that means “this pixel is undefined”.

This is the BLANK card, which the standard defines only for the integer BITPIX types; a floating point image says the same thing with a NaN and needs no card for it.

Source

pub fn blank(&self) -> Option<f64>

The raw value this normaliser treats as undefined, if any.

Source

pub fn is_blank(&self, raw: f64) -> bool

Whether raw is the BLANK value, and so carries no data.

Source

pub fn for_bitpix(bitpix: Bitpix, zero_offset: f64, scale: f64) -> Option<Self>

Builds a normaliser spanning the full representable range of bitpix.

Returns None for the floating point types, which have no such range; use Normalizer::from_samples or Normalizer::new for those.

Source

pub fn from_samples( zero_offset: f64, scale: f64, samples: impl IntoIterator<Item = f64>, ) -> Self

Builds a normaliser whose black and white points are the smallest and largest values actually present in samples.

This is the honest choice for floating point images, which carry no representable range — but it needs every sample up front, so it is only available once the whole array has been read.

Source

pub fn from_header( header: &Header, ) -> Result<Self, Box<dyn Error + Send + Sync>>

Builds a normaliser from a header’s BITPIX, BZERO, BSCALE, DATAMIN and DATAMAX cards.

§Errors

Returns an error for a floating point image (BITPIX -32 or -64) that carries neither DATAMIN nor DATAMAX. Such an image has no black and white point that can be known without reading every pixel, so a single-pass normalisation is not possible — read the image with ImageHDU::read_image instead, which has the whole array available.

Source

pub fn physical(&self, raw: f64) -> f64

Converts a raw array value into physical units.

A BLANK pixel has no physical value, and reads as NaN.

Source

pub fn normalize(&self, raw: f64) -> f64

Converts a raw array value into the 0.0..=1.0 range.

Values outside the black and white points are clamped, which matters when DATAMIN and DATAMAX do not actually bound the data. A BLANK pixel is not clamped into range but reads as NaN, so that “undefined” stays distinguishable from “black”.

Trait Implementations§

Source§

impl Clone for Normalizer

Source§

fn clone(&self) -> Normalizer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Normalizer

Source§

impl Debug for Normalizer

Source§

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

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

impl PartialEq for Normalizer

Source§

fn eq(&self, other: &Normalizer) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Normalizer

Auto Trait Implementations§

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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.