Example #1
0
 def test_point_metadata(self):
     '''Validate pandas return of sites ordered by distance to the nearest point to
     a WKT using metadata
     '''
     wkt = "POINT(-103.128662109375 40.24179856487036)"
     result = get_3tiersites_from_wkt(wkt)
     self.assertEqual(53252, result.index[0])
Example #2
0
def get_nrel_site(state):
    """Retrieve ID of wind farms in given state.

    :param list state: list of state abbreviation.
    :return: (*pandas.DataFrame*) -- data frame with *'site_id'*, *'lat'*,
        *'lon'*, *'capacity'* and *'capacity_factor'* as columns.
    """
    site = None

    for s in state:
        coord = np.column_stack((states[s]['lons'], states[s]['lats']))

        # Prepare coordinates for call
        # Convert into string format
        out_tot = []
        for i in coord:
            out = str(i[0]) + ' ' + str(i[1]) + ','
            out_tot.append(out)
        out = str(coord[0][0]) + ' ' + str(coord[0][1])
        out_tot.append(out)
        str1 = ''.join(out_tot)
        str_final = 'POLYGON((' + str1 + '))'
        print('Retrieving nrel sites for ' + s)
        site_tmp = get_3tiersites_from_wkt(str_final)
        print('Got ' + str(site_tmp.shape[0]) + ' sites in ' + s)
        site_tmp = site_tmp.reset_index()
        if site is not None:
            site = site.append(site_tmp[['site_id', 'lat', 'lon', 'capacity',
                                         'capacity_factor']])
        else:
            site = site_tmp[['site_id', 'lat', 'lon', 'capacity',
                             'capacity_factor']].copy()
    return site
Example #3
0
def handler(event, context):
    '''Expose API thru Lambda.  Restrict returns to MAX_RETURN_SIZE.  An estimate
    on return size is made and if it exceeds the limit data will not be pulled in.

    Required event parameters:
        type - "site", "forecast", "metrology"

    Must have only one of the following event parameters:
        wkt - Well Known Text string of area to return site data
        sites - list of site ids

    Optional event parameters, some required for certain data types:
        wkt - Well Known Text string of area to return site data
        sites - list of site ids
        date_from - Unix timestamp of start date
        date_to - Unix timestamp of end date

    Returns:
        {"success": true, "data": data} for success
        {"success": false, "message": reason} for failure
    '''
    required_params = set(["type"])
    missing_params = required_params - set(event.keys())
    if len(missing_params) > 0:
        return {
            "success": False,
            "message": "Missing event parameters: %s" % list(missing_params)
        }
    dtype = event["type"]
    valid_dtypes = ["site", "forecast", "metrology"]
    if dtype not in valid_dtypes:
        return {
            "success": False,
            "message": "Invalid data type, must be one of %s" % valid_dtypes
        }
    if "wkt" in event.keys() and "sites" not in event.keys():
        site_list = get_3tiersites_from_wkt(event["wkt"])
    elif "sites" in event.keys() and "wkt" not in event.keys():
        site_list = site.loc(event["sites"]).copy()
    else:
        return {
            "success": False,
            "message":
            "Must define either wkt containing sites or a list of sites"
        }
    if dtype == "site":
        ret_data = site_list
    retsize = df_size(ret_data)
    if retsize > MAX_RETURN_SIZE:
        return {
            "success":
            False,
            "data":
            "Return data too large at %.2f MB, limit is %s MB" %
            (retsize, MAX_RETURN_SIZE)
        }
    return {"success": True, "data": ret_data.to_json()}
Example #4
0
 def test_rectangle(self):
     '''Validate pandas return of multiple sites within a rectangle using metadata
     '''
     #https://mapsbeta.nrel.gov/api/developer_proxy?wkt=POLYGON((-120.82763671875+34.452218472826566%2C-119.19616699218749+34.452218472826566%2C-119.19616699218749+33.920571528675104%2C-120.82763671875+33.920571528675104%2C-120.82763671875+34.452218472826566))&attributes=power%2Ctemperature&names=2012&site_url=wind-toolkit%2Fwind%2Fwtk_download.json&full_name=Your+Name&email=your.email%40here&affiliation=NREL&mailing_list=false&reason=Development+testing&leap_day=true&utc=true
     wkt = "POLYGON((-120.82763671875 34.452218472826566,-119.19616699218749 34.452218472826566,-119.19616699218749 33.920571528675104,-120.82763671875 33.920571528675104,-120.82763671875 34.452218472826566))"
     sites = get_3tiersites_from_wkt(wkt)
     from_zip = [
         29375, 29733, 29872, 30019, 30190, 30539, 30712, 30713, 30873,
         30874, 31032, 31033, 31034, 31189, 31190, 31191, 31192, 31320,
         31321, 31322, 31323, 31324, 31563, 32060, 32314, 32834, 33203,
         34828
     ]
     #expected = set([str(x) for x in from_zip])
     self.assertEqual(set(from_zip), set(sites.index))
Example #5
0
def get_wind_data_by_wkt(wkt,
                         names,
                         attributes=None,
                         interval=5,
                         leap_day=True,
                         utc=False,
                         dataset="met"):
    '''Duplicate functionality of URL data grabber at
    https://mapsbeta.nrel.gov/api/developer_proxy

    The data in both the condensed hdf and original nc files are in UTC

    Required Args:
        wkt - (String) Well Known Text describing a point of area for use in GIS
              mapping to wind sites
        names - (List of Strings) List of year names

    Optional Args:
        attributes - (String or List of Strings) List of attributes to retrieve
                      from the database.  Limited to MET_ATTRS.
        interval - Limited to H5_AVAILABLE_DATA_INTERVALS
        leap_day - (boolean) Include leap day data or remove it.  Defaults to
                   True, include leap day data
        utc - (boolean) Keep as UTC or convert to local time.  Defaults to local
        dataset - (String) Dataset to retrieve, met or forecast.  Defaults to met

    Returns:
        dict of site_id to Pandas dataframe containing requested data
    '''
    if dataset == "met":
        data_dir = WIND_MET_NC_DIR
    elif dataset == "forecast":
        data_dir = WIND_FCST_DIR
    else:
        raise Exception("Invalid data to retrieve: %s" % type)
    ret_dict = {}
    for site_id in get_3tiersites_from_wkt(wkt).index.values:
        site_tz = timezones.iloc[site_id]['zoneName']
        _logger.info("Site %s is in %s", site_id, site_tz)
        ret_df = pandas.DataFrame()
        for year in names:
            if utc == False:
                # Min datetime in UTC
                min_dt = pandas.Timestamp('%s-01-01' % year,
                                          tz=site_tz).tz_convert('utc')
                # Max datetime in UTC
                max_dt = pandas.Timestamp('%s-12-31 23:59:59' % year,
                                          tz=site_tz).tz_convert('utc')
            else:
                min_dt = pandas.Timestamp('%s-01-01' % year, tz='utc')
                max_dt = pandas.Timestamp('%s-12-31 23:59:59' % year, tz='utc')
            #ret_df = ret_df.append(data_function(site_id, min_dt, max_dt, attributes, leap_day, utc))
            ret_df = ret_df.append(
                get_nc_data(site_id, min_dt, max_dt, attributes, leap_day, utc,
                            data_dir))
        ret_dict[site_id] = ret_df
        # Break on POINT as it will return all sites in order of distance to the
        # wkt point
        if 'POINT' in wkt:
            break
    return ret_dict