Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wise fov rotation #110

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fixed a time offset in the FOV's downloaded from IRSA WISE/NEOWISE. They were offset
by 4.4 seconds.
- Fixed rotation approximation in WISE/NEOWISE field of views which was causing a small
percentage of objects to not be found during FOV checks when they were close to the
edge of the field.


## [0.3.0] - 2024 - 8 - 28
Expand Down
20 changes: 17 additions & 3 deletions src/kete/rust/fovs/definitions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use nalgebra::Vector3;
use kete_core::fov::{self, NeosBand};
use kete_core::fov::{FovLike, SkyPatch};
use nalgebra::Vector3;
use pyo3::{exceptions, prelude::*};

use crate::vector::VectorLike;
Expand Down Expand Up @@ -156,8 +156,8 @@ impl From<fov::FOV> for AllowedFOV {

#[pymethods]
impl PyWiseCmos {
#[new]
pub fn new(
#[staticmethod]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping the old constructor, but downgrading it from the main constructor to just 'from_pointing'.

pub fn from_pointing(
pointing: VectorLike,
rotation: f64,
observer: PyState,
Expand All @@ -176,6 +176,20 @@ impl PyWiseCmos {
))
}

#[new]
pub fn new(
corners: [VectorLike; 4],
observer: PyState,
frame_num: u64,
scan_id: String,
) -> Self {
let corners: [Vector3<f64>; 4] = corners.map(|x| x.into_vec(observer.frame()));
let scan_id = scan_id.into();
PyWiseCmos(fov::WiseCmos::from_corners(
corners, observer.0, frame_num, scan_id,
))
}

/// Position of the observer in this FOV.
#[getter]
pub fn observer(&self) -> PyState {
Expand Down
41 changes: 35 additions & 6 deletions src/kete/wise.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from . import spice
from .cache import cache_path, download_file
from .time import Time
from .vector import Vector
from .vector import Vector, Frames
from .irsa import IRSA_URL, query_irsa_tap, plot_fits_image, zoom_plot, annotate_plot
from .deprecation import rename

Expand Down Expand Up @@ -570,7 +570,20 @@ def fetch_WISE_fovs(phase):
return FOVList.load(filename)

table = phase.frame_meta_table
cols = ["scan_id", "frame_num", "mjd", "ra", "dec"]
cols = [
"scan_id",
"frame_num",
"mjd",
"w1ra1",
"w1ra2",
"w1ra3",
"w1ra4",
"w1dec1",
"w1dec2",
"w1dec3",
"w1dec4",
"crota",
]
mjd_start = Time(phase.jd_start).mjd
mjd_end = Time(phase.jd_end).mjd

Expand All @@ -583,13 +596,29 @@ def fetch_WISE_fovs(phase):
res["jd"] = jd

fovs = []
for row in res.itertuples():
for _, row in res.iterrows():
state = spice.get_state("WISE", row.jd)

pointing = Vector.from_ra_dec(row.ra, row.dec).as_ecliptic
# Each band has a slightly different size on sky.
# Kete represents all bands simultaneously, so this information is not kept
# track of. In order to deal with this, here we load the W1 ra/dec, and then
# push the corners out by 1 arc-minute to act as a bit of a buffer region.

corners = []
for i in range(4):
corners.append(Vector.from_ra_dec(row[f"w1ra{i+1}"], row[f"w1dec{i+1}"]))

pointing = np.mean(corners, axis=0)
pointing = Vector(pointing, frame=Frames.Equatorial)

# shifting the corners out by 1 arc-minute
shifted_corners = []
for corner in corners:
rot_vec = np.cross(pointing, corner)
shifted_corners.append(corner.rotate_around(rot_vec, 1 / 60))

fov = WiseCmos(
pointing,
0.0,
shifted_corners[::-1],
state,
row.frame_num,
row.scan_id,
Expand Down
19 changes: 19 additions & 0 deletions src/kete_core/src/fov/wise.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! # WISE Fov definitions.
use core::f64;

use super::{Contains, FovLike, Frame, OnSkyRectangle, SkyPatch, FOV};
use crate::constants::WISE_WIDTH;
use crate::prelude::*;
Expand Down Expand Up @@ -42,6 +44,23 @@ impl WiseCmos {
scan_id,
}
}

/// Create a Wise fov from corners
pub fn from_corners(
corners: [Vector3<f64>; 4],
observer: State,
frame_num: u64,
scan_id: Box<str>,
) -> Self {
let patch = OnSkyRectangle::from_corners(corners, observer.frame);
Self {
patch,
observer,
frame_num,
rotation: f64::NAN,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have like to removed this variable, but backwards compatibility makes this not possible currently.

scan_id,
}
}
}

impl FovLike for WiseCmos {
Expand Down
4 changes: 2 additions & 2 deletions src/kete_core/src/propagation/radau.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ where
integrator.metadata,
));
}
let mut next_step_size: f64 = 1.0_f64.copysign(integrator.final_time - integrator.cur_time);
let mut next_step_size: f64 = 0.1_f64.copysign(integrator.final_time - integrator.cur_time);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tiny adjustment let to a reduction in 50km discretization noise on propagation near earth.


let mut step_failures = 0;
loop {
Expand All @@ -190,7 +190,7 @@ where
match integrator.step(next_step_size) {
Ok(s) => {
next_step_size = s;
if integrator.cur_time == integrator.final_time {
if (integrator.cur_time - integrator.final_time).abs() < 1e-12 {
return Ok((
integrator.cur_state,
integrator.cur_state_der,
Expand Down