From c2068598fe02e7f434fa429b628b76b6a0e1fb10 Mon Sep 17 00:00:00 2001 From: katamartin Date: Fri, 26 Apr 2024 15:40:44 -0400 Subject: [PATCH] Remove checks against ncviewjs:-prefixed attributes --- components/data/dataset.js | 13 ++++++----- components/data/store.js | 18 +++++++-------- components/dataset.js | 6 ++--- components/utils/data.js | 45 ++++---------------------------------- 4 files changed, 23 insertions(+), 59 deletions(-) diff --git a/components/data/dataset.js b/components/data/dataset.js index 86a8b39..dd03993 100644 --- a/components/data/dataset.js +++ b/components/data/dataset.js @@ -1,27 +1,28 @@ import { getActiveChunkKeys, - getMetadata, + getVariables, getVariableInfo, pointToChunkKey, + inferCfAxes, } from '../utils/data' import Level from './level' class Dataset { - constructor(url, cfAxes, pyramid) { + constructor(url, metadata, pyramid) { this.url = url - this.cfAxes = cfAxes + this.metadata = metadata this.pyramid = pyramid + this.cfAxes = inferCfAxes(metadata.metadata, pyramid) } async initialize() { this.variable = null this.chunks = {} - const { metadata, variables, levels } = await getMetadata( - this.url, + const { variables, levels } = await getVariables( + this.metadata, this.pyramid ) - this.metadata = metadata this.variables = variables this.variableMetadata = {} diff --git a/components/data/store.js b/components/data/store.js index 57bf8e2..c5b3762 100644 --- a/components/data/store.js +++ b/components/data/store.js @@ -44,7 +44,7 @@ const useStore = create((set, get) => ({ ...createDatasetSlice(set, get), ...createDisplaySlice(set, get), ...createPlotsSlice(set, get), - setUrl: async (url, { cfAxes, clim, pyramid } = {}) => { + setUrl: async (url, { metadata, clim, pyramid } = {}) => { const { _registerLoading, _unregisterLoading } = get() set({ error: null, @@ -65,7 +65,7 @@ const useStore = create((set, get) => ({ _registerLoading('metadata') let dataset try { - dataset = new Dataset(url, cfAxes, pyramid) + dataset = new Dataset(url, metadata, pyramid) await dataset.initialize() set({ dataset }) } catch (e) { @@ -77,13 +77,13 @@ const useStore = create((set, get) => ({ // default to first variable const initialVariable = dataset.variables[0] - if (Object.keys(cfAxes[initialVariable] ?? {}).length < 2) { - set({ - error: 'Unable to parse coordinates. Please use CF conventions.', - }) - _unregisterLoading('metadata') - return - } + // if (Object.keys(cfAxes[initialVariable] ?? {}).length < 2) { + // set({ + // error: 'Unable to parse coordinates. Please use CF conventions.', + // }) + // _unregisterLoading('metadata') + // return + // } get().setVariable(initialVariable, { clim }) _unregisterLoading('metadata') diff --git a/components/dataset.js b/components/dataset.js index 9eeef8e..237dac5 100644 --- a/components/dataset.js +++ b/components/dataset.js @@ -66,10 +66,10 @@ const Dataset = () => { setStoreUrl() try { - const { url, cf_axes, pyramid } = await inspectDataset(value) + const { url, pyramid, metadata } = await inspectDataset(value) if (pyramid) { // Use pyramid when present - setStoreUrl(url, { cfAxes: cf_axes, pyramid: true, clim }) + setStoreUrl(url, { metadata, pyramid: true, clim }) } else { // Otherwise construct Zarr proxy URL const u = new URL(url) @@ -77,7 +77,7 @@ const Dataset = () => { 'https://ok6vedl4oj7ygb4sb2nzqvvevm0qhbbc.lambda-url.us-west-2.on.aws/' + u.hostname + u.pathname, - { cfAxes: cf_axes, pyramid: false, clim } + { metadata, pyramid: false, clim } ) } } catch (e) { diff --git a/components/utils/data.js b/components/utils/data.js index 2c9dd0a..9cc395e 100644 --- a/components/utils/data.js +++ b/components/utils/data.js @@ -95,11 +95,7 @@ export const toKeyArray = (chunkKey, { chunk_separator }) => { return chunkKey.split(chunk_separator).map(Number) } -export const getMetadata = async (url, pyramid) => { - // fetch zmetadata to figure out compression and variables - const response = await fetch(`${url}/.zmetadata`) - const metadata = await response.json() - +export const getVariables = async (metadata, pyramid) => { if (!metadata.metadata) { throw new Error(metadata?.message || 'Unable to parse metadata') } @@ -146,7 +142,7 @@ export const getMetadata = async (url, pyramid) => { .filter(Boolean) .map((a) => a[0]) - return { metadata, variables, levels } + return { variables, levels } } const getChunkShapeOverride = (chunkShape, shape, dimensions, axes) => { @@ -697,7 +693,7 @@ export const validatePoint = ([lon, lat]) => { } // Infer axes from consolidated metadata -const inferCfAxes = (metadata, pyramid) => { +export const inferCfAxes = (metadata, pyramid) => { const prefix = pyramid ? '0/' : '' const suffix = '/.zattrs' @@ -819,44 +815,11 @@ export const inspectDataset = async (url) => { let visualizedUrl = sanitized const multiscales = metadata.metadata['.zattrs']['multiscales'] - let cf_axes = metadata.metadata['.zattrs']['ncviewjs:cf_axes'] - const rechunking = metadata.metadata['.zattrs']['ncviewjs:rechunking'] ?? [] - const store_url = metadata.metadata['.zattrs']['ncviewjs:store_url'] - - if (store_url) { - visualizedUrl = sanitizeUrl(store_url) - let storeInfo - try { - storeInfo = await inspectDataset(visualizedUrl) - metadata = storeInfo.metadata - cf_axes ||= storeInfo.cf_axes - } catch (e) { - // Do not surface CF axes based on ability to deduce for nested_store - } - } - if (multiscales) { pyramid = true - } else if (rechunking && rechunking.length > 0) { - const pyramidRechunked = rechunking.find( - (r) => r.use_case === 'multiscales' - ) - if (pyramidRechunked) { - pyramid = true - visualizedUrl = sanitizeUrl(pyramidRechunked.path) - const { cf_axes: pyramidCfAxes } = await inspectDataset(visualizedUrl) - cf_axes = pyramidCfAxes ?? cf_axes - } - } - - cf_axes ||= inferCfAxes(metadata.metadata, pyramid) - if (!cf_axes || Object.keys(cf_axes).length === 0) { - throw new Error( - 'No CF axes information provided and unable to infer from metadata.' - ) } - return { url: visualizedUrl, cf_axes, metadata, pyramid } + return { url: visualizedUrl, metadata, pyramid } } export const isNullValue = (p, variable) => {