Skip to content

Commit 991f0bc

Browse files
authored
Merge pull request #824 from Caltech-IPAC/IRSA-2894-compass-fix
IRSA-2894: ZTF images flipped east-west in time series tool
2 parents b2d3570 + 90fb2c3 commit 991f0bc

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/firefly/js/drawingLayers/NorthUpCompass.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,14 @@ function makeCompass(plotId, action){
164164
var zf= cc.zoomFactor || 1;
165165
var wpt2= makeWorldPt(wpStart.getLon(), wpStart.getLat() + (Math.abs(cdelt1)/zf)*(px), CoordinateSys.EQ_J2000);
166166
var spt2= cc.getScreenCoords(wpt2);
167-
var sptE2 = getEastFromNorthOnScreen(cc, sptStart, spt2, Math.PI/2);
167+
var wpt3= makeWorldPt(wpStart.getLon() + (Math.abs(cdelt1)/(Math.cos(wpStart.getLat()*Math.PI/180.)*zf))*(px),
168+
wpStart.getLat(), CoordinateSys.EQ_J2000);
169+
var spt3= cc.getScreenCoords(wpt3);
170+
// don't use spt3 because of funny effects near the celestial poles
171+
// the sign of the cross product of compass vectors tells us if the image is mirror-reversed from the sky
172+
var cross_product= (spt3.x - sptStart.x)*(spt2.y - sptStart.y) -
173+
(spt3.y - sptStart.y)*(spt2.x - sptStart.x);
174+
var sptE2= getEastFromNorthOnScreen(cc, sptStart, spt2, Math.sign(cross_product));
168175

169176
if (sptStart===null || spt2===null || sptE2===null) {
170177
return null;
@@ -176,12 +183,12 @@ function makeCompass(plotId, action){
176183
return [dataE, dataN];
177184
}
178185

179-
function getEastFromNorthOnScreen(cc, origin, nVec) {
186+
function getEastFromNorthOnScreen(cc, origin, nVec, sign) {
180187
var originSpt = cc.getScreenCoords(origin);
181188
var vec1Spt = cc.getScreenCoords(nVec);
182189

183-
var x2 = (vec1Spt.y - originSpt.y) + originSpt.x;
184-
var y2 = -(vec1Spt.x - originSpt.x) + originSpt.y;
190+
var x2 = sign*(vec1Spt.y - originSpt.y) + originSpt.x;
191+
var y2 = -sign*(vec1Spt.x - originSpt.x) + originSpt.y;
185192

186193
return makeScreenPt(x2, y2);
187194
}

src/firefly/js/visualize/ui/ThumbnailView.jsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,21 @@ function makeDrawing(pv,width,height) {
223223
//const wptE2= makeWorldPt(wptC.getLon()+(Math.abs(cdelt1)/thumbZoomFact)*(arrowLength/2), wptC.getLat());
224224
const wptE1= wptC;
225225
const wpt1= wptC;
226+
const wpt3= makeWorldPt(wptC.getLon() +
227+
(Math.abs(cdelt1)/(Math.cos(wptC.getLat()*Math.PI/180.)/thumbZoomFact)*(arrowLength/1.6)),
228+
wptC.getLat());
229+
226230

227231
const sptC = cc.getScreenCoords(wptC);
228232
const sptN = cc.getScreenCoords(wpt2);
229233
if (!sptC || !sptN) return null;
230-
const [x, y] = [(sptN.y - sptC.y) + sptC.x, (-sptN.x + sptC.x)+sptC.y];
234+
const spt3= cc.getScreenCoords(wpt3);
235+
// don't use spt3 because of funny effects near the celestial poles
236+
// the sign of the cross product of compass vectors tells us if the image is mirror-reversed from the sky
237+
const cross_product= (spt3.x - sptC.x)*(sptN.y - sptC.y) -
238+
(spt3.y - sptC.y)*(sptN.x - sptC.x);
239+
const [x, y] = [Math.sign(cross_product)*(sptN.y - sptC.y) + sptC.x,
240+
Math.sign(cross_product)*(-sptN.x + sptC.x)+sptC.y];
231241
const wptE2 = cc.getWorldCoords(makeScreenPt(x, y));
232242

233243
const spt1= cc.getDeviceCoords(wpt1, thumbZoomFact, thumbnailTrans);

0 commit comments

Comments
 (0)