solar-rad

0.0.4 • Public • Published

solar-rad

A node module for retrieving data from the United States National Solar Radiation Database (NSRDB) API.

Installation

$ npm install solar-rad 

Usage

const sr = require('solar-rad')

API Key

For extended usage, you should request an API Key. If not specified, a demo key will be used, but usage is limited. See: https://developer.nrel.gov/docs/api-key/

fetch

Return the data associated with a particular latitude+longitude point.

  let { data } = await sr.fetch({
    lat: 40.48343343339606, // required
    lon: -86.97950005531311,// required
    api_key, // if omitted, defaults to the demo key
    email, // required
    years: [1998, 1999, 2000] //earliest valid year is 1998; defaults to 1998 - now
  })
Sample Output
{
  "1998-02-01T00:30:00-05:00": {
    Year: '1998',
    Month: '1',
    Day: '1',
    Hour: '0',
    Minute: '30',
    Temperature: '-11',
    'Clearsky DHI': '0',
    'Clearsky DNI': '0',
    'Clearsky GHI': '0',
    'Cloud Type': '4',
    'Dew Point': '-14',
    DHI: '0',
    DNI: '0',
    'Fill Flag': '0',
    GHI: '0',
    'Relative Humidity': '78.44',
    'Solar Zenith Angle': '161.95000000000002',
    'Surface Albedo': '0.866',
    Pressure: '1000',
    'Precipitable Water': '0.5690000000000001',
    'Wind Direction': '201.70000000000002',
    'Wind Speed': '3.2',
    template: 'f159fcc9c6c1c9344fa74b809c3a9194', // Template reference, see below
    time: '1998-02-01T00:30:00-05:00'
  },
  ...
}

fetch - optional params

Additional arguments listed here may also be included for additional control: https://developer.nrel.gov/docs/solar/nsrdb/psm3-download/

  let { data } = await sr.fetch({
    lat: 40.48343343339606, // required
    lon: -86.97950005531311,// required
    api_key, // if omitted, defaults to the demo key
    email, // required
    years: [1998, 1999, 2000], //earliest valid year is 1998; defaults to 1998 - now

    // Optional parameters and their defaults:
    attributes, //defaults to all, see documentation above
    interval: '60', // or '30'
    leap_day: false,
    utc: false,
    mailing_list: false,
    reason: 'undefined',
    full_name: 'undefined',
    affilliation: 'undefined',
  })

aggregate

Aggregate the data to daily.

  let { data } = await sr.fetch({
    lat: 40.48343343339606,
    lon: -86.97950005531311,
    api_key, // if omitted, defaults to the demo key
    email, // required
    years: [1998, 1999, 2000] //earliest valid year is 1998; defaults to 1998 - now
  })

  let daily = await sr.aggregate(data, 'daily');

Generate report of missing data

  let { data } = await sr.fetch({
    lat: 40.48343343339606,
    lon: -86.97950005531311
  })

  let interval = 3600*1000; // time in ms
  let missing = await missingDataReport(data, interval);

Templates

Each data point is assigned a template under the template key. Templates specify the units and metadata about the output data to avoid repitition within the data points themselves.

  let { data, templates } = await sr.fetch({
    lat: 40.48343343339606,
    lon: -86.97950005531311,
    api_key, // if omitted, defaults to the demo key
    email, // required
    years: [1998, 1999, 2000] //earliest valid year is 1998; defaults to 1998 - now
  })

  console.log(template)
/*
{
  "f159fcc9c6c1c9344fa74b809c3a9194": {
    Source: 'NSRDB',
    'Location ID': '917192',
    City: '-',
    State: '-',
    Country: '-',
    Latitude: '40.49',
    Longitude: '-86.98',
    'Time Zone': '-5',
    Elevation: { value: '222', units: 'meters' },
    'Local Time Zone': '-5',
    'Clearsky DHI': { units: 'w/m2' },
    'Clearsky DNI': { units: 'w/m2' },
    'Clearsky GHI': { units: 'w/m2' },
    'Dew Point': { units: 'c' },
    DHI: { units: 'w/m2' },
    DNI: { units: 'w/m2' },
    GHI: { units: 'w/m2' },
    'Solar Zenith Angle': { units: 'Degree' },
    Temperature: { units: 'c' },
    Pressure: { units: 'mbar' },
    'Relative Humidity': { units: '%' },
    'Precipitable Water': { units: 'cm' },
    'Wind Direction': { units: 'Degrees' },
    'Wind Speed': { units: 'm/s' },
    'Cloud Type': {
      enumerate: {
        '0': 'Clear',
        '1': 'Probably Clear',
        '2': 'Fog',
        '3': 'Water',
        '4': 'Super-Cooled Water',
        '5': 'Mixed',
        '6': 'Opaque Ice',
        '7': 'Cirrus',
        '8': 'Overlapping',
        '9': 'Overshooting',
        '10': 'Unknown',
        '11': 'Dust',
        '12': 'Smoke',
        '-15': 'N/A'
      }
    },
    'Fill Flag': {
      enumerate: {
        '0': 'N/A',
        '1': 'Missing Image',
        '2': 'Low Irradiance',
        '3': 'Exceeds Clearsky',
        '4': 'Missing CLoud Properties',
        '5': 'Rayleigh Violation'
      }
    },
    'Surface Albedo': { units: 'N/A' },
    Version: '3.0.6'
  }
}
*/

CSV Output

The data is provided in a JSON structure that can be readily prepared for use with the popular node package csvjson:

let out = csvjson.toCSV(Object.values(data), {delimiter: ",", wrap: false});
fs.writeFileSync(`output-nsrdb.csv`, out);

/*
[].Year,[].Month,[].Day,[].Hour,[].Minute,[].Temperature,[].Clearsky DHI,[].Clearsky DNI,[].Clearsky GHI,[].Cloud Type,[].Dew Point,[].DHI,[].DNI,[].Fill Flag,[].GHI,[].Relative Humidity,[].Solar Zenith Angle,[].Surface Albedo,[].Pressure,[].Precipitable Water,[].Wind Direction,[].Wind Speed,[].template,[].time
1998,1,1,0,30,-11,0,0,0,4,-14,0,0,0,0,78.44,161.95000000000002,0.866,1000,0.5690000000000001,201.70000000000002,3.2,f159fcc9c6c1c9344fa74b809c3a9194,1998-02-01T00:30:00-05:00
*/

This package uses the Physical Solar Model (PSM) v3. See https://developer.nrel.gov/docs/solar/nsrdb/ for additional details.

Package Sidebar

Install

npm i solar-rad

Weekly Downloads

33

Version

0.0.4

License

Apache-2.0

Unpacked Size

34.8 MB

Total Files

354

Last publish

Collaborators

  • sanoel