Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/firefly/js/voAnalyzer/VoCoreUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

import {isObject, isString} from 'lodash';
import {getCellValue, getColumnByRef, getTblById} from '../tables/TableUtil.js';
import {cisxAdhocServiceUtype, ColNameIdx, OBSTAPCOLUMNS, standardIDs, UCDSyntax, UtypeColIdx} from './VoConst.js';
import {
cisxAdhocServiceUtype, ColNameIdx, OBSTAPCOLUMNS, posCol, standardIDs, UCDSyntax, UtypeColIdx
} from './VoConst.js';


export const isSIAStandardID = (standardID) => standardID?.toLowerCase().startsWith(standardIDs.sia);
Expand Down Expand Up @@ -91,6 +93,19 @@ export function isUCDWith(ucdValue, ucdWord, syntaxCode = UCDSyntax.any) {
(syntaxCode === UCDSyntax.any && idx >= 0);
}

/**
* If there is a match return a coordinate system that matches the ucd, otherwise return undefined
* @param {String} ucd
* @return {CoordinateSys|undefined}
*/
export function findCsysFromUCD(ucd) {
if (!ucd) return;
const foundPosCol= Object.values(posCol)
.find( (entry) => entry.ucd
.some( (pair) => pair.some((v) => isUCDWith(ucd, v))));
return foundPosCol?.coord;
}

/**
* Given a TableModel or a table id return a table model
* @param {TableModel|String} tableOrId - a table model or a table id
Expand Down
25 changes: 18 additions & 7 deletions src/firefly/js/voAnalyzer/VoTableRecognizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
alternateMainPos, ColNameIdx, mainMeta, obsCorePosColumns, OBSTAPCOLUMNS, POS_EQ_UCD, posCol, S_REGION,
SSA_COV_UTYPE, UCDCoord, ucdSyntaxMap, UtypeColIdx
} from './VoConst.js';
import {getObsTabColEntry, isUCDWith} from './VoCoreUtils.js';
import {findCsysFromUCD, getObsTabColEntry, isUCDWith} from './VoCoreUtils.js';


/**
Expand Down Expand Up @@ -391,25 +391,29 @@ export class VoTableRecognizer {
let lonCol;
let latCol;
if (useReg) {
let reLon = new RegExp(`^[A-z]*[-_]?(${lon})[1-9]*$`);
let reLat = new RegExp(`^[A-z]*[-_]?(${lat})[1-9]*$`);
let reLon = new RegExp(`^[A-z]*[-_]?(${lon})[1-9]*$`, 'i');
let reLat = new RegExp(`^[A-z]*[-_]?(${lat})[1-9]*$`, 'i');
lonCol = findColumn(lon, reLon);
latCol = findColumn(lat, reLat);
if (!lonCol || !latCol) {
reLon = new RegExp(`^${lon}[-_].*$`);
reLat = new RegExp(`^${lat}[-_].*$`);
reLon = new RegExp(`^${lon}[-_].*$`, 'i');
reLat = new RegExp(`^${lat}[-_].*$`, 'i');
lonCol = findColumn(lon, reLon);
latCol = findColumn(lat, reLat);
}
if (lonCol && latCol) {
if (lonCol.name.replace(lon, '') !== latCol.name.replace(lat, '')) return undefined;
const testLon= lonCol.name.toLowerCase();
const testLat= latCol.name.toLowerCase();
if (testLon.replace(lon.toLowerCase(), '') !== testLat.replace(lat.toLowerCase(), '')) return undefined;
}
} else {
lonCol = findColumn(lon);
latCol = findColumn(lat);
}

return (lonCol && latCol) ? this.setCenterColumnsInfo([lonCol, latCol]) : undefined;
return (lonCol && latCol)
? this.setCenterColumnsInfo([lonCol, latCol], findCsysForCoordColumns(lonCol,latCol))
: undefined;
};

const centerColumnInfo = (guess('ra', 'dec') || guess('lon', 'lat') || guess('ra', 'dec', true) || guess('lon', 'lat', true));
Expand Down Expand Up @@ -542,3 +546,10 @@ function centerColumnUTypesFromObsTap() {

return centerUTypes.findIndex((oneUtype) => !oneUtype) >= 0 ? null : centerUTypes;
}

function findCsysForCoordColumns(lonCol, latCol) {
if (!lonCol || !latCol) return undefined;
const lonCsys= findCsysFromUCD(lonCol.UCD);
const latCsys= findCsysFromUCD(latCol.UCD);
return (lonCsys && lonCsys===latCsys) ? lonCsys : undefined;
}
Loading