Skip to content

Commit

Permalink
IRSA-6654: Nicer Simbad search error
Browse files Browse the repository at this point in the history
  - also: new way of doing not units (---)
  - also: fix hips render sometime being slighly off in middle cases
  • Loading branch information
robyww committed Feb 24, 2025
1 parent 1dbe023 commit 04f8b46
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 69 deletions.
18 changes: 14 additions & 4 deletions src/firefly/js/ui/DefaultSearchActions.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import {getMenu} from '../core/AppDataCntlr.js';
import {makeSearchActionObj, SearchTypes} from '../core/ClickToAction.js';
import {flux} from '../core/ReduxFlux.js';
import {MetaConst} from '../data/MetaConst';
import {ServerParams} from '../data/ServerParams.js';
import {sprintf} from '../externalSource/sprintf.js';
import {getActiveTableId, getMetaEntry, getTableUiByTblId, getTblById, makeFileRequest} from '../api/ApiUtilTable.jsx';
import {
getActiveTableId, getMetaEntry, getTableUiByTblId, getTblById, makeFileRequest, onTableLoaded
} from '../api/ApiUtilTable.jsx';
import {extractDatalinkTable} from '../metaConvert/TableDataProductUtils';
import {makeVOCatalogRequest} from '../tables/TableRequestUtil.js';
import {dispatchTableSearch} from '../tables/TablesCntlr.js';
import {dispatchTableSearch, dispatchTableUpdate} from '../tables/TablesCntlr.js';
import { findTableCenterColumns, isFormatDataLink, isObsCoreLike } from '../voAnalyzer/TableAnalysis.js';
import {DEFAULT_FITS_VIEWER_ID} from '../visualize/MultiViewCntlr.js';
import {getServiceDescriptors, isDataLinkServiceDesc} from '../voAnalyzer/VoDataLinkServDef';
import {setMultiSearchPanelTab} from './MultiSearchPanel.jsx';
import {Format} from 'firefly/data/FileAnalysis';
import {doJsonRequest} from 'firefly/core/JsonUtils';
import {showInfoPopup} from 'firefly/ui/PopupUtil';
import {getDataServiceOption, getDataServiceOptionByTable} from './tap/DataServicesOptions';
import {getDataServiceOptionByTable} from './tap/DataServicesOptions';

//note - these two redundant function are here because of circular dependencies.
// this file is imported very early and webpack is creating errors
Expand Down Expand Up @@ -276,7 +277,16 @@ function searchSimbad(cenWpt,radius) {
};
const url = base + '?' + new URLSearchParams(params).toString();
const request= makeFileRequest('Simbad', url);
const {tbl_id}= request.META_INFO;
dispatchTableSearch(request);
onTableLoaded(tbl_id).then( (table) => {
if (!table.error) return;
const lon= sprintf('%.5f',cenWpt.getLon());
const lat= sprintf('%.5f',cenWpt.getLat());
const radStr= sprintf('%.5f',Number(radius));
const error= `No data found for SIMBAD cone search with center ${lon}, ${lat} and radius ${radStr} degrees`;
dispatchTableUpdate({...table,error});
});
}

function gotoAndSearchSimbad(cenWpt,radius) {
Expand Down
1 change: 1 addition & 0 deletions src/firefly/js/visualize/FitsHeaderUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const HdrConst= {
};


export const EMPTY_BUNIT_DEFAULT='---';


export function makeHeaderParse(header, altWcs='') {
Expand Down
79 changes: 21 additions & 58 deletions src/firefly/js/visualize/iv/HiPSSingleTileRender.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function getCorrection(tileSize, norder,desiredNorder,isMaxOrder) {
else return .01;
}
else {
return tileSize < 80 ? .05 : tileSize < 150 ? .035 : .01;
return tileSize < 80 ? .05 : tileSize < 150 ? .035 : .005;
}
}

Expand All @@ -54,10 +54,8 @@ function getCorrection(tileSize, norder,desiredNorder,isMaxOrder) {
* @param {number} desiredNorder
*/
export function drawOneHiPSTile(ctx, img, cornersAry, tileSize, offset, isMaxOrder, norder, desiredNorder) {
const triangles= norder===2 || (tileSize < 70) ? 2 : 4;
const triangles= norder > isMaxOrder && desiredNorder>norder ? 4 : 2;
const correction= getCorrection(tileSize,norder,desiredNorder,isMaxOrder);
// correction= window.cor ?? correction;
// window.firefly.debug && console.log(`tri:${triangles}, tileSize:${tileSize}, maxOrder:${isMaxOrder}, ${norder}, ${desiredNorder}, ${correction}`);

if (triangles===2) {
const triangle1= [{x:tileSize, y:tileSize}, {x:tileSize, y:0}, {x:0, y:tileSize}];
Expand All @@ -67,64 +65,29 @@ export function drawOneHiPSTile(ctx, img, cornersAry, tileSize, offset, isMaxOrd
drawTexturedTriangle(ctx, img,offset, ...triangle2, cornersAry[1], cornersAry[3], cornersAry[2], correction, true);
}
else if (triangles===4) {
const mp=tileSize/2;
const cMx= cornersAry.reduce( (total,pt) => total+pt.x, 0)/cornersAry.length;
const cMy= cornersAry.reduce( (total,pt) => total+pt.y, 0)/cornersAry.length;
const cPt= {x:cMx,y:cMy};

const [triangle1, triangle2, triangle3, triangle4]= makeSource4Triangle({x:mp, y:mp}, 0, tileSize);
drawTexturedTriangle(ctx, img, offset, ...triangle1, cornersAry[0], cPt, cornersAry[1], correction, false); // 3 >
drawTexturedTriangle(ctx, img, offset, ...triangle2, cornersAry[1], cPt, cornersAry[2], correction, false); // 12 ^
drawTexturedTriangle(ctx, img, offset, ...triangle3, cornersAry[3], cPt, cornersAry[2], correction, false); // 9 <
drawTexturedTriangle(ctx, img, offset, ...triangle4, cornersAry[0], cPt, cornersAry[3], correction, false); // 6 v
draw4Triangles(ctx, img, correction, offset, cornersAry,tileSize);
}
else if (triangles===16) { // keep this section around if we have to use it, it is not complete and not tested
// const mp=tileSize/2;
// const cMx= cornersAry.reduce( (total,pt) => total+pt.x, 0)/cornersAry.length;
// const cMy= cornersAry.reduce( (total,pt) => total+pt.y, 0)/cornersAry.length;
// const cPt= {x:cMx,y:cMy};
//
//
//
//
//
// bottom - right
// const sec1cp= mp+mp/2;
// const sec1CenPt= {x:sec1cp, y:sec1cp};
// const triangle1_1= [{x:tileSize, y:tileSize}, sec1CenPt, {x:tileSize, y:mp}]; // 3
// const triangle1_2= [{x:tileSize, y:tileSize}, sec1CenPt, {x:mp, y:tileSize}]; // 6
// const triangle1_3= [{x:mp, y:tileSize}, sec1CenPt, {x:mp, y:mp}]; // 9
// const triangle1_4= [{x:mp, y:mp}, sec1CenPt, {x:tileSize, y:tileSize}]; // 12

// const srcTriangles= [
// ...makeSource4Triangle(mp+(mp/2),mp,tileSize), // bottom right
// ...makeSource4Triangle(mp-(mp/2), mp,tileSize), // top right
// ...makeSource4Triangle(mp+(mp/2), 0,mp), // bottom left
// ...makeSource4Triangle(mp/2, 0,mp), // bottom left
// ];



// top - right
// const sec2cp= mp-mp/2;
// const sec2CenPt= {x:sec2cp,y:sec2cp};
//
//
//
//
//
// // const triangle1= [{x:tileSize-delta, y:tileSize-delta}, {x:mp-delta, y:mp-delta}, {x:tileSize-delta, y:delta}];
// const triangle2= [{x:tileSize-delta, y:delta}, {x:mp-delta, y:mp-delta}, {x:delta, y:delta}];
// const triangle3= [{x:delta, y:tileSize-delta}, {x:mp-delta, y:mp-delta}, {x:delta, y:delta}];
// const triangle4= [{x:tileSize-delta, y:tileSize-delta}, {x:mp-delta, y:mp-delta}, {x:delta, y:tileSize-delta}];
//
// drawTexturedTriangle(ctx, img, offset, ...triangle1, cornersAry[0], cPt, cornersAry[1], correction);
// drawTexturedTriangle(ctx, img, offset, ...triangle2, cornersAry[1], cPt, cornersAry[2], correction);
// drawTexturedTriangle(ctx, img, offset, ...triangle3, cornersAry[3], cPt, cornersAry[2], correction);
// drawTexturedTriangle(ctx, img, offset, ...triangle4, cornersAry[0], cPt, cornersAry[3], correction);
else if (triangles===8) { // keep this section around if we have to use it, it is not complete and not tested
//todo - will probably never do this
}
}


function draw4Triangles(ctx, img, correction, offset, cornersAry,tileSize) {
const mp=tileSize/2;
const cMx= cornersAry.reduce( (total,pt) => total+pt.x, 0)/cornersAry.length;
const cMy= cornersAry.reduce( (total,pt) => total+pt.y, 0)/cornersAry.length;
const cPt= {x:cMx,y:cMy};

const [triangle1, triangle2, triangle3, triangle4]= makeSource4Triangle({x:mp, y:mp}, 0, tileSize);
drawTexturedTriangle(ctx, img, offset, ...triangle1, cornersAry[0], cPt, cornersAry[1], correction, false); // 3 >
drawTexturedTriangle(ctx, img, offset, ...triangle2, cornersAry[1], cPt, cornersAry[2], correction, false); // 12 ^
drawTexturedTriangle(ctx, img, offset, ...triangle3, cornersAry[3], cPt, cornersAry[2], correction, false); // 9 <
drawTexturedTriangle(ctx, img, offset, ...triangle4, cornersAry[0], cPt, cornersAry[3], correction, false); // 6 v
}



const scaleCoeff = 0.01;

/**
Expand Down
7 changes: 3 additions & 4 deletions src/firefly/js/visualize/projection/ProjectionHeaderParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import {findCoordSys, EQUATORIAL_J, EQUATORIAL_B, GALACTIC_JSYS,
ECLIPTIC_B, SUPERGALACTIC_JSYS, ECLIPTIC_J, NONCELESTIAL} from '../CoordSys.js';
import {MAX_SIP_LENGTH} from './ProjectionUtil.js';
import {makeProjectionNew} from './Projection.js';
import {getHeader, makeHeaderParse, HdrConst} from '../FitsHeaderUtil.js';
import {getHeader, makeHeaderParse, HdrConst, EMPTY_BUNIT_DEFAULT} from '../FitsHeaderUtil.js';

const CD1_1_HEADERS= ['CD1_1','CD001001'];
const CD1_2_HEADERS= ['CD1_2','CD001002'];
const CD2_1_HEADERS= ['CD2_1','CD002001'];
const CD2_2_HEADERS= ['CD2_2','CD002002'];


function getHeaderListD(parse, list, def, altWcs) {
const key= list.find( (i) => parse.header[i+altWcs]);
return key ? parse.getDoubleValue(key+altWcs, def) : def;
Expand Down Expand Up @@ -369,7 +368,7 @@ export function parseSpacialHeaderInfo(header, altWcs='', zeroHeader) {


p.bunit = parse.getValue(HdrConst.BUNIT);
if (!p.bunit) p.bunit = 'DN';
if (!p.bunit) p.bunit = EMPTY_BUNIT_DEFAULT;
p.fluxUnits= getFluxUnits(parse, zeroHeader);


Expand All @@ -380,7 +379,7 @@ export function parseSpacialHeaderInfo(header, altWcs='', zeroHeader) {
function getFluxUnits(parse, zeroHeader) {
let bunit = parse.getValue(HdrConst.BUNIT, 'NONE');
if (bunit==='NONE') {
bunit= zeroHeader ? getHeader(zeroHeader, 'BUNIT', 'DN') : 'DN';
bunit= zeroHeader ? getHeader(zeroHeader, 'BUNIT', EMPTY_BUNIT_DEFAULT) : EMPTY_BUNIT_DEFAULT;
}
if (bunit.startsWith('HITS')) return 'frames';

Expand Down
7 changes: 5 additions & 2 deletions src/firefly/js/visualize/ui/MouseReadoutBottomLine.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Box, Chip, Stack, Switch, Tooltip, Typography} from '@mui/joy';
import React, {memo, useEffect, useRef, useState} from 'react';
import {object, bool, number} from 'prop-types';
import BrowserInfo from '../../util/BrowserInfo.js';
import {EMPTY_BUNIT_DEFAULT} from '../FitsHeaderUtil';
import {dispatchChangePointSelection} from '../ImagePlotCntlr.js';
import {showMouseReadoutFluxRadixDialog} from './MouseReadoutOptionPopups.jsx';
import {getNonFluxDisplayElements, getFluxInfo} from './MouseReadoutUIUtil.js';
Expand Down Expand Up @@ -144,12 +145,14 @@ const LabelItem= memo(({showCopy=false, label='', value='', copyValue='', prefCh
});

const DataItem= memo(({ value='', unit='', monoFont=false, sx}) => {
const isEmptyUnit= unit===EMPTY_BUNIT_DEFAULT;
const mStyle= monoFont ? {fontFamily:'monospace', whiteSpace:'nowrap'} : {whiteSpace:'nowrap'};
const vStr=value+'';
const vStr=isEmptyUnit ? value + ' (no units defined in file)' : value+' ' + unit;
return (
<Stack {...{direction:'row', className:'ff-readout-value', alignItems:'center', sx }}>
<Typography level='body-sm' color='warning' title={vStr} sx={mStyle}>{value}</Typography>
{unit && <Typography level='body-sm' color='warning' title={vStr} sx={{pl:.25}}>{unit}</Typography>}
{unit && <Typography level='body-sm' color={!isEmptyUnit ? 'warning' : undefined} title={vStr}
sx={{pl:.25, opacity:isEmptyUnit?.5:1}}>{unit}</Typography>}
</Stack>
);
});
Expand Down
2 changes: 1 addition & 1 deletion src/firefly/js/visualize/ui/MouseReadoutUIUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export function getReadoutElement(readoutItems, readoutKey, plotId, copyPref) {
return {value:makeImagePtReturn(readoutItems?.zeroBasedImagePt?.value)};
case MR_HEALPIX_PIXEL:
const {healpixPixel}= readoutItems;
return {value: (healpixPixel && healpixPixel.value) ? `${healpixPixel.value}` : ''};
return {value: (healpixPixel && healpixPixel.value) ? `${healpixPixel.value.toString(16)}` : ''};
case MR_HEALPIX_NORDER:
const {healpixNorder}= readoutItems;
return {value: (healpixNorder && healpixNorder.value) ? `${healpixNorder.value}` : ''};
Expand Down

0 comments on commit 04f8b46

Please sign in to comment.