-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLocalNetCDFMeta.tsx
More file actions
72 lines (60 loc) · 1.93 KB
/
LocalNetCDFMeta.tsx
File metadata and controls
72 lines (60 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use client';
import React, { ChangeEvent, useState } from 'react';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { MetaNetCDFAccordion } from './MetaNetCDFAccordion';
import { NetCDF4 } from '@earthyscience/netcdf4-wasm';
import BrowzarrCTA from './BrowzarrCTA';
const LocalNetCDFMeta = () => {
const [variables, setVariables] = useState<Record<string, unknown> | null>(null);
const [attributes, setAttributes] = useState<Record<string, unknown> | null>(null);
const [metadata, setMetadata] = useState<Record<string, unknown>[] | null>(null);
const handleFileSelect = async (
event: ChangeEvent<HTMLInputElement>
) => {
const files = event.target.files;
if (!files || files.length === 0) return;
const file = files[0];
try {
const data = await NetCDF4.fromBlobLazy(file);
const [variables, attrs, metadata] = await Promise.all([
data.getVariables(),
data.getGlobalAttributes(),
data.getFullMetadata(),
]);
setVariables(variables);
setAttributes(attrs);
setMetadata(metadata);
} catch (error) {
console.error('Error loading NetCDF file:', error);
alert('Failed to load NetCDF file. Check console for details.');
}
};
return (
<div className="grid w-full max-w-sm items-center gap-3 p-4 py-0">
<Label
htmlFor="netcdf-file"
className="justify-self-center font-semibold"
>
NetCDF file
</Label>
<Input
id="netcdf-file"
type="file"
accept=".nc,.netcdf,.nc3,.nc4"
onChange={handleFileSelect}
className="cursor-pointer"
/>
{variables && attributes && metadata && (
<MetaNetCDFAccordion
variables={variables}
attributes={attributes}
metadata={metadata}
/>
)
}
<BrowzarrCTA />
</div>
);
};
export default LocalNetCDFMeta;