Skip to content

Commit

Permalink
wip parse the header inside xmp
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatthieu3 committed Jul 26, 2024
1 parent 245030f commit 2c0afd8
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 40 deletions.
7 changes: 6 additions & 1 deletion examples/al-image-with-AVM-tags.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@

aladin.setOverlayImageLayer(A.image(
//"https://www.virtualastronomy.org/images/sig05-013.jpg",
"https://www.astropix.org/archive/eso/eso0755a/eso_eso0755a_1280.jpg",
//"https://www.eso.org/public/archives/images/original/eso1137_hubble_dark.tif",
//"images/eso1137_hubble_dark.jpg",
//"https://nova.astrometry.net/new_fits_file/11015534",
//"https://chandra.harvard.edu/photo/2024/25th/25th_gcenter.jpg",
"https://www.astropix.org/archive/spitzer/ssc2008-14b/spitzer_ssc2008-14b_original.jpg",
//"https://chandra.harvard.edu/photo/2024/25th/25th_crab.jpg",
{
name: "sig05-017",
successCallback: (ra, dec, fov, image) => {
Expand Down
1 change: 0 additions & 1 deletion src/core/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ pub struct App {
_fbo_view: FrameBufferObject,
_fbo_ui: FrameBufferObject,
//line_renderer: RasterizedLineRenderer,

colormaps: Colormaps,

pub projection: ProjectionType,
Expand Down
4 changes: 3 additions & 1 deletion src/core/src/camera/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ pub fn build_fov_coverage(
moc
}
} else {
let center_xyzw = crate::coosys::apply_coo_system(camera_frame, frame, camera_center);

let biggest_fov_rad = proj.aperture_start().to_radians();
let lonlat = camera_center.lonlat();
let lonlat = center_xyzw.lonlat();
HEALPixCoverage::from_cone(&lonlat, biggest_fov_rad * 0.5, depth)
}
}
2 changes: 1 addition & 1 deletion src/glsl/webgl2/image/sampler.frag
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ uniform float opacity;
#include ../hips/color.glsl;

void main() {
out_frag_color = texture(tex, frag_uv);
out_frag_color = texture(tex, vec2(frag_uv.x, 1.0 - frag_uv.y));
out_frag_color.a = out_frag_color.a * opacity;
}
2 changes: 1 addition & 1 deletion src/glsl/webgl2/projection/ait.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ vec2 w2c_ait(vec3 p) {
float y2d = p.y / w;

float x2d = 0.0;
if (abs(p.x) < 1e-3) {
if (abs(p.x) < 5e-3) {
float x_over_r = p.x/r;
x2d = -p.x * (1.0 - x_over_r*x_over_r/21.0) / w;
} else {
Expand Down
53 changes: 25 additions & 28 deletions src/js/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,26 @@ export let Image = (function () {
},
layer
);
},
error: (e) => {
// try as cors
const url = Aladin.JSONP_PROXY + '?url=' + self.url;

return Utils.fetch({
url: url,
dataType: 'readableStream',
success: (stream) => {
return self.view.wasm.addImageFITS(
stream,
{
...self.colorCfg.get(),
longitudeReversed: false,
imgFormat: 'fits',
},
layer
);
},
});
}
})
.then((imageParams) => {
Expand Down Expand Up @@ -278,7 +298,7 @@ export let Image = (function () {
if (!self.options.wcs) {
/* look for avm tags if no wcs is given */
let avm = new AVM(img);
console.log(img.complete)

avm.load((obj) => {
// obj contains the following information:
// obj.id (string) = The ID provided for the image
Expand All @@ -289,39 +309,16 @@ export let Image = (function () {
console.log(obj)

if (obj.avmdata) {
let wcs = {};
wcs.CTYPE1 = obj.tags['Spatial.CoordinateFrame'] === 'ICRS' ? 'RA---' : 'GLON-';
wcs.CTYPE1 += obj.tags['Spatial.CoordsystemProjection'];
wcs.CTYPE2 = obj.tags['Spatial.CoordinateFrame'] === 'ICRS' ? 'DEC--' : 'GLAT-';
wcs.CTYPE2 += obj.tags['Spatial.CoordsystemProjection'];

if (obj.tags['Spatial.Equinox'])
wcs.EQUINOX = +obj.tags['Spatial.Equinox'];

wcs.NAXIS1 = +obj.tags['Spatial.ReferenceDimension'][0];
wcs.NAXIS2 = +obj.tags['Spatial.ReferenceDimension'][1];

wcs.CDELT1 = +obj.tags['Spatial.Scale'][0];
wcs.CDELT2 = +obj.tags['Spatial.Scale'][1];
self.options.wcs = obj.oTags;

wcs.CRPIX1 = +obj.tags['Spatial.ReferencePixel'][0];
wcs.CRPIX2 = +obj.tags['Spatial.ReferencePixel'][1];

wcs.CRVAL1 = +obj.tags['Spatial.ReferenceValue'][0];
wcs.CRVAL2 = +obj.tags['Spatial.ReferenceValue'][1];

if (obj.tags['Spatial.Rotation'] !== undefined)
wcs.CROTA2 = +obj.tags['Spatial.Rotation'];

self.options.wcs = wcs;
console.log(wcs)

img2Blob()
} else {
// no tags found
reject('No AVM tags have been found in the image')
return;
}

})
} else {
img2Blob()
Expand Down Expand Up @@ -387,8 +384,8 @@ export let Image = (function () {
} else {
// imgformat not defined we will try first supposing it is a fits file and then use the jpg heuristic
promise = this._addFITS(layer)
.catch(_ => {
console.warn(`Image located at ${self.url} could not be parsed as fits file. Try as a jpg/png image...`)
.catch(e => {
console.warn(`Image located at ${self.url} could not be parsed as fits file. Try as a jpg/png image...:`, e)
return self._addJPGOrPNG(layer)
.catch(e => {
console.error(`Image located at ${self.url} could not be parsed as jpg/png image file. Aborting...`)
Expand Down
43 changes: 36 additions & 7 deletions src/js/libs/avm.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export let AVM = (function() {
var oAVM = _obj.findAVMinJPEG(view);
_obj.avmdata = true;
_obj.tags = oAVM || {};

if (typeof fnCallback=="function") fnCallback(_obj);
})
}
Expand All @@ -137,18 +138,16 @@ export let AVM = (function() {
var iLength = oFile.byteLength;
while (iOffset < iLength) {
if (oFile.getUint8(iOffset) != 0xFF) return false; // not a valid marker, something is wrong
var iMarker = oFile.getUint8(iOffset+1)+1;

var iMarker = oFile.getUint8(iOffset+1);

// we could implement handling for other markers here,
// but we're only looking for 0xFFE1 for AVM data
if (iMarker == 22400) {
return this.readAVMData(oFile, iOffset + 4, oFile.getUint16(iOffset+2, false)-2);
iOffset += 2 + oFile.getUint16(iOffset+2, false);
//iOffset += 2 + oFile.getUint16(iOffset+2, false);

} else if (iMarker == 225) {
// 0xE1 = Application-specific 1 (for AVM)
console.log("jkjk")
var oTags = this.readAVMData(oFile, iOffset + 4, oFile.getUint16(iOffset+2, false)-2);
return oTags;
} else {
Expand All @@ -157,11 +156,42 @@ export let AVM = (function() {
}
}

AVM.prototype.readAVMData = function(oFile, iStart, iLength){
AVM.prototype.readAVMData = function(oFile) {
var oTags = {};
this.xmp = this.readXMP(oFile);
console.log("xmp read", this.xmp)
if (this.xmp) oTags = this.readAVM(this.xmp);
if (this.xmp) {
oTags = this.readAVM(this.xmp);
let wcs = {};

if (oTags) {
wcs.CTYPE1 = obj.tags['Spatial.CoordinateFrame'] === 'ICRS' ? 'RA---' : 'GLON-';
wcs.CTYPE1 += obj.tags['Spatial.CoordsystemProjection'];
wcs.CTYPE2 = obj.tags['Spatial.CoordinateFrame'] === 'ICRS' ? 'DEC--' : 'GLAT-';
wcs.CTYPE2 += obj.tags['Spatial.CoordsystemProjection'];

if (obj.tags['Spatial.Equinox'])
wcs.EQUINOX = +obj.tags['Spatial.Equinox'];

wcs.NAXIS1 = obj.tags['Spatial.ReferenceDimension'] && +obj.tags['Spatial.ReferenceDimension'][0] || img.width;
wcs.NAXIS2 = obj.tags['Spatial.ReferenceDimension'] && +obj.tags['Spatial.ReferenceDimension'][1] || img.height;

wcs.CDELT1 = obj.tags['Spatial.Scale'] && +obj.tags['Spatial.Scale'][0];
wcs.CDELT2 = obj.tags['Spatial.Scale'] && +obj.tags['Spatial.Scale'][1];
wcs.CRPIX1 = obj.tags['Spatial.ReferencePixel'] && +obj.tags['Spatial.ReferencePixel'][0];
wcs.CRPIX2 = obj.tags['Spatial.ReferencePixel'] && +obj.tags['Spatial.ReferencePixel'][1];

wcs.CRVAL1 = obj.tags['Spatial.ReferenceValue'] && +obj.tags['Spatial.ReferenceValue'][0];
wcs.CRVAL2 = obj.tags['Spatial.ReferenceValue'] && +obj.tags['Spatial.ReferenceValue'][1];

if (obj.tags['Spatial.Rotation'] !== undefined)
wcs.CROTA2 = +obj.tags['Spatial.Rotation'];


} else {
// try to read directly the WCS
}
}
return oTags;
}

Expand All @@ -178,7 +208,6 @@ export let AVM = (function() {
var byteStr = '';
var iEntryOffset = -1;
console.log(iEntryOffset)

// Here we want to search for the XMP packet starting string
// There is probably a more efficient way to search for a byte string
for (var i=0;i<iEntries;i++) {
Expand Down

0 comments on commit 2c0afd8

Please sign in to comment.