From 4ecb78b6a76c84308cdc477e4f161ae33ea119f4 Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Thu, 25 Apr 2024 17:46:41 -0700 Subject: [PATCH 1/2] use of array dimensions in `inferCfAxes()` --- components/utils/data.js | 43 ++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/components/utils/data.js b/components/utils/data.js index 9c6c595..ca23203 100644 --- a/components/utils/data.js +++ b/components/utils/data.js @@ -684,24 +684,47 @@ const inferCfAxes = (metadata, pyramid) => { } if (prefix && !k.startsWith(prefix)) { - return false + return false // skip keys that do not start with the prefix } - const variable = k.replace(prefix, '').replace(suffix, '') + const variablePath = k.replace(prefix, '') + const variable = variablePath.replace(suffix, '') if (!variable) { - return false + return false // skip if no variable name is found } - const dims = metadata[k]['_ARRAY_DIMENSIONS'] - if (!dims) { - return false + const attrs = metadata[k] + + if (!attrs?._ARRAY_DIMENSIONS) { + return false // skip if there no array dimensions } - const time = dims.find( - (dim) => metadata[`${prefix}${dim}${suffix}`]?.calendar - ) - const base = { variable, ...(time ? { T: time } : {}) } + const dims = attrs['_ARRAY_DIMENSIONS'] + const axisInfo = dims.reduce((accum, dim) => { + const dimAttrsPath = `${prefix}${dim}${suffix}` + const dimAttrs = metadata[dimAttrsPath] + if (dimAttrs) { + if (dimAttrs.axis) { + accum[dimAttrs.axis] = dim // collect axis information + } + // ensure time is captured if it has a 'calendar' attribute + if (dimAttrs.calendar && !accum.T) { + accum.T = dim // set time dimension based on 'calendar' attribute + } + } + return accum + }, {}) + + // construct the base object including time dimension if found + const base = { variable, ...(axisInfo.T ? { T: axisInfo.T } : {}) } + + // use axis information directly if available and complete + if (axisInfo.X && axisInfo.Y) { + return { ...base, X: axisInfo.X, Y: axisInfo.Y } + } + + // fallback to hardcoded checks if axis info is incomplete if (['x', 'y'].every((d) => dims.includes(d))) { return { ...base, X: 'x', Y: 'y' } } else if (['lat', 'lon'].every((d) => dims.includes(d))) { From 4a7cb9e124c2698bebc3e6d61b35108dddb1e2af Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Thu, 25 Apr 2024 17:49:28 -0700 Subject: [PATCH 2/2] remove debugging comments --- components/utils/data.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/utils/data.js b/components/utils/data.js index ca23203..4f4456c 100644 --- a/components/utils/data.js +++ b/components/utils/data.js @@ -684,14 +684,14 @@ const inferCfAxes = (metadata, pyramid) => { } if (prefix && !k.startsWith(prefix)) { - return false // skip keys that do not start with the prefix + return false } const variablePath = k.replace(prefix, '') const variable = variablePath.replace(suffix, '') if (!variable) { - return false // skip if no variable name is found + return false } const attrs = metadata[k]