Skip to content

Commit

Permalink
For Catalog only: plot the sources when the footprints are too small
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatthieu3 committed Apr 12, 2024
1 parent a1434f7 commit 3dcdeee
Show file tree
Hide file tree
Showing 36 changed files with 587 additions and 324 deletions.
2 changes: 1 addition & 1 deletion examples/al-adass2022.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import A from '../src/js/A.js';
let aladin;
A.init.then(() => {
aladin = A.aladin('#aladin-lite-div', {survey: ["P/PanSTARRS/DR1/color-i-r-g"], showReticle: false, gridOptions: {opacity: 0.5, color: 'rgba(255, 0, 0)'}, projection: "AIT", cooFrame: 'icrs', target: "stephan's quintet", fov: 1000, showGotoControl: false, showFrame: false, fullScreen: true, showLayersControl: true, showCooGrid: true, showCooGridControl: false});
aladin = A.aladin('#aladin-lite-div', {survey: ["P/PanSTARRS/DR1/color-i-r-g"], showReticle: false, projection: "AIT", cooFrame: 'icrs', target: "stephan's quintet", fov: 1000, showGotoControl: false, showFrame: false, fullScreen: true, showLayersControl: true, showCooGrid: true, showCooGridControl: false});

const chft = aladin.createImageSurvey('CFHT', "CFHT deep view of NGC7331 and Stephan's quintet u+g+r", "https://cds.unistra.fr/~derriere/PR_HiPS/2022_Duc/", null, null, {imgFormat: 'png'});
const nircamJWST = aladin.createImageSurvey('Nircam', "Stephans Quintet NIRCam+MIRI", "http://alasky.cds.unistra.fr/JWST/CDS_P_JWST_Stephans-Quintet_NIRCam+MIRI/", null, null, {imgFormat: 'png', colormap: "viridis"});
Expand Down
2 changes: 0 additions & 2 deletions examples/al-animation-CS-CDS-2022.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
</div>
</div>
</div>

<script type="module">
import A from '../src/js/A.js';
let aladin;
A.init.then(() => {
aladin = A.aladin('#aladin-lite-div', {projection: 'MOL', cooFrame: 'galactic', fov: 360, fullScreen: true, showCooGrid: false, showReticle: false})
aladin.gotoRaDec(79.9525321, -69.2742586)
Expand Down
3 changes: 1 addition & 2 deletions examples/al-artifact.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</head>
<body>

<div id="aladin-lite-div" style="width: 1024px; height: 768px"></div>
<div id="aladin-lite-div" style="width: 1024px; height: 100%;"></div>

<script type="module">
import A from '../src/js/A.js';
Expand All @@ -19,7 +19,6 @@
target: '19 24 51.556 +45 16 44.36', // initial target
cooFrame: 'equatorial', // set galactic frame
showCooGrid: true, // set the grid
fullScreen: true,
}
);
});
Expand Down
2 changes: 1 addition & 1 deletion examples/al-cat-galaxy-shape.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// Start up Aladin Lite
aladin = A.aladin('#aladin-lite-div', {
target: "M31",
fov: 2,
fov: 89.78,
showContextMenu: true,
fullScreen: true,
showSimbadPointerControl: true,
Expand Down
11 changes: 8 additions & 3 deletions examples/al-cat-proper-motion.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
selectionColor: 'white',
// Footprint associated to sources
shape: (s) => {

// Compute the mean of pm over the catalog sources
if (!pmraMean || !pmdecMean) {
pmraMean = 0, pmdecMean = 0;
Expand All @@ -47,16 +48,20 @@
pmdecMean /= numSources
}

console.log("mean", pmraMean, pmdecMean)

let dra = +s.data.pmra - pmraMean;
let ddec = +s.data.pmdec - pmdecMean;

let mag = Math.sqrt(dra * dra + ddec * ddec);
// discard drawing a vector for big pm
if (mag > 1) {


let totalPmSquared = s.data.pmra*s.data.pmra + s.data.pmdec*s.data.pmdec;
if (totalPmSquared > 6) {
return;
}

let color = rainbowColorMap(mag * 2)
let color = rainbowColorMap((totalPmSquared - 2.5) / 2)

return A.vector(
s.ra,
Expand Down
3 changes: 2 additions & 1 deletion examples/al-catalog-hips-shape.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
let a = +s.data.size_maj;
let b = +s.data.size_min;

if (a < 0.1 || b < 0.1)
let galaxy = ['Seyfert', 'Gin', 'StarburstG', 'LINER', 'AGN', 'Galaxy'].some((n) => s.data.main_type.indexOf(n) >= 0)
if (!galaxy)
return;

let angle = +s.data.size_angle || 0.0;
Expand Down
1 change: 0 additions & 1 deletion examples/al-easy-access-vizier.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

aladin.addCatalog(A.catalogFromURL(vmc_cepheids, {onClick: 'showTable', sourceSize:14, color: '#fff080'}));



aladin.addCatalog(A.catalogFromURL(pessto, {onClick: 'showPopup', sourceSize:14, color: '#00f080'}));
aladin.on('select', (objs) => {
Expand Down
8 changes: 4 additions & 4 deletions examples/al-init-custom-options.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
<body>

<div id="aladin-lite-div" style="width: 1024px; height: 768px"></div>

<script> let aladin;
</script>
<script type="module">
import A from '../src/js/A.js';
var aladin;

A.init.then(() => {
aladin = A.aladin(
'#aladin-lite-div',
Expand All @@ -22,8 +21,9 @@
reticleColor: '#00ff00', // change reticle color
reticleSize: 40, // change reticle size
gridOptions: {color: 'pink'},
showCooGrid: true, // set the grid
showCooGrid: false, // set the grid
fullScreen: true,
inertia: false,
showStatusBar: false,
showShareControl: true,
showSettingsControl: true,
Expand Down
55 changes: 22 additions & 33 deletions src/core/al-core/src/image/fits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,34 @@ pub enum Data<'a> {
I32(Cow<'a, [i32]>),
F32(Cow<'a, [f32]>),
}
use fitsrs::{fits::Fits as FitsData, hdu::data::InMemData};
use std::io::Cursor;
use fitsrs::{
hdu::data::InMemData,
fits::Fits as FitsData,
};

impl<'a> Fits<'a> {
pub fn from_byte_slice(bytes_reader: &'a mut Cursor<&[u8]>) -> Result<Self, JsValue> {
let FitsData { hdu } = FitsData::from_reader(bytes_reader)
.map_err(|_| {
JsValue::from_str(&"Parsing fits error")
})?;
.map_err(|_| JsValue::from_str(&"Parsing fits error"))?;

let header = hdu.get_header();
let xtension = header.get_xtension();
let width = xtension.get_naxisn(1)
let width = xtension
.get_naxisn(1)
.ok_or_else(|| JsValue::from_str("NAXIS1 not found in the fits"))?;

let height = xtension.get_naxisn(2)
let height = xtension
.get_naxisn(2)
.ok_or_else(|| JsValue::from_str("NAXIS2 not found in the fits"))?;

let data = hdu.get_data();
let data = match *data {
InMemData::U8(slice) => {
Data::U8(Cow::Borrowed(slice))
},
InMemData::I16(slice) => {
Data::I16(Cow::Borrowed(slice))
},
InMemData::I32(slice) => {
Data::I32(Cow::Borrowed(slice))
},
InMemData::U8(slice) => Data::U8(Cow::Borrowed(slice)),
InMemData::I16(slice) => Data::I16(Cow::Borrowed(slice)),
InMemData::I32(slice) => Data::I32(Cow::Borrowed(slice)),
InMemData::I64(slice) => {
let data = slice.iter().map(|v| *v as i32).collect();
Data::I32(Cow::Owned(data))
},
InMemData::F32(slice) => {
Data::F32(Cow::Borrowed(slice))
},
}
InMemData::F32(slice) => Data::F32(Cow::Borrowed(slice)),
InMemData::F64(slice) => {
let data = slice.iter().map(|v| *v as f32).collect();
Data::F32(Cow::Owned(data))
Expand All @@ -66,8 +55,8 @@ impl<'a> Fits<'a> {
// Tile size
size: Vector2::new(*width as i32, *height as i32),

// Allocation info of the layout
data
// Allocation info of the layout
data,
})
}

Expand Down Expand Up @@ -121,14 +110,14 @@ impl<'a> Fits<'a> {
// Tile size
size: Vector2::new(*width as i32, *height as i32),
// Allocation info of the layout
// Allocation info of the layout
data
})
}
}*/

use crate::Texture2DArray;
use crate::image::Image;
use crate::Texture2DArray;
impl Image for Fits<'_> {
fn tex_sub_image_3d(
&self,
Expand All @@ -138,7 +127,7 @@ impl Image for Fits<'_> {
offset: &Vector3<i32>,
) -> Result<(), JsValue> {
match &self.data {
Data::U8(data) => {
Data::U8(data) => {
let view = unsafe { R8UI::view(&data) };
textures[offset.z as usize]
.bind()
Expand All @@ -150,7 +139,7 @@ impl Image for Fits<'_> {
Some(view.as_ref()),
);
}
Data::I16(data) => {
Data::I16(data) => {
let view = unsafe { R16I::view(&data) };
textures[offset.z as usize]
.bind()
Expand All @@ -162,7 +151,7 @@ impl Image for Fits<'_> {
Some(view.as_ref()),
);
}
Data::I32(data) => {
Data::I32(data) => {
let view = unsafe { R32I::view(&data) };
textures[offset.z as usize]
.bind()
Expand All @@ -174,7 +163,7 @@ impl Image for Fits<'_> {
Some(view.as_ref()),
);
}
Data::F32(data) => {
Data::F32(data) => {
let view = unsafe { R32F::view(&data) };
textures[offset.z as usize]
.bind()
Expand All @@ -192,8 +181,8 @@ impl Image for Fits<'_> {
}
}

use wasm_bindgen::JsValue;
use crate::image::format::ImageFormat;
use wasm_bindgen::JsValue;

pub trait FitsImageFormat: ImageFormat {
const BITPIX: i8;
Expand All @@ -205,7 +194,7 @@ impl FitsImageFormat for R32F {
}

#[cfg(feature = "webgl2")]
use crate::image::{R16I, R32I, R8UI, R64F};
use crate::image::{R16I, R32I, R64F, R8UI};
#[cfg(feature = "webgl2")]
impl FitsImageFormat for R64F {
const BITPIX: i8 = -64;
Expand Down
65 changes: 63 additions & 2 deletions src/core/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,11 @@ impl App {
for rsc in rscs_received {
match rsc {
Resource::Tile(tile) => {
if !has_camera_moved {
if !_has_camera_zoomed {
if let Some(survey) =
self.layers.get_mut_hips_from_cdid(&tile.get_hips_cdid())
{
let cfg = survey.get_config();
let cfg = survey.get_config_mut();

if cfg.get_format() == tile.format {
let delta_depth = cfg.delta_depth();
Expand Down Expand Up @@ -649,6 +649,63 @@ impl App {
} else {
Some(image)
};
use al_core::image::ImageType;
use fitsrs::fits::Fits;
use std::{io::Cursor, rc::Rc};
if let Some(image) = image.as_ref() {
match &*image.lock().unwrap_abort() {
Some(ImageType::FitsImage {
raw_bytes: raw_bytes_buf,
}) => {
// check if the metadata has not been set
if !cfg.fits_metadata {
let num_bytes =
raw_bytes_buf.length() as usize;
let mut raw_bytes = vec![0; num_bytes];
raw_bytes_buf.copy_to(&mut raw_bytes[..]);

let mut bytes_reader =
Cursor::new(raw_bytes.as_slice());
let Fits { hdu } =
Fits::from_reader(&mut bytes_reader)
.map_err(|_| {
JsValue::from_str(
"Parsing fits error",
)
})?;

let header = hdu.get_header();
let bscale = if let Some(
fitsrs::card::Value::Float(bscale),
) = header.get(b"BSCALE ")
{
*bscale as f32
} else {
1.0
};
let bzero = if let Some(
fitsrs::card::Value::Float(bzero),
) = header.get(b"BZERO ")
{
*bzero as f32
} else {
0.0
};
let blank = if let Some(
fitsrs::card::Value::Float(blank),
) = header.get(b"BLANK ")
{
*blank as f32
} else {
std::f32::NAN
};

cfg.set_fits_metadata(bscale, bzero, blank);
}
}
_ => (),
}
}

survey.add_tile(&cell, image, time_req)?;
self.request_redraw = true;
Expand Down Expand Up @@ -1501,6 +1558,10 @@ impl App {
self.request_redraw = true;
}

pub(crate) fn set_inertia(&mut self, inertia: bool) {
*self.disable_inertia.borrow_mut() = !inertia;
}

/*pub(crate) fn project_line(&self, lon1: f64, lat1: f64, lon2: f64, lat2: f64) -> Vec<Vector2<f64>> {
let v1: Vector3<f64> = LonLatT::new(ArcDeg(lon1).into(), ArcDeg(lat1).into()).vector();
let v2: Vector3<f64> = LonLatT::new(ArcDeg(lon2).into(), ArcDeg(lat2).into()).vector();
Expand Down
3 changes: 3 additions & 0 deletions src/core/src/camera/viewport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::healpix::cell::HEALPixCell;
use crate::healpix::coverage::HEALPixCoverage;
use crate::math::angle::ToAngle;
use crate::math::{projection::coo_space::XYZWModel, projection::domain::sdf::ProjDef};
use al_core::log::console_log;
use al_core::{info, inforec, log};

use cgmath::{Matrix4, Vector2};
Expand Down Expand Up @@ -380,6 +381,8 @@ impl CameraViewPort {
}
};

//console_log(&format!("clip factor {:?}", self.aperture));

// Project this vertex into the screen
self.moved = true;
self.zoomed = true;
Expand Down
8 changes: 8 additions & 0 deletions src/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ extern "C" {
#[macro_use]
mod utils;

use al_core::log::console_log;
use math::projection::*;
use renderable::coverage::moc::MOC;
//use votable::votable::VOTableWrapper;
Expand Down Expand Up @@ -484,6 +485,13 @@ impl WebClient {
Ok(())
}

#[wasm_bindgen(js_name = setInertia)]
pub fn set_inertia(&mut self, inertia: bool) -> Result<(), JsValue> {
self.app.set_inertia(inertia);

Ok(())
}

/// Set the absolute orientation of the view
///
/// # Arguments
Expand Down
Loading

0 comments on commit 3dcdeee

Please sign in to comment.