This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pd.DataFrame({ | |
"t_2": df.head(11)["energy"].shift(2), | |
"t_1": df.head(11)["energy"].shift(), | |
"energy": df.head(11)["energy"] | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df.head(11).diff() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tsextract.feature_extraction.extract import build_features, build_features_forecast | |
from tsextract.domain.statistics import mean, median, std | |
features_request = { | |
"window": [48], | |
"window_statistic": [48, mean], | |
"difference_statistic": [48, 1, std], | |
} | |
build_df = build_features(df.energy, features_request, target_lag=48, include_tzero=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scaler_features = StandardScaler().fit(build_df[build_df.columns.values[:-1]]) | |
scaled_features = scaler_features.transform(build_df[build_df.columns.values[:-1]]) | |
scaler_label = StandardScaler().fit(np.array(build_df[build_df.columns.values[-1]]).reshape(-1, 1)) | |
scaled_label = scaler_label.transform(np.array(build_df[build_df.columns.values[-1]]).reshape(-1, 1)) | |
### Split data using train proportion of 0.7 | |
train_size = int(scaled_features[:, :-1].shape[0] * 0.7) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras.models import Sequential | |
from keras.layers import Dense, Dropout | |
model = Sequential() | |
model.add(Dense(128, input_dim=X_train.shape[1], kernel_initializer='normal', activation='relu')) | |
model.add(Dropout(0.3)) | |
model.add(Dense(64, kernel_initializer='normal', activation='relu')) | |
model.add(Dropout(0.3)) | |
model.add(Dense(1, kernel_initializer='normal')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
! pip install --upgrade git+https://github.com/SheffieldSolar/PV_Live-API | |
from pvlive_api import PVLive | |
from datetime import datetime | |
import pytz | |
pvl = PVLive() | |
years = [2014, 2015, 2016, 2017, 2018, 2019] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Build Features for forecasting | |
build_forecast_df = build_features_forecast(df.energy, features_request, include_tzero=True) | |
scaled_features_forecast = scaler_features.transform(build_forecast_df.tail(48)) | |
pred = model.predict(scaled_features_forecast[:, :-1]) | |
pred = scaler_label.inverse_transform(pred) | |
# Range for next 24 hours | |
range = pd.date_range(start=build_df.index[-1]+timedelta(minutes=30), | |
end=build_df.index[-1]+timedelta(hours=24), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tsextract.plots.eval import actualPred, get_lag_corr, scatter | |
actualPred(y_test.reshape(-1, ), test_pred.reshape(-1)) | |
scatter(y_test.reshape(-1, ), test_pred.reshape(-1)) | |
get_lag_corr(y_test.reshape(-1, ), test_pred.reshape(-1), num_lags=20) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
import numpy as np | |
from scipy import ndimage | |
from skimage import filters | |
from skimage.filters import laplace, sobel_h, sobel_v | |
from skimage.feature import canny | |
from skimage.color import rgb2hsv | |
img = np.array(Image.open(img_path)) | |
img_hsv = rgb2hsv(img) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from plantcv import plantcv as pcv | |
from PIL import Image | |
import numpy as np | |
import cv2 | |
img = cv2.imread(img_path) | |
a = pcv.rgb2gray_lab(img, channel='a') | |
img_binary = pcv.threshold.binary(gray_img=a, threshold=120, max_value=255, object_type='dark') | |
greenPlants = pcv.fill(bin_img=img_binary, size=200) |
OlderNewer