Note
----
Please register for NREL_API_KEY at https://developer.nrel.gov/signup/, it's free. 

@author: skoeb
"""

import PySAM.ResourceTools as tools
import PySAM.Windpower as wp
import PySAM.Singleowner as so
    
# --- Initialize Wind Fetcher ---
wtkfetcher = tools.FetchResourceFiles(
                tech='wind',
                workers=1, #thread workers if fetching multiple files
                nrel_api_key=<NREL_API_KEY>,
                nrel_api_email=<NREL_API_EMAIL>)

# --- Pass a list of (lon, lat) tuples or Shapely points to fetch the nearest resource data ---
lon_lats = [(-105.1800775, 39.7383155)]  # golden CO
wtkfetcher.fetch(lon_lats)
    
# --- Get resource data file path ---
wtk_path_dict = wtkfetcher.resource_file_paths_dict
wtk_fp = wtk_path_dict[lon_lats[0]]

# --- Initialize Generator ---
generator = wp.default('WindPowerSingleOwner')
generator.Resource.assign({'wind_resource_model_choice': 0})
generator.Resource.assign({'wind_resource_filename': wtk_fp}) #pass path to resource file
Exemple #2
0
geocode = False
if geocode:
    # See https://geocoder.readthedocs.io/ for different geocoding services
    g = geocoder.bing('golden, co', key=geocode_api_key)
    lon = g.latlng[1]
    lat = g.latlng[0]
else:
    lon = -105.22
    lat = 39.75

# --- Wind Example ---

# --- Initialize Wind Resource Fetcher using minimum parameters---
# See function documentation for full parameter list
wtkfetcher = tools.FetchResourceFiles(tech='wind',
                                      nrel_api_key=sam_api_key,
                                      nrel_api_email=sam_email)

# --- List of (lon, lat) tuples or Shapely points ---
lon_lats = [(lon, lat)]
wtkfetcher.fetch(lon_lats)

# --- Get resource data file path ---
wtk_path_dict = wtkfetcher.resource_file_paths_dict
wtk_fp = wtk_path_dict[lon_lats[0]]

# --- Initialize generator ---
if wtk_fp is not None:
    generator = wp.default('WindPowerSingleOwner')
    generator.Resource.assign({'wind_resource_model_choice': 0})
    generator.Resource.assign({'wind_resource_filename': wtk_fp})
Exemple #3
0
def test_resourcefilefetcher():

    # please get your own API key from here https://developer.nrel.gov/signup/
    NREL_API_KEY = 'HIiOQJN8C4dcWoJ5cxJ6Cl9LdEOQeo7c2bL67WqA'
    NREL_API_EMAIL = '*****@*****.**'

    lon_lats = [(-105.1800775, 39.7383155)]  # golden CO

    resource_dir = str(Path(__file__).parent / "tmp")

    # --- fetch solar tmy file from psm3-tmy using default parameters ---
    solarfetcher = tools.FetchResourceFiles(tech='solar',
                                            nrel_api_key=NREL_API_KEY,
                                            nrel_api_email=NREL_API_EMAIL,
                                            resource_dir=resource_dir)
    solarfetcher.fetch(lon_lats)

    # --- read csv and confirm dimensions ---
    solar_path_dict = solarfetcher.resource_file_paths_dict
    solar_fp = solar_path_dict[lon_lats[0]]
    solar_csv = pd.read_csv(solar_fp)
    num_timesteps = 8760
    assert solar_csv.shape[0] == num_timesteps + 2

    # --- test legacy 'pv' instead of 'solar'---
    solarfetcher = tools.FetchResourceFiles(tech='pv',
                                            nrel_api_key=NREL_API_KEY,
                                            nrel_api_email=NREL_API_EMAIL,
                                            resource_dir=resource_dir)
    solarfetcher.fetch(lon_lats)

    # --- read csv and confirm dimensions ---
    solar_path_dict = solarfetcher.resource_file_paths_dict
    solar_fp = solar_path_dict[lon_lats[0]]
    solar_csv = pd.read_csv(solar_fp)
    num_timesteps = 8760
    assert solar_csv.shape[0] == num_timesteps + 2

    # --- fetch solar single-year 30-min file from psm3 ---
    solarfetcher = tools.FetchResourceFiles(tech='solar',
                                            nrel_api_key=NREL_API_KEY,
                                            nrel_api_email=NREL_API_EMAIL,
                                            resource_dir=resource_dir,
                                            resource_type='psm3',
                                            resource_year='2018',
                                            resource_interval_min=30)
    solarfetcher.fetch(lon_lats)

    # --- read csv and confirm dimensions ---
    solar_path_dict = solarfetcher.resource_file_paths_dict
    solar_fp = solar_path_dict[lon_lats[0]]
    solar_csv = pd.read_csv(solar_fp)
    num_timesteps = 17520
    assert solar_csv.shape[0] == num_timesteps + 2

    # --- fetch solar tgy for 2018 from psm3-tmy ---
    solarfetcher = tools.FetchResourceFiles(tech='solar',
                                            nrel_api_key=NREL_API_KEY,
                                            nrel_api_email=NREL_API_EMAIL,
                                            resource_dir=resource_dir,
                                            resource_type='psm3-tmy',
                                            resource_year='tgy-2018')
    solarfetcher.fetch(lon_lats)

    # --- read csv and confirm dimensions ---
    solar_path_dict = solarfetcher.resource_file_paths_dict
    solar_fp = solar_path_dict[lon_lats[0]]
    solar_csv = pd.read_csv(solar_fp)
    num_timesteps = 8760
    assert solar_csv.shape[0] == num_timesteps + 2

    # --- fetch 5-minute data for 2018 from psm3-5min ---
    # this NSRDB API endpoint not working properly as of 8/21/2020
    #solarfetcher = tools.FetchResourceFiles(
    #                tech='solar',
    #                nrel_api_key=NREL_API_KEY,
    #                nrel_api_email=NREL_API_EMAIL,
    #                resource_dir=resource_dir,
    #                resource_type='psm3-5min',
    #                resource_interval_min=5,
    #                resource_year='2018')
    #solarfetcher.fetch(lon_lats)

    # --- read csv and confirm dimensions ---
    #solar_path_dict = solarfetcher.resource_file_paths_dict
    #solar_fp = solar_path_dict[lon_lats[0]]
    #solar_csv = pd.read_csv(solar_fp)
    #num_timesteps = 175200
    #assert solar_csv.shape[0] == num_timesteps+2

    # --- fetch wind ---
    wtkfetcher = tools.FetchResourceFiles(tech='wind',
                                          nrel_api_key=NREL_API_KEY,
                                          nrel_api_email=NREL_API_EMAIL,
                                          resource_dir=resource_dir)
    wtkfetcher.fetch(lon_lats)

    # --- read csv and confirm dimensions ---
    wtk_path_dict = wtkfetcher.resource_file_paths_dict
    wtk_fp = wtk_path_dict[lon_lats[0]]
    wtk_csv = pd.read_csv(wtk_fp)
    assert wtk_csv.shape == (8764, 10)

    shutil.rmtree(resource_dir)
Exemple #4
0
def test_resourcefilefetcher():
    load_dotenv()
    # please get your own API key from here https://developer.nrel.gov/signup/
    NREL_API_KEY = os.environ.get('NREL_API_KEY')
    NREL_API_EMAIL = os.environ.get('NREL_API_EMAIL')

    lon_lats = [(-105.1800775, 39.7383155)]  # golden CO

    resource_dir = str(Path(__file__).parent / "tmp")

    # --- fetch solar tmy file from psm3-tmy using default parameters ---
    solarfetcher = tools.FetchResourceFiles(tech='solar',
                                            nrel_api_key=NREL_API_KEY,
                                            nrel_api_email=NREL_API_EMAIL,
                                            resource_dir=resource_dir)
    solarfetcher.fetch(lon_lats)

    # --- read csv and confirm dimensions ---
    solar_path_dict = solarfetcher.resource_file_paths_dict
    solar_fp = solar_path_dict[lon_lats[0]]
    with open(solar_fp, mode='r') as f:
        reader = csv.DictReader(f)
        list(reader)
        num_timesteps = 8760
        assert reader.line_num == num_timesteps + 3

    # --- test legacy 'pv' instead of 'solar'---
    solarfetcher = tools.FetchResourceFiles(tech='pv',
                                            nrel_api_key=NREL_API_KEY,
                                            nrel_api_email=NREL_API_EMAIL,
                                            resource_dir=resource_dir)
    solarfetcher.fetch(lon_lats)

    # --- read csv and confirm dimensions ---
    solar_path_dict = solarfetcher.resource_file_paths_dict
    solar_fp = solar_path_dict[lon_lats[0]]
    with open(solar_fp, mode='r') as f:
        solar_csv = csv.DictReader(f)
        list(solar_csv)
        num_timesteps = 8760
        assert solar_csv.line_num == num_timesteps + 3

    # --- fetch solar single-year 30-min file from psm3 ---
    solarfetcher = tools.FetchResourceFiles(tech='solar',
                                            nrel_api_key=NREL_API_KEY,
                                            nrel_api_email=NREL_API_EMAIL,
                                            resource_dir=resource_dir,
                                            resource_type='psm3',
                                            resource_year='2018',
                                            resource_interval_min=30)
    solarfetcher.fetch(lon_lats)

    # --- read csv and confirm dimensions ---
    solar_path_dict = solarfetcher.resource_file_paths_dict
    solar_fp = solar_path_dict[lon_lats[0]]
    with open(solar_fp, mode='r') as f:
        solar_csv = csv.DictReader(f)
        list(solar_csv)
        num_timesteps = 17520
        assert solar_csv.line_num == num_timesteps + 3

    # --- fetch solar tgy for 2018 from psm3-tmy ---
    solarfetcher = tools.FetchResourceFiles(tech='solar',
                                            nrel_api_key=NREL_API_KEY,
                                            nrel_api_email=NREL_API_EMAIL,
                                            resource_dir=resource_dir,
                                            resource_type='psm3-tmy',
                                            resource_year='tgy-2018')
    solarfetcher.fetch(lon_lats)

    # --- read csv and confirm dimensions ---
    solar_path_dict = solarfetcher.resource_file_paths_dict
    solar_fp = solar_path_dict[lon_lats[0]]
    with open(solar_fp, mode='r') as f:
        solar_csv = csv.DictReader(f)
        list(solar_csv)
        num_timesteps = 8760
        assert solar_csv.line_num == num_timesteps + 3

    # --- fetch 5-minute data for 2018 from psm3-5min ---
    # this NSRDB API endpoint not working properly as of 8/21/2020
    #solarfetcher = tools.FetchResourceFiles(
    #                tech='solar',
    #                nrel_api_key=NREL_API_KEY,
    #                nrel_api_email=NREL_API_EMAIL,
    #                resource_dir=resource_dir,
    #                resource_type='psm3-5min',
    #                resource_interval_min=5,
    #                resource_year='2018')
    #solarfetcher.fetch(lon_lats)

    # --- read csv and confirm dimensions ---
    #solar_path_dict = solarfetcher.resource_file_paths_dict
    #solar_fp = solar_path_dict[lon_lats[0]]
    #solar_csv = pd.read_csv(solar_fp)
    #num_timesteps = 175200
    #assert solar_csv.shape[0] == num_timesteps+2

    # --- fetch wind ---
    wtkfetcher = tools.FetchResourceFiles(tech='wind',
                                          nrel_api_key=NREL_API_KEY,
                                          nrel_api_email=NREL_API_EMAIL,
                                          resource_dir=resource_dir)
    wtkfetcher.fetch(lon_lats)

    # --- read csv and confirm dimensions ---
    wtk_path_dict = wtkfetcher.resource_file_paths_dict
    wtk_fp = wtk_path_dict[lon_lats[0]]
    with open(wtk_fp, mode='r') as f:
        wtk_csv = csv.DictReader(f)
        list(wtk_csv)
        assert wtk_csv.line_num == 8764 + 1

    shutil.rmtree(resource_dir)