Skip to content

Commit

Permalink
make the HiPS browser more robust and implement a very proto interfac…
Browse files Browse the repository at this point in the history
…e for querying the HiPS on the fly generation from cube service: https://alasky.cds.unistra.fr/onthefly-cube-hips/
  • Loading branch information
bmatthieu3 committed May 16, 2024
1 parent cd363ca commit 219761c
Show file tree
Hide file tree
Showing 28 changed files with 592 additions and 379 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Always prefer using the latest version. If you want the new features without min
## API documentation

There is a new in progress API documentation at [this link](https://cds-astro.github.io/aladin-lite).
Editable examples showing the API can also be found [here](https://aladin.cds.unistra.fr/AladinLite/doc/API/examples/).

## Embed it into your projects

Expand Down
88 changes: 88 additions & 0 deletions examples/al-onthefly.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<!doctype html>
<html>
<head>
</head>
<body>

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

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

let aladin;
A.init.then(() => {
aladin = A.aladin('#aladin-lite-div', {
fullScreen: true,
target: "ngc 1436",
fov: 2,
projection: 'TAN',
showContextMenu: true,
showSimbadPointerControl: true,
expandLayersControl: true,
hipsList: [
// High energy (Gamma and X-rays)
'CDS/P/HGPS/Flux',
'CDS/P/Fermi/5',
'CDS/P/Fermi/4',
'CDS/P/Fermi/3',
'ov-gso/P/Fermi/Band2',
'ov-gso/P/BAT/150-195keV',
'ov-gso/P/BAT/35-50keV',
'ov-gso/P/BAT/14-20keV',
'erosita/dr1/rate/023',
'erosita/dr1/rate/024',
// Uv/Optical/Infrared
'CDS/P/GALEXGR6_7/FUV',
'CDS/P/GALEXGR6_7/NUV',
'CDS/P/DSS2/color',
'CDS/P/PanSTARRS/DR1/g',
'CDS/P/PanSTARRS/DR1/r',
'CDS/P/Finkbeiner',
'CDS/P/PanSTARRS/DR1/i',
'CDS/P/PanSTARRS/DR1/color-i-r-g',
'CDS/P/PanSTARRS/DR1/z',
'CDS/P/PanSTARRS/DR1/y',
'CDS/P/DES-DR2/ColorIRG',
'CDS/P/2MASS/color',
'ov-gso/P/GLIMPSE/irac1',
'ov-gso/P/GLIMPSE/irac2',
'CDS/P/unWISE/color-W2-W1W2-W1',
'ov-gso/P/GLIMPSE/irac3',
'ov-gso/P/GLIMPSE/irac4',
'CDS/P/IRIS/color',
'ESAVO/P/AKARI/N60',
'ESAVO/P/AKARI/WideL',
'ESAVO/P/HERSCHEL/SPIRE-250',
'ESAVO/P/HERSCHEL/SPIRE-350',
'ESAVO/P/HERSCHEL/SPIRE-500',
// sub-mm/mm/radio
'CDS/P/PLANCK/R3/HFI/color',
'CDS/P/ACT_Planck/DR5/f220',
'CDS/P/CO',
'CDS/P/PLANCK/R3/HFI100',
'CDS/P/PLANCK/R3/LFI30',
'CDS/P/NVSS',
'CSIRO/P/RACS/mid/I',
'ov-gso/P/CGPS/VGPS',
'CDS/C/HI4PI/HI',
'CDS/P/MeerKAT/Galactic-Centre-1284MHz-StokesI',
'CSIRO/P/RACS/low/I',
'astron.nl/P/tgssadr',
'ov-gso/P/GLEAM/170-231',
'ov-gso/P/GLEAM/139-170',
'astron.nl/P/lotss_dr2_high',
'ov-gso/P/GLEAM/103-134',
'ov-gso/P/GLEAM/072-103'
]
});

aladin.addCatalog(
A.catalogFromSKAORucio("ngc 1436", 15, {
onClick: 'showTable',
hoverColor: "yellow",
})
);
});
</script>
</body>
</html>
6 changes: 3 additions & 3 deletions examples/al-soda-ska.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
aladin = A.aladin("#aladin-lite-div", {
fullScreen: true,
target: "m51",
fov: 90,
fov: 15,
projection: "AIT",
showContextMenu: true,
showShareControl: true,
Expand Down Expand Up @@ -76,8 +76,8 @@
aladin.setImageLayer(A.imageHiPS("P/DSS2/color"));

aladin.addCatalog(
A.catalogFromSKAORucio("m51", 10, {
onClick: "showTable",
A.catalogFromSKAORucio("m51", 15, {
onClick: 'showTable',
hoverColor: "yellow",
})
);
Expand Down
3 changes: 1 addition & 2 deletions examples/al-zoomchanged.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
console.log("zoomChanged")
})
aladin.on("positionChanged", ({ra, dec}) => {
console.log('call to aladin', aladin.pix2world(0, 0))
console.log('call to aladin', aladin.pix2world(300, 300))
console.log('positionChanged in icrs', ra, dec)
})

aladin.gotoRaDec(0, 20);


aladin.on('rightClickMove', (x, y) => {
console.log("right click move", x, y)
})
Expand Down
22 changes: 16 additions & 6 deletions src/core/al-core/src/image/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ impl ImageFormat for RGB8U {

fn decode(raw_bytes: &[u8]) -> Result<Bytes<'_>, &'static str> {
let mut decoder = jpeg::Decoder::new(raw_bytes);
let bytes = decoder.decode().map_err(|_| "Cannot decoder jpeg. This image may not be compressed.")?;
let bytes = decoder
.decode()
.map_err(|_| "Cannot decoder jpeg. This image may not be compressed.")?;

Ok(Bytes::Owned(bytes))
}
Expand All @@ -70,7 +72,9 @@ impl ImageFormat for RGBA8U {

fn decode(raw_bytes: &[u8]) -> Result<Bytes<'_>, &'static str> {
let mut decoder = jpeg::Decoder::new(raw_bytes);
let bytes = decoder.decode().map_err(|_| "Cannot decoder png. This image may not be compressed.")?;
let bytes = decoder
.decode()
.map_err(|_| "Cannot decoder png. This image may not be compressed.")?;

Ok(Bytes::Owned(bytes))
}
Expand All @@ -93,7 +97,9 @@ impl ImageFormat for RGBA8U {

fn decode(raw_bytes: &[u8]) -> Result<Bytes<'_>, &'static str> {
let mut decoder = jpeg::Decoder::new(raw_bytes);
let bytes = decoder.decode().map_err(|_| "Cannot decoder png. This image may not be compressed.")?;
let bytes = decoder
.decode()
.map_err(|_| "Cannot decoder png. This image may not be compressed.")?;

Ok(Bytes::Owned(bytes))
}
Expand Down Expand Up @@ -188,7 +194,6 @@ impl ImageFormat for R32F {
}
}


#[cfg(feature = "webgl2")]
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
pub struct R64F;
Expand Down Expand Up @@ -310,6 +315,8 @@ pub enum ChannelType {
R32I,
}

pub const NUM_CHANNELS: usize = 9;

#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]
pub struct ImageFormatType {
pub ext: ImageExt,
Expand All @@ -327,8 +334,11 @@ impl ImageFormatType {

pub fn is_colored(&self) -> bool {
match self.channel {
ChannelType::RGBA32F | ChannelType::RGB32F | ChannelType::RGBA8U | ChannelType::RGB8U => true,
_ => false
ChannelType::RGBA32F
| ChannelType::RGB32F
| ChannelType::RGBA8U
| ChannelType::RGB8U => true,
_ => false,
}
}
}
10 changes: 3 additions & 7 deletions src/core/src/renderable/hips/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use al_core::image::Image;
use al_core::log::console_log;
use al_core::shader::Shader;
use al_core::webgl_ctx::GlWrapper;
use al_core::Texture2DArray;
use al_core::VecData;
use al_core::VertexArrayObject;
use al_core::WebGlContext;
Expand Down Expand Up @@ -43,6 +44,7 @@ use uv::{TileCorner, TileUVW};

use cgmath::{Matrix, Matrix4};
use std::fmt::Debug;
use std::rc::Rc;
use wasm_bindgen::JsValue;
use web_sys::WebGl2RenderingContext;

Expand Down Expand Up @@ -381,11 +383,7 @@ pub struct HiPS {
}

impl HiPS {
pub fn new(
config: HiPSConfig,
gl: &WebGlContext,
_camera: &CameraViewPort,
) -> Result<Self, JsValue> {
pub fn new(config: HiPSConfig, gl: &WebGlContext) -> Result<Self, JsValue> {
let mut vao = VertexArrayObject::new(gl);

// layout (location = 0) in vec2 lonlat;
Expand Down Expand Up @@ -497,8 +495,6 @@ impl HiPS {
.unbind();

let num_idx = 0;
//let min_depth_tile = config.get_min_depth_tile();

let textures = ImageSurveyTextures::new(gl, config)?;

let gl = gl.clone();
Expand Down
15 changes: 4 additions & 11 deletions src/core/src/renderable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod utils;
use crate::renderable::image::Image;

use al_core::image::format::ChannelType;
use al_core::Texture2DArray;
pub use hips::HiPS;

pub use catalog::Manager;
Expand All @@ -20,6 +21,7 @@ use al_api::hips::ImageMetadata;
use al_api::image::ImageParams;

use al_core::colormap::Colormaps;
use al_core::image::format::NUM_CHANNELS;
use al_core::shader::Shader;
use al_core::SliceData;
use al_core::VertexArrayObject;
Expand All @@ -38,6 +40,7 @@ use hips::raytracing::RayTracer;

use std::borrow::Cow;
use std::collections::HashMap;
use std::rc::Rc;
use wasm_bindgen::JsValue;
use web_sys::WebGl2RenderingContext;

Expand Down Expand Up @@ -481,7 +484,7 @@ impl Layers {
}*/
camera.register_view_frame(cfg.get_frame(), proj);

let hips = HiPS::new(cfg, gl, camera)?;
let hips = HiPS::new(cfg, gl)?;
// add the frame to the camera

self.surveys.insert(creator_did.clone(), hips);
Expand Down Expand Up @@ -613,16 +616,6 @@ impl Layers {
Ok(())
}

/*pub fn is_ready(&self) -> bool {
let ready = self
.surveys
.iter()
.map(|(_, survey)| survey.is_ready())
.fold(true, |acc, x| acc & x);
ready
}*/

// Accessors
// HiPSes getters
pub fn get_hips_from_layer(&self, layer: &str) -> Option<&HiPS> {
Expand Down
9 changes: 2 additions & 7 deletions src/core/src/survey/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub struct ImageSurveyTextures {
//pub cutoff_values_tile: Rc<RefCell<HashMap<HEALPixCell, (f32, f32)>>>,

// Array of 2D textures
texture_2d_array: Texture2DArray,
pub texture_2d_array: Texture2DArray,

// A boolean ensuring the root textures
// have already been loaded
Expand Down Expand Up @@ -168,11 +168,7 @@ fn create_texture_array<F: ImageFormat>(
}

impl ImageSurveyTextures {
pub fn new(
gl: &WebGlContext,
config: HiPSConfig,
//exec: Rc<RefCell<TaskExecutor>>,
) -> Result<ImageSurveyTextures, JsValue> {
pub fn new(gl: &WebGlContext, config: HiPSConfig) -> Result<ImageSurveyTextures, JsValue> {
let size = config.num_textures();
// Ensures there is at least space for the 12
// root textures
Expand Down Expand Up @@ -212,7 +208,6 @@ impl ImageSurveyTextures {
#[cfg(feature = "webgl2")]
ChannelType::R64F => create_texture_array::<R64F>(gl, &config)?,
};

// The root textures have not been loaded
//let ready = false;
//let num_root_textures_available = 0;
Expand Down
1 change: 1 addition & 0 deletions src/core/src/survey/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use al_api::hips::ImageExt;
use al_core::log::console_log;
use al_core::{image::format::ImageFormat, image::raw::ImageBuffer};

#[derive(Debug)]
Expand Down
Loading

0 comments on commit 219761c

Please sign in to comment.