Skip to main content

Wcs

Struct Wcs 

Source
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

Source

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.

Source

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.

Source

pub fn projection(&self) -> Projection

The projection this system uses.

Source

pub fn is_celestial(&self) -> bool

Whether the first two axes describe a position on the sky, as opposed to a plain linear pair.

Source

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.

Source

pub fn axis_count(&self) -> usize

How many axes the header describes.

Source

pub fn axis_type(&self, axis: usize) -> Option<&str>

The CTYPEn of an axis, counting from zero.

Source

pub fn axis_unit(&self, axis: usize) -> Option<&str>

The CUNITn of an axis, counting from zero — the unit its world coordinates are in.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn pixel_to_world_indexed(&self, index: (u32, u32)) -> (f64, f64)

As Wcs::pixel_to_world, but taking a zero-based array index.

Source

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§

Source§

impl Clone for Wcs

Source§

fn clone(&self) -> Wcs

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 Debug for Wcs

Source§

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

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

impl PartialEq for Wcs

Source§

fn eq(&self, other: &Wcs) -> 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 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> 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.