# -*- coding: utf-8 -*- """ Created on Tue Sep 10 12:51:48 2019 @author: IST_1 """ import helper import pandas as pd import numpy as np solar = helper.pv_data(address='Lancaster, Massachusetts', solar_size_kw_dc=6032, tilt=23.45) solar['year'] = 2018 total_output = solar.solar_output_kw.sum() print(total_output) date = pd.DataFrame() date['year'] = solar.year date['month'] = solar.month date['day'] = solar.day date['hour'] = solar.hour power = 2400 discharge_time = 2 peak_duration = 4 assumed_duration_multiplier = peak_duration / discharge_time #this is to calculate utilization based on the number of peak hours and discharge time #calculated by number of peak hours / discharge_time eff = 0.9
import pandas as pd import pvlib import datetime import helper import numpy as np from pvlib import clearsky, atmosphere, solarposition from pvlib.location import Location from pvlib.iotools import read_tmy3 from pvlib.forecast import GFS, NAM, NDFD, HRRR, RAP import ml date = pd.date_range(start='1/1/2018', end='12/31/2018', freq='H') solcast = pd.read_csv('new_york_solcast_data.csv') pv = helper.pv_data(address='New York, New York', solar_size_kw_dc=1000, tilt=0) dates = pd.to_datetime(solcast.Date) solcast.Date = dates #dirint_dni = pvlib.irradiance.dirint(solcast.Ghi,solcast.Zenith,times=pd.to_datetime(date)) solcast['Month'] = solcast.Date.dt.month solcast['Day'] = solcast.Date.dt.day solcast['Hour'] = solcast.Date.dt.hour solcast = solcast.drop(columns=['Date']) solcast = solcast.reindex(index=np.roll(solcast.index, -4)).reset_index( drop=True) solcast['solar_output_kw'] = pv.solar_output_kw solcast = solcast.drop(solcast.loc[(solcast.Dni == 0) & (solcast.Dhi == 0) & (solcast.Ghi == 0)].index) target_output = ['Dhi', 'Ghi', 'Dni'] #solcast.loc[solcast.Azimuth<=-1] = solcast.loc[solcast.Azimuth<=-1] + 360
""" Created on Thu Aug 8 14:37:04 2019 @author: IST_1 """ import csv import pandas as pd import numpy as np import helper txt_file = r"s3159989.txt" csv_file = r"solar_data.csv" with open(txt_file, 'r') as infile, open(csv_file, 'w') as outfile: stripped = (line.strip() for line in infile) lines = (line.split(",") for line in stripped if line) writer = csv.writer(outfile) writer.writerows(lines) df = pd.read_csv('solar_data.csv') tilt = -20 angle_of_array = 180 aoi = np.arccos((np.cos(df['Zenith (refracted)']) * np.cos(tilt)) + (np.sin(df['Zenith (refracted)']) * np.sin(tilt) * np.cos(df['Azimuth angle'] - angle_of_array))) dni_df = helper.pv_data(address='New York, NY', solar_size_kw_dc=1230, tilt=20) dni_df.direct_normal_irradiance = dni_df.direct_normal_irradiance * aoi
output = ml.load_models('entersolar_model.h5') import importlib importlib.reload(ml) start_idx = 0 length = 2000 target_names = target_output y_pred, y_true,x,mse = ml.plot_comparison(x_test_scaled,y_test,y_scaler, target_names,output, start_idx = start_idx, length=length, verbose=True) solar_pvwatts = helper.pv_data(coordinates=(lat,lon),solar_size_kw_dc = 1750,tilt=25) index = pd.date_range(start='1/1/'+str(2018), periods=8760, freq='60T') solar_pvwatts.index = index solar_pvwatts = solar_pvwatts.resample('15T').asfreq() #solar_pvwatts = solar_pvwatts.drop(columns={'month','day','hour'}) solar_pvwatts = solar_pvwatts.interpolate() solar_pvwatts = solar_pvwatts.reset_index(drop=True) solar_pvwatts = solar_pvwatts[seg_start:seg_end] segment_pvwatts = solar_pvwatts[-(int(np.ceil(len(segment)-0.9*(len(segment))))+1):-1] plt.figure(figsize=(15,5)) #plt.plot(segment_pvwatts.index,segment_pvwatts.solar_output_kw,'bo',alpha=0.5) plt.plot(segment_pvwatts.index,y_pred)
import ml import matplotlib.pyplot as plt import tensorflow as tf import numpy as np import pandas as pd import os from sklearn.preprocessing import MinMaxScaler from tensorflow.python.keras.models import Sequential from tensorflow.python.keras.layers import Input, Dense, GRU, Embedding, LSTM from tensorflow.python.keras.optimizers import RMSprop from tensorflow.python.keras.callbacks import EarlyStopping, ModelCheckpoint, TensorBoard, ReduceLROnPlateau import keras import helper import numpy as np solar = helper.pv_data(address = 'New York, NY', solar_size_kw_dc = 200, tilt = 20) import pandas as pd data = pd.read_csv('nyc_data2017.csv') data.columns = ['year','month','day','hour','minute','dhi','dni','ghi','x','surface_albedo','xx','pressure'] data = data.drop([0,1]) data = data.reset_index(drop=True) data = data.drop(columns=['x','xx','minute','year','month','day','hour']) data['solar_output_kw'] = solar.solar_output_kw #data['solar_irradiance'] = solar.solar_irradiance #solar_prev = solar.reindex(index=np.roll(solar.index,1*24)).reset_index(drop=True) #solar_2prev = solar.reindex(index=np.roll(solar.index,2*24)).reset_index(drop=True) #dni_prev = data.reindex(index=np.roll(data.index,1*24)).reset_index(drop=True).dni #dni_2prev = data.reindex(index=np.roll(data.index,2*24)).reset_index(drop=True).dni #dhi_prev = data.reindex(index=np.roll(data.index,1*24)).reset_index(drop=True).dhi
from sklearn.ensemble import RandomForestClassifier import numpy as np df = pd.read_excel('File 2.xlsx') df = df[['Device name', 'Unnamed: 8']] df = df.drop([0, 1, 2, 3, 4, 5, 6]) df = df.rename(columns={ 'Device name': 'date', 'Unnamed: 8': 'original_building_power_kw' }) df.date = pd.to_datetime(df.date) df.original_building_power_kw = df.original_building_power_kw / 1000 df['original_building_energy_kwh'] = df.original_building_power_kw / 4 df = df.sort_values(by='date') df = df.reset_index(drop=True) solar = helper.pv_data(address='Chirin Gita, Mexico', solar_size_kw_dc=80) df = helper.add_solar_to_df(df, solar, 4) #f['y'] = 'yes' #df['target'] = df['y'].apply(lambda x: 1 if x=='yes' else 0) df.isnull().mean().sort_values(ascending=False) * 100 #df.drop('y',axis=1,inplace=True) df.original_building_power_kw = df.original_building_power_kw.astype(float) df.original_building_energy_kwh = df.original_building_energy_kwh.astype(float) df.power_post_solar_kw = df.power_post_solar_kw.astype(float) df.energy_post_solar_kwh = df.energy_post_solar_kwh.astype(float) #df['month'] = df.date.dt.month.astype(float) #df['day'] = df.date.dt.day.astype(float) #df['hour'] = df.date.dt.hour.astype(float) corr = df.corr()