diff --git a/src/firefly/js/voAnalyzer/VoCoreUtils.js b/src/firefly/js/voAnalyzer/VoCoreUtils.js index fba942cf33..aa00b2d485 100644 --- a/src/firefly/js/voAnalyzer/VoCoreUtils.js +++ b/src/firefly/js/voAnalyzer/VoCoreUtils.js @@ -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); @@ -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 diff --git a/src/firefly/js/voAnalyzer/VoTableRecognizer.js b/src/firefly/js/voAnalyzer/VoTableRecognizer.js index 882ddd414d..ed6d950a8e 100644 --- a/src/firefly/js/voAnalyzer/VoTableRecognizer.js +++ b/src/firefly/js/voAnalyzer/VoTableRecognizer.js @@ -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'; /** @@ -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)); @@ -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; +} \ No newline at end of file