0.2.6 • Published 4 years ago

erddap4js v0.2.6

Weekly downloads
5
License
ISC
Repository
github
Last release
4 years ago

erddap4js - ERDDAP JavaScript interface for the browser & Node

Node.js CI

Simple ERDDAP library for JS, written in TypeScript. Works in Node or the browser. Supports tabledap and griddap queries. Browser version is dependency free.

Quickstart

Browser example

See a demo in demo/browser/index.html

Copy the file dist/browser/ERDDAP.js to the same folder with your HTML file.

<script src="ERDDAP.js"></script>
<script>
  document.addEventListener("DOMContentLoaded", async function () {
    const erddapServer = new ERDDAP("https://coastwatch.pfeg.noaa.gov/erddap");

    const tableData = await erddapServer.tabledap({
      dataset: "erdCinpKfmSFNH",
      variables: ["id", "common_name"],
      constraints: [
        ["time", ">=", "2007-06-24T00:00:00Z"],
        ["size", ">=", 140],
        ["common_name", "=~", ".*urchin.*"],
      ],
      distinct: true,
    });
  });
</script>

Node example

The import is different, the rest is the same as the browser example above.

npm install erddap4js
const ERDDAP = require("erddap4js").default;

See a demo in demo/node/query.js

Documentation

ERDDAP()

const erddapServer = new ERDDAP("https://coastwatch.pfeg.noaa.gov/erddap");

To use debug mode add a second argument of true, this will console log URLs of all queries.

tabledap()

  • Everything is case sensitive
  • Constraints are ANDed together
  • Operators are !=, =~, <=, >=, =, <, >
  • Order types are: orderBy, orderByClosest, orderByCount, orderByLimit, orderByMax, orderByMin, orderByMinMax, orderByMean
await erddapServer.tabledap({
  dataset: "erdCinpKfmSFNH",
  variables: ["id", "common_name"],
  constraints: [
    ["time", ">=", "2007-06-24T00:00:00Z"],
    ["common_name", "=~", ".*urchin.*"],
  ],
  orderType: "orderBy", // optional
  orderVariables: ["common_name"], // must have unless it's "orderByCount"
  distinct: true, // optional
});

Sample response:

[{ id: "Anacapa (Landing Cove)", common_name: "Red sea urchin" } ... ];

griddap()

  • Constraints are set differently for griddap.
  • make sure to match number of dimensions with that of the dataset
  • dimension properties must be ordered as they appear in the dataset (time, altitude, latitude, longitude)
  • to add a stride argument (to get every nth value), add another element to the range array, eg ["2010-12-16T12:00:00Z", "2010-12-16T12:00:00Z",3]
await erddapServer.griddap({
  dataset: "jplAmsreSstMon_LonPM180",
  time: ["2010-12-16T12:00:00Z", "2010-12-16T12:00:00Z"],
  latitude: [50, 50],
  longitude: [-150, -120],
  variables: ["tos", "tosNobs", "tosStderr"],
});

Sample response:

[ { time: '2010-12-16T12:00:00Z',
  latitude: 50.5,
  longitude: -150,
  tos: 6.109735,
  tosNobs: 3175,
  tosStderr: 0.6101171 }, ... ]

info()

Get variable and global attribute information for this dataset

await erddapServer.info("erdCinpKfmSFNH");

Sample response:

[ { "Row Type": "attribute",
    "Variable Name": "NC_GLOBAL",
    "Attribute Name": "acknowledgement",
    "Data Type": "String",
    "Value": "NOAA NESDIS COASTWATCH, NOAA SWFSC ERD, Channel Islands National Park, National Park Service"
    },
    ...
  { "Row Type": "variable",
    "Variable Name": "longitude",
    "Attribute Name": "",
    "Data Type": "double",
    "Value": "",
  }, ...]

allDatasets()

Get metadata for all datasets- griddap, tabledap and others

await erddapServer.allDatasets();

Sample response:

[
  {
    datasetID: 'jplAmsreSstMon',
    accessible: 'public',
    institution: 'Remote Sensing Systems',
    dataStructure: 'grid',
    cdm_data_type: 'Grid',
    class: 'EDDGridSideBySide',
    title: 'AMSRE Model Output, obs4MIPs NASA-JPL, Global, 1 Degree, 2002-2010, Monthly',
      ... many more fields ...
  }, ... ]

CORS

Lots of ERDDAP servers won't support CORS, so you may run into this issue while trying to use ERDDAP in your browser. Read more about CORS and ERDDAP

Development

  • npm run build - build the 'dist' directory
  • npm test to run tests
  • npm run coverage - to build a folder 'coverage' to see coverage reports in your browser
  • act - test Github Actions with act
0.2.6

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago