This mini-tutorial describes how to create DIRSIG-friendly formatted weather files (.wth) using weather data.

Note The tool used in this tutorial (makewth.py) designed to do a specific function and is not meant to be a robust tool.

Requirements

  • Python 3

    • Packages: numpy, pandas, os, sys, argparse and json.

  • A data source (2 options):

    • An API key from NREL’s NSRDB website

    • A "Properly formatted" weather data file (this very specific formatting is how weather data comes from the National Solar Radiation Database (NSRDB):

      • 30-minute time resolution

      • Data with specific column names:

        • "Temperature" - temperature in Celsius

        • "Pressure" - pressure in mbar

        • "Relative Humidity" - relative humidity in %

        • "Wind Speed" - wind speed in m/s

        • "DNI" - direct normal irradiance in W/m^2 (direct sun)

        • "DHI" - diffuse horizontal irradiance in W/m^2 (diffuse sky)

  • The makewth.py tool distributed with DIRSIG (can be found in the extra/makewth folder inside the DIRSIG installation directory)

Overview

This tool has 2 "modes": CSV Mode and API Mode. In CSV Mode the user provides weather data in a Comma Separated Values (CSV) file with a very specific format. The formatting requirements are listed above. When weather data is downloaded from NSRDB it comes in this format.

In API Mode the user will supply an API key which can be obtained from the NSRDB API signup page. Once the user has an API key the rest of the setup can be done with the make_wth.py tool.

Setting up makewth.py by editing a local copy

One way to set the options in makewth.py is by creating and editing a local copy of the script. Alternatively you can set all of these options via the command line.

  • ❏ Make a copy of makewth.py that you can edit. Using this setup requires that you edit this script with appropriate inputs. Making a copy of this file in your home directory or My Documents folder is the easiest, safest way to accomplish this step.

folder
Figure 1. An example of how one might organize their weather folder is shown here.
  • ❏ Edit the options section of the script.

    • ❏ Set the outfile variable to the filename you want your output .wth to be.

    • ❏ Set the daysoffset to the number of days you want to skip from the beginning of the data file.

makewth options1
Figure 2. The Options section inside make_wth.py. The General Options are used in both the CSV and API modes.
Note The output .wth file contains 48 hours of data at 15-minute time resolution. If your input data file contains, for example, 1 year of data, use the daysoffset variable to "select" which days you would like in your output.

Using CSV Mode

After setting the General Options, the CSV mode option (infile) should be set to run in CSV Mode.

makewth options2
Figure 3. The CSV mode options in makewth.py.
  • ❏ Set the infile variable to the file that contains your weather data (e.g. Miami.csv).

  • ❏ Double-check that api_mode is set to False to run in CSV Mode.

  • ❏ Run makewth.py. This can be done multiple ways. If you need help you can search online (eg. search "run python3 script in Windows 10"). Specific instructions for this step are not provided in this manual because this can vary system to system.

The output .wth file is ready to be used in your DIRSIG simulations.

Using API Mode

Using API Mode is recommended if you are planning on making weather files from more than 2 or 3 locations. The options available in this mode make it very easy to change time and location to quickly generate multiple weather files. Before proceeding, you will need an API key from the NSRDB API signup page.

Setting up your API Key

After receiving your API key from the NSRDB API signup page, you need to set up makewth.py to use it. The variables to do this are described below:

Note If your require spaces in these fields, use the + symbol as spaces (e.g. John+Doe or Academic+Research).
  • api_key is your api key you received from NREL

  • your_name is your name (e.g. John+Doe)

  • reason_for_use is the reason you are using the data

  • your_affiliation is the company or organization you are affiliated with.

  • your_email is your email address

  • mailing_list is set to true if you would like to sign up for updates about the NSRDB (otherwise is set to false).

These can be set and saved inside the script itself (they are located at the bottom of the Options section), or you can leave these blank and run makewth.py to have the script walk you through the setup. One benefit of leaving the fields blank is that the tool will provide you with instructions to set this information as an environment variable which will tie your API key to your computer account without saving it inside the script.

Setting the API Mode options

makewth options3
Figure 4. The API mode options in makewth.py.
  • ❏ Set the api_mode variable to True to enable API Mode.

  • ❏ Set the latitude (lat) and longitude (lon) of the location of interest.

  • ❏ Set the year to the year of interest.

  • ❏ Set the leap_year variable to true unless you want to ignore leap years.

  • ❏ Leave the time interval as 30, which is the highest frequency data available from NSRDB at this time.

  • ❏ Setting utc to true will use UTC as the time zone. Otherwise, the data will use the time zone local to the data location.

  • ❏ Run makewth.py. This can be done multiple ways. If you need help you can search online (eg. search "run python3 script in Windows 10"). Specific instructions for this step are not provided in this manual because this can vary system to system.

Setting options with the command line

Running makewth.py with the -h argument (e.g. python3 makewth.py -h) will display a list of the command line options. Note that in CSV Mode you only need to set the --outfile, --nskipdays, and --infile options. In API Mode the required arguments are --outfile, --nskipdays, --api_mode, --lat, --lon, --year, and --utc.

Below are two example commands for running makewth.py. The first example runs the tool in CSV Mode, and the second example runs it in API Mode.

Note If some (or all) of the arguments are missing from the command, the script will fall back on the values stored inside the script as defaults.
python3 makewth.py --outfile=my_weather.wth --nskipdays=10 --infile=raw/Denver.csv
python3 makewth.py --api_mode --outfile=my_weather.wth --nskipdays=10 --lat=39.742043 --lon=-104.991531 --year=2019 --utc=false

Both commands will save a weather file called my_weather.wth that is ready to be used with DIRSIG.