pub struct Wcs { /* private fields */ }Expand description
The world coordinate system of an image.
Built from a header’s CRPIXn, CRVALn, CDELTn, CDi_j, CROTAn and CTYPEn cards,
this converts between pixel positions and the sky coordinates they fall on.
The first two axes carry the projection, and Wcs::pixel_to_world works on
those; a cube’s remaining axes are read one at a time through
Wcs::pixel_to_world_axis.
Pixel coordinates follow the FITS convention: the centre of the first pixel
is (1.0, 1.0), not (0.0, 0.0). Use Wcs::pixel_to_world_indexed and
Wcs::world_to_pixel_indexed to work in zero-based array indices instead.
A pixel the projection cannot place on the sky — a corner of an all-sky
image falls outside the sky itself — comes back as NaN rather than as a
plausible coordinate somewhere else.
Implementations§
Source§impl Wcs
impl Wcs
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>>
Reads the world coordinate system out of header.
§Errors
Returns an error when the header carries no usable WCS — CRPIXn and CRVALn are both required — when it names a projection this crate does not implement, or when its celestial axes are given in units other than degrees.
Sourcepub fn transform(&self) -> [[f64; 2]; 2]
pub fn transform(&self) -> [[f64; 2]; 2]
The matrix taking pixel offsets to intermediate world coordinates, row-major.
Whichever of the three conventions the header used — a CDi_j matrix, a PCi_j matrix with CDELTn, or CDELTn with CROTAn — this is what it came to.
Sourcepub fn projection(&self) -> Projection
pub fn projection(&self) -> Projection
The projection this system uses.
Sourcepub fn is_celestial(&self) -> bool
pub fn is_celestial(&self) -> bool
Whether the first two axes describe a position on the sky, as opposed to a plain linear pair.
Sourcepub fn celestial_pole(&self) -> Option<(f64, f64)>
pub fn celestial_pole(&self) -> Option<(f64, f64)>
The celestial coordinates of the projection’s own pole, in degrees, for a system that has one.
For the zenithal projections — TAN among them — this is the reference point itself. For the whole-sky projections it is a quarter turn away from it, which is what an all-sky map is drawn about.
Sourcepub fn axis_count(&self) -> usize
pub fn axis_count(&self) -> usize
How many axes the header describes.
Sourcepub fn axis_type(&self, axis: usize) -> Option<&str>
pub fn axis_type(&self, axis: usize) -> Option<&str>
The CTYPEn of an axis, counting from zero.
Sourcepub fn axis_unit(&self, axis: usize) -> Option<&str>
pub fn axis_unit(&self, axis: usize) -> Option<&str>
The CUNITn of an axis, counting from zero — the unit its world coordinates are in.
Sourcepub fn pixel_to_world_axis(&self, axis: usize, pixel: f64) -> Option<f64>
pub fn pixel_to_world_axis(&self, axis: usize, pixel: f64) -> Option<f64>
The world coordinate at a pixel along one axis, counting from zero.
This is how a cube’s third axis is read: the wavelength, frequency or
time a plane was taken at. pixel is one-based, as FITS counts pixels.
A -LOG axis is read as the standard defines it, with the coordinate
growing geometrically rather than by a fixed step. The two celestial
axes have no coordinate of their own — they only mean anything together —
so they come back None; Wcs::pixel_to_world is what reads those.
Sourcepub fn world_to_pixel_axis(&self, axis: usize, world: f64) -> Option<f64>
pub fn world_to_pixel_axis(&self, axis: usize, world: f64) -> Option<f64>
The pixel a world coordinate falls on along one axis, the inverse of
Wcs::pixel_to_world_axis.
Sourcepub fn pixel_to_world(&self, pixel: (f64, f64)) -> (f64, f64)
pub fn pixel_to_world(&self, pixel: (f64, f64)) -> (f64, f64)
The sky coordinate at a pixel, in degrees.
pixel is one-based, as FITS counts pixels.
Sourcepub fn world_to_pixel(&self, world: (f64, f64)) -> (f64, f64)
pub fn world_to_pixel(&self, world: (f64, f64)) -> (f64, f64)
The pixel a sky coordinate falls on, in degrees in and one-based pixels out.
Sourcepub fn pixel_to_world_indexed(&self, index: (u32, u32)) -> (f64, f64)
pub fn pixel_to_world_indexed(&self, index: (u32, u32)) -> (f64, f64)
As Wcs::pixel_to_world, but taking a zero-based array index.
Sourcepub fn world_to_pixel_indexed(
&self,
world: (f64, f64),
width: u32,
height: u32,
) -> Option<(u32, u32)>
pub fn world_to_pixel_indexed( &self, world: (f64, f64), width: u32, height: u32, ) -> Option<(u32, u32)>
As Wcs::world_to_pixel, but returning a zero-based array index.
The index is rounded to the nearest pixel, and None when the
coordinate falls outside the width by height image.
Trait Implementations§
impl StructuralPartialEq for Wcs
Auto Trait Implementations§
impl Freeze for Wcs
impl RefUnwindSafe for Wcs
impl Send for Wcs
impl Sync for Wcs
impl Unpin for Wcs
impl UnsafeUnpin for Wcs
impl UnwindSafe for Wcs
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