Skip to content

Commit

Permalink
Update XML parsing utils
Browse files Browse the repository at this point in the history
  • Loading branch information
mpiannucci committed Apr 15, 2024
1 parent ade97a5 commit 0776e8a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
18 changes: 12 additions & 6 deletions datasets/datasets_local.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,27 @@
"drop_variables": ["Itime2"]
},
"ngofs2_2d": {
"path": "s3://nextgen-dmac-cloud-ingest/nos/ngofs2/nos.ngofs2.2ds.best.nc.zarr",
"path": "s3://nextgen-dmac-cloud-ingest-nosofs/nos/ngofs2/nos.ngofs2.2ds.best.nc.zarr",
"type": "kerchunk",
"chunks": {},
"drop_variables": ["Itime2"]
},
"hrrr": {
"path": "./datasets/hrrr.dswrf.nc",
"type": "netcdf",
"nyofs": {
"path": "s3://nextgen-dmac-cloud-ingest-nosofs/nos/nyofs/nos.nyofs.fields.forecast.20240409.t23z.nc.zarr",
"type": "kerchunk",
"chunks": {},
"drop_variables": []
},
"hrrr_subhourly": {
"path": "s3://nextgen-dmac/kerchunk/hrrr_subhourly.json",
"sscofs": {
"path": "s3://nextgen-dmac-cloud-ingest-nosofs/nos/sscofs/sscofs.fields.best.nc.zarr",
"type": "kerchunk",
"chunks": {},
"drop_variables": ["Itime", "Itime2"]
},
"hrrr": {
"path": "./datasets/hrrr.dswrf.nc",
"type": "netcdf",
"chunks": {},
"drop_variables": []
}
}
27 changes: 16 additions & 11 deletions viewer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"preview": "vite preview"
},
"dependencies": {
"fast-xml-parser": "^3.21.1",
"fast-xml-parser": "^4.3.2",
"he": "^1.2.0",
"maplibre-gl": "^2.4.0",
"material-icons": "^1.12.2",
Expand Down
12 changes: 6 additions & 6 deletions viewer/src/tools.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { parse, X2jOptions } from 'fast-xml-parser';
import { XMLParser, X2jOptions } from 'fast-xml-parser';
import { Map, LngLat, LngLatBounds } from "maplibre-gl";
import he from 'he';

const XML_PARSER_OPTIONS: Partial<X2jOptions> = {
ignoreAttributes: false,
parseAttributeValue: true,
tagValueProcessor: a => he.decode(a),
attrValueProcessor: a => he.decode(a, { isAttributeValue: true })
tagValueProcessor: (_, tagValue) => he.decode(tagValue),
};

/**
* Parses XML data to a javascript object
* @param data
* @param data
* @returns a javascript object representation of the xml data tree
*/
export function xmlToJSON(data: any): any {
return parse(data, XML_PARSER_OPTIONS);
const parser = new XMLParser(XML_PARSER_OPTIONS);
return parser.parse(data, false);
}

/**
Expand All @@ -36,7 +36,7 @@ export function bboxContainsPoint(bbox: [number, number, number, number], point:
if (bbox[0] === -180 && bbox[2] === -180) {
inLon = true;
}

return (inLon && inLat);
} catch (e) {
console.error(e);
Expand Down

0 comments on commit 0776e8a

Please sign in to comment.