npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

solar-rad

v0.0.4

Published

A node module for accessing NSRDB solar radiation data.

Downloads

176

Readme

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.