예제 #1
0
 def test_nmar_destroyer(self):
     turbine = NREL().get_turbine(NREL.park_id['tehachapi'], 2004)
     timeseries = turbine.get_measurements()[:1000]
     damaged, indices = NMARDestroyer().destroy(timeseries, percentage=.50,\
             min_length=10, max_length=50)
     misses = MissingDataFinder().find(damaged, 600)
     assert(len(misses) > 0)
예제 #2
0
    def test_mreg_interpolation_multi(self):
        park_id = NREL.park_id['tehachapi']
        windpark = NREL().get_windpark(park_id, 3, 2004)
        target = windpark.get_target()
        timestep = 600
        measurements = target.get_measurements()[300:350]
        damaged, indices = MARDestroyer().destroy(measurements, percentage=.50)
        before_misses = MissingDataFinder().find(damaged, timestep)
        neighbors = windpark.get_turbines()[:-1]
        count_neighbors = len(neighbors)
        reg = 'knn' # KNeighborsRegressor(10, 'uniform')
        regargs = {'n' : 10, 'variant' : 'uniform'}

        processed = 0
        missed = {k : count_neighbors for k in indices}
        exclude = []
        damaged_nseries = []

        for neighbor in neighbors:
            nseries = neighbor.get_measurements()[300:350]
            damaged, indices = MARDestroyer().destroy(nseries, percentage=.50, exclude=exclude)

            for index in indices:
                if(index not in missed.keys()):
                    missed[index] = count_neighbors
                missed[index] -= 1
                if(missed[index] == 1):
                    exclude.append(index) # exclude in next iterations
            damaged_nseries.append(damaged)

        t_hat = MRegInterpolation().interpolate(damaged, timestep=timestep,\
            neighbor_series=damaged_nseries, reg=reg, regargs=regargs)

        after_misses = MissingDataFinder().find(t_hat, timestep)
        assert(len(after_misses) < 1)
예제 #3
0
 def test_marthres_destroyer(self):
     turbine = NREL().get_turbine(NREL.park_id['tehachapi'], 2004)
     timeseries = turbine.get_measurements()[:1000]
     damaged, indices = MARThresDestroyer().destroy(timeseries, percentage=.50,\
             lower_bound = 0, upper_bound = 20)
     misses = MissingDataFinder().find(damaged, 600)
     assert(len(misses) > 0)
예제 #4
0
 def setUpClass(cls):
     ds = NREL()
     cls.turbine = ds.get_turbine(NREL.park_id['tehachapi'], 2004, 2005)
     cls.windpark = ds.get_windpark(NREL.park_id['tehachapi'], 3, 2004,
                                    2005)
     cls.pmapping = PowerMapping()
     cls.pdmapping = PowerDiffMapping()
예제 #5
0
def down(citynum, methodnum):
    cityname = [
        'tehachapi', 'cheyenne', 'palmsprings', 'lasvegas', 'lancaster'
    ]
    method = [
        'KMeans', 'SpectralClustering', 'AgglomerativeClustering', 'Birch'
    ]
    target_idx = NREL.park_id[cityname[citynum]]
    year_from, year_to = 2004, 2006
    if sys.version_info < (3, ):
        mode = 'rU'
    else:
        mode = 'r'
    csvfile = 'cluster/' + method[methodnum] + '200.csv'
    pick = []
    with open(csvfile, mode) as csv_arch:
        reader = csv.reader(csv_arch, delimiter=',')
        for row in reader:
            pick.append(int(row[0]))

    nrel = NREL()
    d = 0
    turbines = nrel.fetch_nrel_meta_data_all()

    for row in turbines:
        turbine_index = np.int(row[0])
        if (turbine_index != target_idx):
            if (pick[turbine_index - 1] == pick[target_idx - 1]):
                d = d + 1
                for y in range(year_from, year_to + 1):
                    measurement = nrel.fetch_nrel_data(
                        row[0], y, ['date', 'corrected_score', 'speed'])
예제 #6
0
    def test_mreg_interpolation_multi(self):
        park_id = NREL.park_id['tehachapi']
        windpark = NREL().get_windpark(park_id, 3, 2004)
        target = windpark.get_target()
        timestep = 600
        measurements = target.get_measurements()[300:350]
        damaged, indices = MARDestroyer().destroy(measurements, percentage=.50)
        before_misses = MissingDataFinder().find(damaged, timestep)
        neighbors = windpark.get_turbines()[:-1]
        count_neighbors = len(neighbors)
        reg = 'knn' # KNeighborsRegressor(10, 'uniform')
        regargs = {'n' : 8, 'variant' : 'uniform'}

        processed = 0
        missed = {k : count_neighbors for k in indices}
        exclude = []
        damaged_nseries = []

        for neighbor in neighbors:
            nseries = neighbor.get_measurements()[300:350]
            damaged, indices = MARDestroyer().destroy(nseries, percentage=.50, exclude=exclude)

            for index in indices:
                if(index not in missed.keys()):
                    missed[index] = count_neighbors
                missed[index] -= 1
                if(missed[index] == 1):
                    exclude.append(index) # exclude in next iterations
            damaged_nseries.append(damaged)

        t_hat = MRegInterpolation().interpolate(damaged, timestep=timestep,\
            neighbor_series=damaged_nseries, reg=reg, regargs=regargs)

        after_misses = MissingDataFinder().find(t_hat, timestep)
        assert(len(after_misses) < 1)
예제 #7
0
 def test_nmar_destroyer(self):
     turbine = NREL().get_turbine(NREL.park_id['tehachapi'], 2004)
     timeseries = turbine.get_measurements()[:1000]
     damaged, indices = NMARDestroyer().destroy(timeseries, percentage=.50,\
             min_length=10, max_length=50)
     misses = MissingDataFinder().find(damaged, 600)
     assert(len(misses) > 0)
예제 #8
0
def compute_mse(regressor, horizon):
    # get wind park and corresponding target. 
    windpark = NREL().get_windpark(NREL.park_id['tehachapi'], 3, 2004, 2005)
    target = windpark.get_target()

    # use power mapping for pattern-label mapping. 
    feature_window = 3
    mapping = PowerMapping()
    X = mapping.get_features_park(windpark, feature_window, horizon)
    y = mapping.get_labels_turbine(target, feature_window, horizon)

    # train roughly for the year 2004, test for 2005.
    train_to = int(math.floor(len(X) * 0.5))
    test_to = len(X)
    train_step, test_step = 25, 25
    X_train=X[:train_to:train_step]
    y_train=y[:train_to:train_step]
    X_test=X[train_to:test_to:test_step]
    y_test=y[train_to:test_to:test_step]

    if(regressor == 'svr'):
        reg = SVR(kernel='rbf', epsilon=0.1, C = 100.0,\
                gamma = 0.0001).fit(X_train,y_train)
        mse = mean_squared_error(reg.predict(X_test),y_test)
    elif(regressor == 'knn'):
        reg = KNeighborsRegressor(10, 'uniform').fit(X_train,y_train)
        mse = mean_squared_error(reg.predict(X_test),y_test)
    return mse
예제 #9
0
 def test_marthres_destroyer(self):
     turbine = NREL().get_turbine(NREL.park_id['tehachapi'], 2004)
     timeseries = turbine.get_measurements()[:1000]
     damaged, indices = MARThresDestroyer().destroy(timeseries, percentage=.50,\
             lower_bound = 0, upper_bound = 20)
     misses = MissingDataFinder().find(damaged, 600)
     assert(len(misses) > 0)
예제 #10
0
def amount_of_windmills(radius, park):
    target = NREL.park_id[park]
    ds = NREL()
    windpark = ds.get_windpark(target, radius, 2004, 2005)
    target = ds.get_windmill(target, 2004, 2005)
    windmills = windpark.get_windmills()
    return len(windmills)
예제 #11
0
def compute_mse(regressor, param):
    # get wind park and corresponding target. forecast is for the target
    # turbine
    park_id = NREL.park_id['tehachapi']
    windpark = NREL().get_windpark(park_id, 3, 2004)
    target = windpark.get_target()

    # use power mapping for pattern-label mapping. Feature window length
    # is 3 time steps and time horizon (forecast) is 3 time steps.
    feature_window = 6
    horizon = 3
    mapping = PowerMapping()
    X = mapping.get_features_park(windpark, feature_window, horizon)
    Y = mapping.get_labels_turbine(target, feature_window, horizon)

    # train roughly for the year 2004.
    train_to = int(math.floor(len(X) * 0.5))

    # test roughly for the year 2005.
    test_to = len(X)

    # train and test only every fifth pattern, for performance.
    train_step, test_step = 5, 5

    if (regressor == 'rf'):
        # random forest regressor
        reg = RandomForestRegressor(n_estimators=param, criterion='mse')
        reg = reg.fit(X[0:train_to:train_step], Y[0:train_to:train_step])
        y_hat = reg.predict(X[train_to:test_to:test_step])
    elif (regressor == 'knn'):
        # TODO the regressor does not need to be newly trained in
        # the case of KNN
        reg = KNeighborsRegressor(param, 'uniform')
        # fitting the pattern-label pairs
        reg = reg.fit(X[0:train_to:train_step], Y[0:train_to:train_step])
        y_hat = reg.predict(X[train_to:test_to:test_step])
    else:
        raise Exception("No regressor set.")

    # naive is also known as persistence model.
    naive_hat = zeros(len(y_hat), dtype=float32)
    for i in range(0, len(y_hat)):
        # naive label is the label as horizon time steps before.
        # we have to consider to use only the fifth label here, too.
        naive_hat[i] = Y[train_to + (i * test_step) - horizon]

    # computing the mean squared errors of Linear and naive prediction.
    mse_y_hat, mse_naive_hat = 0, 0
    for i in range(0, len(y_hat)):
        y = Y[train_to + (i * test_step)]
        mse_y_hat += (y_hat[i] - y)**2
        mse_naive_hat += (naive_hat[i] - y)**2

    mse_y_hat /= float(len(y_hat))
    mse_naive_hat /= float(len(y_hat))

    return mse_y_hat, mse_naive_hat
예제 #12
0
def compute_mse(regressor, param):
    # get wind park and corresponding target. forecast is for the target
    # turbine
    park_id = NREL.park_id['tehachapi']
    windpark = NREL().get_windpark(park_id, 3, 2004)
    target = windpark.get_target()

    # use power mapping for pattern-label mapping. Feature window length
    # is 3 time steps and time horizon (forecast) is 3 time steps.
    feature_window = 6
    horizon = 3
    mapping = PowerMapping()
    X = mapping.get_features_park(windpark, feature_window, horizon)
    Y = mapping.get_labels_turbine(target, feature_window, horizon)

    # train roughly for the year 2004.
    train_to = int(math.floor(len(X) * 0.5))

    # test roughly for the year 2005.
    test_to = len(X)

    # train and test only every fifth pattern, for performance.
    train_step, test_step = 5, 5

    if(regressor == 'rf'):
        # random forest regressor
        reg = RandomForestRegressor(n_estimators=param, criterion='mse')
        reg = reg.fit(X[0:train_to:train_step], Y[0:train_to:train_step])
        y_hat = reg.predict(X[train_to:test_to:test_step])
    elif(regressor == 'knn'):
        # TODO the regressor does not need to be newly trained in
        # the case of KNN
        reg = KNeighborsRegressor(param, 'uniform')
        # fitting the pattern-label pairs
        reg = reg.fit(X[0:train_to:train_step], Y[0:train_to:train_step])
        y_hat = reg.predict(X[train_to:test_to:test_step])
    else:
        raise Exception("No regressor set.")

    # naive is also known as persistence model.
    naive_hat = zeros(len(y_hat), dtype = float32)
    for i in range(0, len(y_hat)):
        # naive label is the label as horizon time steps before.
        # we have to consider to use only the fifth label here, too.
        naive_hat[i] = Y[train_to + (i * test_step) - horizon]

    # computing the mean squared errors of Linear and naive prediction.
    mse_y_hat, mse_naive_hat = 0, 0
    for i in range(0, len(y_hat)):
        y = Y[train_to + (i * test_step)]
        mse_y_hat += (y_hat[i] - y) ** 2
        mse_naive_hat += (naive_hat[i] - y) ** 2

    mse_y_hat /= float(len(y_hat))
    mse_naive_hat /= float(len(y_hat))

    return mse_y_hat, mse_naive_hat
예제 #13
0
    def test_backward_copy_interpolation(self):
        park_id = NREL.park_id['tehachapi']
        windpark = NREL().get_windpark(park_id, 10, 2004)
        target = windpark.get_target()
        timestep = 600
        measurements = target.get_measurements()[300:500]
        damaged, indices = MARDestroyer().destroy(measurements, percentage=.50)
        before_misses = MissingDataFinder().find(damaged, timestep)
        t_hat = BackwardCopy().interpolate(measurements, timestep=timestep)
        after_misses = MissingDataFinder().find(t_hat, timestep)

        assert(measurements.shape[0] == t_hat.shape[0])
        assert(len(after_misses) < 1)
예제 #14
0
    def test_backward_copy_interpolation(self):
        park_id = NREL.park_id['tehachapi']
        windpark = NREL().get_windpark(park_id, 10, 2004)
        target = windpark.get_target()
        timestep = 600
        measurements = target.get_measurements()[300:500]
        damaged, indices = MARDestroyer().destroy(measurements, percentage=.50)
        before_misses = MissingDataFinder().find(damaged, timestep)
        t_hat = BackwardCopy().interpolate(measurements, timestep=timestep)
        after_misses = MissingDataFinder().find(t_hat, timestep)

        assert(measurements.shape[0] == t_hat.shape[0])
        assert(len(after_misses) < 1)
예제 #15
0
    def test_mreg_interpolation(self):
        park_id = NREL.park_id['tehachapi']
        windpark = NREL().get_windpark(park_id, 3, 2004)
        target = windpark.get_target()
        timestep = 600
        measurements = target.get_measurements()[300:500]
        damaged, indices = MARDestroyer().destroy(measurements, percentage=.50)
        before_misses = MissingDataFinder().find(damaged, timestep)
        neighbors = windpark.get_turbines()[:-1]

        reg = 'knn' # KNeighborsRegressor(10, 'uniform')
        regargs = {'n' : 8, 'variant' : 'uniform'}

        nseries = [t.get_measurements()[300:500] for t in neighbors]
        t_hat = MRegInterpolation().interpolate(damaged, timestep=timestep,\
            neighbor_series=nseries, reg=reg, regargs=regargs)
        after_misses = MissingDataFinder().find(t_hat, timestep)
        assert(len(after_misses) < 1)
예제 #16
0
    def test_mreg_interpolation(self):
        park_id = NREL.park_id['tehachapi']
        windpark = NREL().get_windpark(park_id, 3, 2004)
        target = windpark.get_target()
        timestep = 600
        measurements = target.get_measurements()[300:500]
        damaged, indices = MARDestroyer().destroy(measurements, percentage=.50)
        before_misses = MissingDataFinder().find(damaged, timestep)
        neighbors = windpark.get_turbines()[:-1]

        reg = 'knn' # KNeighborsRegressor(10, 'uniform')
        regargs = {'n' : 10, 'variant' : 'uniform'}

        nseries = [t.get_measurements()[300:500] for t in neighbors]
        t_hat = MRegInterpolation().interpolate(damaged, timestep=timestep,\
            neighbor_series=nseries, reg=reg, regargs=regargs)
        after_misses = MissingDataFinder().find(t_hat, timestep)
        assert(len(after_misses) < 1)
예제 #17
0
def fun(citynum,methodnum,K):
    park_id = NREL.park_id[cityname[citynum]]
    windpark = NREL().get_windpark(park_id, 10, 2004,2006)
    pla=[]
    kk=windpark.get_turbines()
    for i in range(len(kk)):
        pla.append(kk[i].idx)
        
    
    feature_window, horizon = 3, 3
    mapping = PowerMapping()   
    data_1 = np.array(mapping.get_features_park(windpark, feature_window, horizon)) 
     
    data_train = np.array(mapping.get_features_park(windpark, 1, 1))
    
    lendata=len(data_1)
    data1 = data_1[:lendata:3]
    l1=len(data_train)
    data_train1=data_train[:l1:3]
    half=int(math.floor(len(data1) * 0.5))
    
    traindata_1=data_train1[0:half,:]
    traindata1=np.transpose(traindata_1)
    traindata1=preprocessing.scale(np.array(traindata1),with_mean=True,with_std=True)
    if methodnum==0:
        ans = KMeans(n_clusters=K, random_state=0).fit(traindata1).predict(traindata1)
    if methodnum==1:
        ans = SpectralClustering(n_clusters=K, random_state=0).fit_predict(traindata1)
    if methodnum==2:
        ans = AgglomerativeClustering(n_clusters=K).fit_predict(traindata1)
    if methodnum==3:
        ans = Birch(n_clusters=K).fit_predict(traindata1)
    if methodnum==4:
        ans = DBSCAN(eps = 0.1).fit_predict(traindata1)
    fo = open('cluster10/'+cityname[citynum]+method[methodnum]+str(K)+'.csv','w', newline='')
    csv_write = csv.writer(fo,dialect='excel')
    for i in range(len(ans)):
        cc=[];
        cc.append(pla[i])
        cc.append(ans[i])
        csv_write.writerow(cc)
    fo.close()
예제 #18
0
    def test_topological_interpolation(self):
        park_id = NREL.park_id['tehachapi']
        windpark = NREL().get_windpark(park_id, 10, 2004)
        target = windpark.get_target()
        timestep = 600
        measurements = target.get_measurements()[300:500]
        damaged, indices = NMARDestroyer().destroy(measurements, percentage=.80,\
                min_length=10, max_length=100)

        tloc = (target.longitude, target.latitude)
        neighbors = windpark.get_turbines()[:-1]

        nseries = [t.get_measurements()[300:500] for t in neighbors]
        nlocs = [(t.longitude, t.latitude) for t in neighbors]

        t_hat = TopologicInterpolation().interpolate(\
                                    damaged, method="topologic",\
                                    timestep=timestep, location=tloc,\
                                    neighbor_series = nseries,\
                                    neighbor_locations = nlocs)
        misses = MissingDataFinder().find(t_hat, timestep)

        assert(measurements.shape[0] == t_hat.shape[0])
        assert(len(misses) < 1)
예제 #19
0
    def test_topological_interpolation(self):
        park_id = NREL.park_id['tehachapi']
        windpark = NREL().get_windpark(park_id, 10, 2004)
        target = windpark.get_target()
        timestep = 600
        measurements = target.get_measurements()[300:500]
        damaged, indices = NMARDestroyer().destroy(measurements, percentage=.80,\
                min_length=10, max_length=100)

        tloc = (target.longitude, target.latitude)
        neighbors = windpark.get_turbines()[:-1]

        nseries = [t.get_measurements()[300:500] for t in neighbors]
        nlocs = [(t.longitude, t.latitude) for t in neighbors]

        t_hat = TopologicInterpolation().interpolate(\
                                    damaged, method="topologic",\
                                    timestep=timestep, location=tloc,\
                                    neighbor_series = nseries,\
                                    neighbor_locations = nlocs)
        misses = MissingDataFinder().find(t_hat, timestep)

        assert(measurements.shape[0] == t_hat.shape[0])
        assert(len(misses) < 1)
예제 #20
0
 def test_nrel_repair(self):
     ds = NREL()
     target = ds.get_turbine(NREL.park_id['tehachapi'], 2004)
     measurements = target.get_measurements()[:43504]
     measurements = NRELRepair().repair(measurements)
     assert(NRELRepair().validate(measurements))
예제 #21
0
 def setUpClass(cls):
     ds = NREL()
     cls.windmill = ds.get_windmill(NREL.park_id['tehachapi'], 2004, 2005)
     cls.windpark = ds.get_windpark(NREL.park_id['tehachapi'], 3, 2004, 2005)
     cls.pmapping = PowerMapping()
     cls.pdmapping = PowerDiffMapping()
예제 #22
0
 def test_get_turbine(self):
     ds = NREL()
     target = ds.get_turbine(NREL.park_id['tehachapi'], 2004, 2005)
     t = target.get_measurements()[0]
     assert (len(t) == 3)
    for i in range(0, len(y_hat)):
        y = YT[i]
        mse_y_hat += (y_hat[i] - y)**2

    mse_y_hat /= float(len(y_hat))

    return mse_y_hat


# generating destroyed measurements which are constant over all
# methods

data = []

for park in parks.keys():
    windpark = NREL().get_windpark_nearest(parks[park], 5, 2004)
    windpark_test = NREL().get_windpark_nearest(parks[park], 5, 2005)

    target = windpark.get_target()
    measurements = repair_nrel(target.get_measurements()[:10000])

    for i in range(2):

        damaged_series = {}
        de = lambda rate: (rate, (destroy(
            measurements, method=destroy_method, percentage=rate)[0]))

        dseries = map(de, rates)
        for rate, series in dseries:
            damaged_series[rate] = series
예제 #24
0
"""
Histogram of Wind Speeds
-------------------------------------------------------------

Histograms of wind speeds of a turbine near Cheyenne in the year 2004.
"""

# Author: Jendrik Poloczek <*****@*****.**>
# License: BSD 3 clause

import matplotlib.pyplot as plt
from pylab import plt
from windml.datasets.nrel import NREL

ds = NREL()
turbine = ds.get_turbine(NREL.park_id['cheyenne'], 2004)
speeds = list(map(lambda x : x[2], turbine.measurements))

plt.hist(speeds, color="#c4d8eb", bins=10, normed = 1)
plt.show()
예제 #25
0
"""
Topography of a Wind Windpark Near Tehachapi
-------------------------------------------------------------------------

This example shows the topography of a wind park near Tehachapi. The red dots
illustrate the locations of wind mills.
"""

from windml.datasets.nrel import NREL
from windml.visualization.show_coord_topo import show_coord_topo

radius = 30
name = 'tehachapi'

windpark = NREL().get_windpark(NREL.park_id['tehachapi'], 30, 2004)

print "Working on windpark around target mill", str(windpark.get_target_idx())
print "Plotting windpark ..."

show_coord_topo(windpark)
예제 #26
0
 def test_get_windmill(self):
     ds = NREL()
     target = ds.get_windmill(NREL.park_id['tehachapi'], 2004, 2005)
     t = target.get_measurements()[0]
     assert(len(t) == 3)
예제 #27
0
"""

# Author: Oliver Kramer <*****@*****.**>
# License: BSD 3 clause

from __future__ import print_function
import sklearn
import numpy as np
import pylab as plt
from sklearn import manifold, decomposition
from builtins import range
from windml.datasets.nrel import NREL

# load data and define parameters / training and test sequences
K = 30
ds = NREL()
windpark = ds.get_windpark(NREL.park_id['tehachapi'], 10, 2004)

X = np.array(windpark.get_powermatrix())
X_train = X[:2000]
X_test = X[2000:2000 + 200 * 4]

# computation of ISOMAP projection
print("computation of ISOMAP projection")

X_latent = manifold.Isomap(K, n_components=2).fit_transform(X_train)

# computation of sequence of closest embedded patterns
sequence = []
for x in X_test:
    win = 0
예제 #28
0
 def setUpClass(cls):
     ds = NREL()
     cls.turbine = ds.get_turbine(NREL.park_id['tehachapi'], 2004)
     cls.windpark = ds.get_windpark(NREL.park_id['tehachapi'], 3, 2004)
예제 #29
0
 def test_get_windpark(self):
     ds = NREL()
     windpark = ds.get_windpark(NREL.park_id['tehachapi'], 10, 2004, 2005)
     assert(len(windpark.mills) == 66)
예제 #30
0
 def setUpClass(cls):
     ds = NREL()
     cls.turbine = ds.get_turbine(NREL.park_id['tehachapi'], 2004)
     cls.windpark = ds.get_windpark(NREL.park_id['tehachapi'], 3, 2004)
예제 #31
0
 def test_get_windpark(self):
     ds = NREL()
     windpark = ds.get_windpark(NREL.park_id['tehachapi'], 10, 2004, 2005)
     assert (len(windpark.turbines) == 66)
예제 #32
0
from matplotlib import dates
import matplotlib.pylab as plt
import datetime, time
import numpy as np

from numpy import array, matrix
from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import KFold
from sklearn import __version__ as sklearn_version
from sklearn.svm import SVR

from sklearn.neighbors import KNeighborsRegressor
from windml.datasets.nrel import NREL
from windml.visualization.plot_response_curve import plot_response_curve

ds = NREL()
turbine = ds.get_turbine(NREL.park_id['palmsprings'], 2004, 2006)
timeseries = turbine.get_measurements()
max_speed = 40
skip = 1

# plot true values as blue points
speed = [m[2] for m in timeseries[::skip]]
score = [m[1] for m in timeseries[::skip]]

# Second Plot: KNN-Interpolation
# Built patterns und labels
X_train = speed[0:len(speed):1]
Y_train = score[0:len(score):1]
X_train_array = array([[element] for element in X_train])
예제 #33
0
This examples shows the topology of a turbine and gives a statistical overview
for different characteristics of its time series.
"""

# Author: Oliver Kramer <*****@*****.**>
# License: BSD 3 clause

import matplotlib.pyplot as plt
import numpy as np
import windml.util.features

from windml.datasets.nrel import NREL
from windml.visualization.show_coord_topo_turbine import show_coord_topo_turbine

ds = NREL()
turbine = ds.get_turbine(NREL.park_id['tehachapi'], 2004)

feat, month_power, ramps_up, ramps_down, power_freq = windml.util.features.compute_highlevel_features(
    turbine)

month = [
    'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct',
    'nov', 'dec'
]
figure = plt.figure(figsize=(15, 10))

# plot 1
plot1 = plt.subplot(2, 2, 1)
plt.title("Turbine Location")
show_coord_topo_turbine(turbine, show=False)
예제 #34
0
"""
Histogram of Wind Speeds of a Wind Mill
-------------------------------------------------------------

Histograms of wind speeds of a wind mill near Cheyenne in the year 2004.
"""

import matplotlib.pyplot as plt
from pylab import plt
from windml.datasets.nrel import NREL

ds = NREL()
mill = ds.get_windmill(NREL.park_id['cheyenne'], 2004)
speeds = map(lambda x : x[2], mill.measurements)

plt.hist(speeds, color="#c4d8eb", bins=10, normed = 1)
plt.show()
예제 #35
0
"""
Histogram of Wind Speeds
-------------------------------------------------------------

Histograms of wind speeds of a turbine near Cheyenne in the year 2004.
"""

# Author: Jendrik Poloczek <*****@*****.**>
# License: BSD 3 clause

import matplotlib.pyplot as plt
from pylab import plt
from windml.datasets.nrel import NREL

ds = NREL()
turbine = ds.get_turbine(NREL.park_id['cheyenne'], 2004)
speeds = list(map(lambda x: x[2], turbine.measurements))

plt.hist(speeds, color="#c4d8eb", bins=10, normed=1)
plt.show()
예제 #36
0
This examples shows the topology of a turbine and gives a statistical overview
for different characteristics of its time series.
'''

# Author: Oliver Kramer <*****@*****.**>
# License: BSD 3 clause

import matplotlib.pyplot as plt
import numpy as np
import windml.util.features

from windml.datasets.nrel import NREL
from windml.visualization.show_coord_topo_turbine import show_coord_topo_turbine

ds = NREL()
turbine = ds.get_turbine(NREL.park_id['tehachapi'], 2004)

feat, month_power, ramps_up, ramps_down, power_freq = windml.util.features.compute_highlevel_features(
    turbine)

month = ['jan', 'feb', 'mar', 'apr', 'may', 'jun',
         'jul', 'aug', 'sep', 'oct', 'nov', 'dec']
figure = plt.figure(figsize=(15, 10))

# plot 1
plot1 = plt.subplot(2, 2, 1)
plt.title('Turbine Location')
show_coord_topo_turbine(turbine, show=False)

# plot 2
예제 #37
0
import numpy as np
import matplotlib.pyplot as plt
import math
import time
import csv
from windml.datasets.nrel import NREL
from windml.mapping.power_mapping import PowerMapping
from sklearn import preprocessing
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import mean_squared_error

start = time.clock()


park_id = NREL.park_id['cheyenne']
windpark = NREL().get_windpark(park_id, 5, 2004,2006)
target = windpark.get_target()
feature_window, horizon = 3, 3
mapping = PowerMapping()
    
data_1 = np.array(mapping.get_features_park(windpark, feature_window, horizon)) 
data_2 = np.array(mapping.get_labels_turbine(target, feature_window, horizon)).reshape(-1,1)
     
#目标多向前取feature_window个点
#data1 = np.array(mapping.get_features_park(windpark, feature_window*2, horizon))
#data2 = np.array(mapping.get_labels_turbine(target, feature_window*2, horizon)).reshape(-1,1)
#region = int(data1.shape[1]/(feature_window*2))
#for i in range(region-1):
#    for j in range(feature_window):
#        data1=np.delete(data1,[(i+1)*feature_window],axis = 1)
#
예제 #38
0
"""
Time-Series of Wind Speed and Power
--------------------------------------------------

This example plots a time-series of a single 
wind mill in the wind park 'tehachapi'.
"""

from matplotlib import dates
import matplotlib.pylab as plt
import numpy as np
import datetime, time

from windml.datasets.nrel import NREL
from windml.visualization.plot_timeseries import plot_timeseries

ds = NREL()
mill = ds.get_windmill(NREL.park_id['tehachapi'], 2004)
plot_timeseries(mill)
예제 #39
0
-------------------------------------------------------------------------

This examples shows a statistical overview of the power levels of a wind turbine. 
"""

# Author: Oliver Kramer <*****@*****.**>
# License: BSD 3 clause

import matplotlib.pyplot as plt
import numpy as np
import windml.util.features

from windml.datasets.nrel import NREL
from windml.visualization.show_coord_topo import show_coord_topo

ds = NREL()
windpark = ds.get_windpark(NREL.park_id['tehachapi'], 2, 2004)
X = np.array(windpark.get_powermatrix())

feat, month_power, ramps_up, ramps_down, power_freq =\
    windml.util.features.compute_highlevel_features(windpark.turbines[0])

help = [
    i * windml.util.features.interval_width
    for i in range(1, 30 / windml.util.features.interval_width + 1)
]
labels = [
    str(i - windml.util.features.interval_width) + "-" + str(i) for i in help
]

with plt.style.context("fivethirtyeight"):
예제 #40
0
citynum = 4
methodnum = 3
target_idx = NREL.park_id[cityname[citynum]]
year_from, year_to = 2004, 2006
if sys.version_info < (3, ):
    mode = 'rU'
else:
    mode = 'r'
csvfile = 'cluster/' + method[methodnum] + '200.csv'
pick = []
with open(csvfile, mode) as csv_arch:
    reader = csv.reader(csv_arch, delimiter=',')
    for row in reader:
        pick.append(int(row[0]))

nrel = NREL()
d = 0
turbines = nrel.fetch_nrel_meta_data_all()
result = Windpark(target_idx, 0)
for row in turbines:
    turbine_index = np.int(row[0])
    if (turbine_index != target_idx):
        if (pick[turbine_index - 1] == pick[target_idx - 1]):
            d = d + 1
            newturbine = Turbine(row[0], row[1], row[2], row[3], row[4],
                                 row[5], row[6])
            for y in range(year_from, year_to + 1):
                measurement = nrel.fetch_nrel_data(
                    row[0], y, ['date', 'corrected_score', 'speed'])
                if y == year_from:
                    measurements = measurement
예제 #41
0
 def test_nrel_repair(self):
     ds = NREL()
     target = ds.get_turbine(NREL.park_id['tehachapi'], 2005)
     measurements = target.get_measurements()[:43504]
     measurements = NRELRepair().repair(measurements)
     assert(NRELRepair().validate(measurements))
예제 #42
0
import matplotlib.pylab as plt
import datetime, time
import numpy as np

from numpy import array, matrix
from sklearn.grid_search import GridSearchCV
from sklearn.cross_validation import KFold
from sklearn import __version__ as sklearn_version
from sklearn.svm import SVR

from sklearn.neighbors import KNeighborsRegressor
from windml.datasets.nrel import NREL
from windml.visualization.plot_response_curve import plot_response_curve


ds = NREL()
turbine = ds.get_turbine(NREL.park_id['palmsprings'], 2004, 2006)
timeseries = turbine.get_measurements()
max_speed = 40
skip = 1


# plot true values as blue points
speed = [m[2] for m in timeseries[::skip]]
score = [m[1] for m in timeseries[::skip]]


# Second Plot: KNN-Interpolation
# Built patterns und labels
X_train = speed[0:len(speed):1]
Y_train = score[0:len(score):1]
예제 #43
0
from windml.preprocessing.preprocessing import destroy
from windml.preprocessing.preprocessing import interpolate
from windml.visualization.plot_timeseries import plot_timeseries
from sklearn.svm import SVR
from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import KFold

import matplotlib.pyplot as plt
import matplotlib.dates as md
from pylab import *

from numpy import array, zeros, float32, int32

# get windpark and corresponding target. forecast is for the target turbine
park_id = NREL.park_id['tehachapi']
windpark = NREL().get_windpark(park_id, 5, 2004)
target = windpark.get_target()

measurements = target.get_measurements()[300:1000]
damaged, indices = destroy(measurements, method='nmar', percentage=.80,\
        min_length=10, max_length=100)

neighbors = windpark.get_turbines()[:-1]
nseries = [t.get_measurements()[300:1000] for t in neighbors]

gamma_range = [0.0001, 0.000001]
C_range = [2**i for i in range(-3, 5, 1)]
regargs = {
    "epsilon": 0.1,
    "cv_method": "kfold",
    "cv_args": {
예제 #44
0
 def setUpClass(cls):
     ds = NREL()
     cls.windmill = ds.get_windmill(NREL.park_id['tehachapi'], 2004)
     cls.windpark = ds.get_windpark(NREL.park_id['tehachapi'], 3, 2004)
예제 #45
0
"""
Topography of a Windpark
-------------------------------------------------------------------------

This example shows the topography of a wind park near Tehachapi. The black dots
illustrate the locations of turbines. The red dot is the target turbine.
"""

# Author: Nils A. Treiber <*****@*****.**>
# License: BSD 3 clause

from windml.datasets.nrel import NREL
from windml.visualization.show_coord_topo import show_coord_topo

radius = 30
name = 'tehachapi'

windpark = NREL().get_windpark(NREL.park_id['tehachapi'], 30, 2004)

print "Working on windpark around target turbine", str(windpark.get_target_idx())
print "Plotting windpark ..."

title = "Some Turbines of NREL Data Set"
show_coord_topo(windpark, title)
예제 #46
0
from windml.datasets.nrel import NREL
from windml.mapping.power_mapping import PowerMapping
from windml.preprocessing.preprocessing import destroy
from windml.preprocessing.preprocessing import interpolate
from windml.visualization.plot_timeseries import plot_timeseries

import matplotlib.pyplot as plt
import matplotlib.dates as md
from pylab import *

from numpy import array, zeros, float32, int32

# get windpark and corresponding target. forecast is for the target turbine
park_id = NREL.park_id['tehachapi']
windpark = NREL().get_windpark(park_id, 3, 2004)
target = windpark.get_target()

measurements = target.get_measurements()[300:1000]
damaged, indices = destroy(measurements, method="nmar", percentage=.80,\
        min_length=10, max_length=100)

neighbors = windpark.get_turbines()[:-1]
nseries = [t.get_measurements()[300:1000] for t in neighbors]

tinterpolated = interpolate(damaged, method='mreg',\
                            timestep=600,\
                            neighbor_series = nseries,\
                            reg = 'linear_model')

d = array([m[0] for m in tinterpolated])
예제 #47
0
# Justin P. Heinermann <*****@*****.**>
# Stefan Oehmcke <*****@*****.**>
# License: BSD 3 clause

from __future__ import print_function
import math
import matplotlib.pyplot as plt
from numpy import zeros, float32
from windml.datasets.nrel import NREL
from windml.mapping.power_mapping import PowerMapping
from sklearn.neighbors import KNeighborsRegressor
from sklearn.metrics import mean_squared_error

# get windpark and corresponding target. forecast is for the target turbine
park_id = NREL.park_id['tehachapi']
windpark = NREL().get_windpark(park_id, 3, 2004, 2005)
target = windpark.get_target()

# use power mapping for pattern-label mapping.
feature_window, horizon = 3, 3
mapping = PowerMapping()
X = mapping.get_features_park(windpark, feature_window, horizon)
y = mapping.get_labels_turbine(target, feature_window, horizon)

# train roughly for the year 2004, test roughly for the year 2005.
train_to, test_to = int(math.floor(len(X) * 0.5)), len(X)
# train and test only every fifth pattern, for performance.
train_step, test_step = 5, 5
X_train = X[:train_to:train_step]
y_train = y[:train_to:train_step]
X_test = X[train_to:test_to:test_step]
예제 #48
0
"""
Flip-Book of Wind Speed
-------------------------------------------------------------------------

This example illustrates the wind speed of the turbines in the park
'tehachapi'. The figures visualize the wind situation at four different times
(with a difference of 20 min). The turbines are colorized with regard to the
wind strengths (from strong in red to low in blue).
"""

# Author: Nils A. Treiber <*****@*****.**>
# License: BSD 3 clause

from windml.datasets.nrel import NREL
from windml.visualization.show_flip_book import show_flip_book

ds = NREL()
windpark = ds.get_windpark(NREL.park_id["tehachapi"], 30, 2004)
show_flip_book(windpark, 4, 3460, 2)