Skip to content

Commit

Permalink
Remove checks against ncviewjs:-prefixed attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
katamartin committed Apr 26, 2024
1 parent a2e033d commit c206859
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 59 deletions.
13 changes: 7 additions & 6 deletions components/data/dataset.js
Original file line number Diff line number Diff line change
@@ -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 = {}

Expand Down
18 changes: 9 additions & 9 deletions components/data/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand All @@ -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')
Expand Down
6 changes: 3 additions & 3 deletions components/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,18 @@ 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)
setStoreUrl(
'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) {
Expand Down
45 changes: 4 additions & 41 deletions components/utils/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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'

Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit c206859

Please sign in to comment.