Skip to content

Commit

Permalink
updated optimizer and improved rendering math.
Browse files Browse the repository at this point in the history
  • Loading branch information
LLO918 committed Sep 11, 2024
1 parent 0831f3c commit 46f6f90
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 41 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ cargo run --bin optimize -- --idx-ra 24 --idx-dec 25 --idx-bt-mag 17 --idx-vt-ma
For other catalogs that satisfy the optimizer's requirements, simply replace the index values above
with the column indexes for those items in your catalog's data file.

If view changes, you will need to re-optimize with new fov_max.

### Optimizer command-line arguments

| Flag | Description | Default | Notes |
Expand All @@ -58,6 +60,7 @@ with the column indexes for those items in your catalog's data file.
| --idx-bt-mag | Index of bt_mag | | |
| --idx-ra | Index of right ascension | | |
| --idx-dec | Index of declination | | |
| --fov-max | Max value of fov w/h | | |


### Running the renderer
Expand Down
8 changes: 6 additions & 2 deletions src/bin/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use starfinder::parsing_utils::parse_star_record;
use std::fs::File;
use std::io::{BufReader, BufWriter, Write};
use std::time::Instant;
use std::f64::consts::PI;

const CSV_SEPARATOR: char = '|';

Expand Down Expand Up @@ -34,6 +35,9 @@ pub struct Args {

#[arg(long)]
idx_dec: usize,

#[arg(long)]
fov_max: f64,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -57,7 +61,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

let out_file = File::create(args.output)?;
let mut out_buffer = BufWriter::new(out_file);

let fov_scale = args.fov_max.to_radians()/(4.0*PI)
for (i, result) in csv_reader.records().enumerate() {
let record = result?;

Expand All @@ -71,7 +75,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
args.idx_vt_mag,
) {
Ok(star) => {
let grid_coords = star.coords.to_grid();
let grid_coords = star.coords.to_grid(fov_scale);
let ra = star.coords.ra;
let dec = star.coords.dec;
let grid_ra = grid_coords.ra;
Expand Down
73 changes: 38 additions & 35 deletions src/fov.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ use std::f64::consts::PI;

use crate::types::{CartesianCoords, EquatorialCoords};

// CAREFUL! If this value is ever changed, the optimize binary needs to be rerun!! The data is
// optimized against this grid resolution.
pub const GRID_RESOLUTION: f64 = 360.0;

pub fn get_fov(
center: EquatorialCoords,
fov_w: f64,
Expand All @@ -19,13 +15,14 @@ pub fn get_fov(
ra: 180.0_f64.to_radians(),
dec: 0.0_f64.to_radians(),
};
let fov_size = fov_w.max(fov_h)/ (4.0 * PI);
let ra_dif = center.ra - view_init_center.ra;
let dec_dif = center.dec - view_init_center.dec;
// Calculate FOV bounds in cartesian coords
let fov_w_half = fov_w / 2.0;
let fov_h_half = fov_h / 2.0;

let step_size = 2.0 * PI / GRID_RESOLUTION;
let step_size = fov_size / 20.0;
let bottom_left = EquatorialCoords {
ra: view_init_center.ra - fov_w_half,
dec: view_init_center.dec - fov_h_half,
Expand All @@ -47,16 +44,18 @@ pub fn get_fov(
}

let c_cartesian = center.to_cartesian();

let y_roll_axis_norm = (c_cartesian.x.powi(2) + c_cartesian.y.powi(2)).sqrt();
let y_roll_axis = CartesianCoords {
x: -c_cartesian.y,
y: c_cartesian.x,
x: c_cartesian.y/y_roll_axis_norm,
y: -c_cartesian.x/y_roll_axis_norm,
z: 0.0,
};

let x_roll = SMatrix::<f64, 3, 3>::new(
// Row 1
roll.cos(),
ra_dif.sin(),
ra_dif.cos(),
-ra_dif.sin(),
0.0,
// Row 2
ra_dif.sin(),
Expand All @@ -65,38 +64,39 @@ pub fn get_fov(
// Row 3
0.0,
0.0,
(1.0 - ra_dif.cos()) + ra_dif.cos(),
1.0
);
let y_roll = SMatrix::<f64, 3, 3>::new(
// Row 1
y_roll_axis.x.powi(2) * (1.0 - dec_dif.cos()) + dec_dif.cos(),
y_roll_axis.x * y_roll_axis.y * (1.0 - dec_dif.cos()) - (y_roll_axis.z * dec_dif.sin()),
y_roll_axis.x * y_roll_axis.z * (1.0 - dec_dif.cos()) + (y_roll_axis.y * dec_dif.sin()),
y_roll_axis.x * y_roll_axis.y * (1.0 - dec_dif.cos()),
y_roll_axis.y * dec_dif.sin(),
// Row 2
y_roll_axis.x * y_roll_axis.y * (1.0 - dec_dif.cos()) + (y_roll_axis.z * dec_dif.sin()),
y_roll_axis.x * y_roll_axis.y * (1.0 - dec_dif.cos()),
y_roll_axis.y.powi(2) * (1.0 - dec_dif.cos()) + dec_dif.cos(),
y_roll_axis.y * y_roll_axis.z * (1.0 - dec_dif.cos()) - (y_roll_axis.x * dec_dif.sin()),
- y_roll_axis.x * dec_dif.sin(),
// Row 3
y_roll_axis.x * y_roll_axis.z * (1.0 - dec_dif.cos()) - (y_roll_axis.y * dec_dif.sin()),
y_roll_axis.y * y_roll_axis.z * (1.0 - dec_dif.cos()) + (y_roll_axis.x * dec_dif.sin()),
y_roll_axis.z.powi(2) * (1.0 - dec_dif.cos()) + dec_dif.cos(),
- y_roll_axis.y * dec_dif.sin(),
y_roll_axis.x * dec_dif.sin(),
dec_dif.cos(),
);
let z_roll = SMatrix::<f64, 3, 3>::new(
// Row 1
c_cartesian.x.powi(2) * (1.0 - roll.cos()) + roll.cos(),
c_cartesian.x * c_cartesian.y * (1.0 - roll.cos()) - (c_cartesian.z * roll.sin()),
c_cartesian.x * c_cartesian.z * (1.0 - roll.cos()) + (c_cartesian.y * roll.sin()),
1.0,
0.0,
0.0,
// Row 2
c_cartesian.x * c_cartesian.y * (1.0 - roll.cos()) + (c_cartesian.z * roll.sin()),
c_cartesian.y.powi(2) * (1.0 - roll.cos()) + roll.cos(),
c_cartesian.y * c_cartesian.z * (1.0 - roll.cos()) - (c_cartesian.x * roll.sin()),
0.0,
roll.cos(),
-roll.sin(),
// Row 3
c_cartesian.x * c_cartesian.z * (1.0 - roll.cos()) - (c_cartesian.y * roll.sin()),
c_cartesian.y * c_cartesian.z * (1.0 - roll.cos()) + (c_cartesian.x * roll.sin()),
c_cartesian.z.powi(2) * (1.0 - roll.cos()) + roll.cos(),
0.0,
roll.sin(),
roll.cos(),
);

let transform = z_roll * y_roll * x_roll;

let transform = y_roll * x_roll * z_roll;
let mut final_grid: HashSet<EquatorialCoords> = HashSet::new();
for p in scatter_shot {
let vec: Vector3<f64> = Vector3::new(p.x, p.y, p.z);
Expand All @@ -107,16 +107,19 @@ pub fn get_fov(
z: transformed[(2, 0)],
}
.to_equatorial()
.to_grid();
.to_grid(fov_size);
let next_coord = EquatorialCoords {
ra: grid_coord.ra + 1.0,
dec: grid_coord.dec,
};
let last_coord = EquatorialCoords {
ra: grid_coord.ra - 1.0,
dec: grid_coord.dec,
};
final_grid.insert(last_coord);
final_grid.insert(next_coord);
final_grid.insert(grid_coord);
}

final_grid
}
/*
pub fn equatorial_to_grid(p: &EquatorialCoords) -> EquatorialCoords {
EquatorialCoords {
ra: ((p.ra / 2.0 * PI) * (1.0 - (2.0 * p.dec / PI).abs()) * APPROX_RES).round(),
dec: ((2.0 * p.dec / PI) * APPROX_RES).round(),
}
}*/
7 changes: 3 additions & 4 deletions src/types/coords.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::fov::GRID_RESOLUTION;
use serde::{Deserialize, Serialize};
use std::f64::consts::PI;
use std::hash::{Hash, Hasher};
Expand Down Expand Up @@ -67,10 +66,10 @@ impl EquatorialCoords {
}
}

pub fn to_grid(&self) -> EquatorialCoords {
pub fn to_grid(&self, fov_size: f64) -> EquatorialCoords {
EquatorialCoords {
ra: ((self.ra / 2.0 * PI) * (1.0 - (2.0 * self.dec / PI).abs()) * GRID_RESOLUTION).round(),
dec: ((2.0 * self.dec / PI) * GRID_RESOLUTION).round(),
ra: (self.ra / (2.0 * PI) * (1.0 - (2.0 * self.dec.abs() / PI)).powf(0.5) / fov_size).round(),
dec: (self.dec / 2.0 / fov_size).round(),
}
}
}
Expand Down

0 comments on commit 46f6f90

Please sign in to comment.