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 * rawNormalising 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
impl Normalizer
Sourcepub fn new(zero_offset: f64, scale: f64, minimum: f64, maximum: f64) -> Self
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.
Sourcepub fn with_blank(self, blank: Option<i64>) -> Self
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.
Sourcepub fn is_blank(&self, raw: f64) -> bool
pub fn is_blank(&self, raw: f64) -> bool
Whether raw is the BLANK value, and so carries no data.
Sourcepub fn for_bitpix(bitpix: Bitpix, zero_offset: f64, scale: f64) -> Option<Self>
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.
Sourcepub fn from_samples(
zero_offset: f64,
scale: f64,
samples: impl IntoIterator<Item = f64>,
) -> Self
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.
Sourcepub fn from_header(
header: &Header,
) -> Result<Self, Box<dyn Error + Send + Sync>>
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.
Sourcepub fn physical(&self, raw: f64) -> f64
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.
Sourcepub fn normalize(&self, raw: f64) -> f64
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
impl Clone for Normalizer
Source§fn clone(&self) -> Normalizer
fn clone(&self) -> Normalizer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for Normalizer
Source§impl Debug for Normalizer
impl Debug for Normalizer
Source§impl PartialEq for Normalizer
impl PartialEq for Normalizer
impl StructuralPartialEq for Normalizer
Auto Trait Implementations§
impl Freeze for Normalizer
impl RefUnwindSafe for Normalizer
impl Send for Normalizer
impl Sync for Normalizer
impl Unpin for Normalizer
impl UnsafeUnpin for Normalizer
impl UnwindSafe for Normalizer
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<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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