Skip to content

Commit

Permalink
allow the creation of a wcs from a wcsparams serializable/deserializa…
Browse files Browse the repository at this point in the history
…ble struct. This can be created from a JSON dict
  • Loading branch information
bmatthieu3 committed Jul 5, 2024
1 parent a7ffe00 commit 5afc3a6
Show file tree
Hide file tree
Showing 6 changed files with 373 additions and 270 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ enum_dispatch = "0.3.8"
fitsrs = "0.2.9"
quick-error = "2.0.1"
paste = "1.0.11"
serde = { version = "1", features = ["derive"] }

[dev-dependencies]
image = "0.24.5"
csv = "1.1"
serde = { version = "1", features = ["derive"] }
glob = "0.3.0"
35 changes: 18 additions & 17 deletions src/coo_system.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::f64::consts::PI;

use fitsrs::hdu::header::{extension::image::Image, Header};
use mapproj::LonLat;
use mapproj::XYZ;

use crate::error::Error;
use crate::utils;
use crate::params::WCSParams;

pub enum RadeSys {
/// International Celestial Reference System
Expand All @@ -21,16 +20,18 @@ pub enum RadeSys {
}

impl RadeSys {
pub fn parse(header: &Header<Image>) -> Result<Self, Error> {
let radesys = utils::retrieve_mandatory_parsed_keyword::<String>(header, "RADESYS ")?;

match radesys.as_str() {
"ICRS" => Ok(RadeSys::ICRS),
"FK5" => Ok(RadeSys::Fk5),
"FK4" => Ok(RadeSys::Fk4),
"FK4-NO-E" => Ok(RadeSys::Fk4NoE),
"GAPPT" => Ok(RadeSys::GAPPT),
_ => Err(Error::UnrecognizedRadeSys(radesys)),
pub fn parse(params: &WCSParams) -> Option<Result<Self, Error>> {
if let Some(radesys) = &params.radesys {
match radesys.as_str() {
"ICRS" => Some(Ok(RadeSys::ICRS)),
"FK5" => Some(Ok(RadeSys::Fk5)),
"FK4" => Some(Ok(RadeSys::Fk4)),
"FK4-NO-E" => Some(Ok(RadeSys::Fk4NoE)),
"GAPPT" => Some(Ok(RadeSys::GAPPT)),
_ => Some(Err(Error::UnrecognizedRadeSys(radesys.to_string()))),
}
} else {
None
}
}
}
Expand All @@ -49,15 +50,15 @@ pub enum CooSystem {
}

impl CooSystem {
pub fn parse(header: &Header<Image>) -> Result<Self, Error> {
let equinox = utils::retrieve_mandatory_parsed_keyword::<f64>(header, "EQUINOX ");
let radesys = RadeSys::parse(header);
pub fn parse(params: &WCSParams) -> Result<Self, Error> {
let equinox = params.equinox;
let radesys = RadeSys::parse(params);

let coo_system = if let (Ok(radesys), Ok(equinox)) = (radesys, equinox) {
let coo_system = if let (Some(Ok(radesys)), Some(equinox)) = (radesys, equinox) {
// if there is a radesys take it into account
CooSystem::CUSTOM { radesys, equinox }
} else {
let ctype1 = utils::retrieve_mandatory_parsed_keyword::<String>(header, "CTYPE1 ")?;
let ctype1 = &params.ctype1;

match ctype1.as_bytes()[0] {
b'G' => CooSystem::GALACTIC,
Expand Down
Loading

0 comments on commit 5afc3a6

Please sign in to comment.