Update app.py
Browse files
app.py
CHANGED
@@ -113,42 +113,36 @@ def forecast_solar_energy(historical_data):
|
|
113 |
# Read and preprocess CSV data for prediction
|
114 |
def preprocess_csv_for_prediction(csv_file):
|
115 |
try:
|
116 |
-
# Load the dataset
|
117 |
data = pd.read_csv(csv_file.name)
|
118 |
|
119 |
# Validate column names
|
120 |
expected_columns = ['Month', 'Hour', 'Irradiance(W/m^2)', 'Latitude', 'Longitude',
|
121 |
'Panel_Capacity(W)', 'Panel_Efficiency', 'Wind_Speed(km/h)',
|
122 |
'Cloud_Cover(%)', 'temperature (°f)']
|
123 |
-
if
|
124 |
-
return f"Error:
|
125 |
|
126 |
-
#
|
127 |
-
|
128 |
-
return "Error: CSV must have at least 43 rows of data for prediction"
|
129 |
|
130 |
-
#
|
131 |
-
|
132 |
-
'Cloud_Cover(%)', 'temperature (°f)']
|
133 |
-
last_43_days = data.tail(43)[relevant_columns]
|
134 |
-
|
135 |
-
# Handle missing values (replace NaNs with 0)
|
136 |
-
if last_43_days.isnull().any().any():
|
137 |
-
last_43_days.fillna(0, inplace=True)
|
138 |
|
139 |
-
#
|
140 |
-
|
141 |
-
sequence =
|
142 |
|
143 |
return sequence
|
144 |
except Exception as e:
|
145 |
return f"Error in preprocessing CSV: {str(e)}"
|
146 |
|
147 |
|
|
|
148 |
# Function to process image and forecast energy using CSV file
|
149 |
# Function to process image and forecast energy using CSV file
|
150 |
def process_image_and_forecast(image, min_area, pixel_area, clip_limit, tile_size, panel_type,
|
151 |
-
|
152 |
try:
|
153 |
# Process the uploaded image
|
154 |
if image is None:
|
|
|
113 |
# Read and preprocess CSV data for prediction
|
114 |
def preprocess_csv_for_prediction(csv_file):
|
115 |
try:
|
116 |
+
# Load the dataset
|
117 |
data = pd.read_csv(csv_file.name)
|
118 |
|
119 |
# Validate column names
|
120 |
expected_columns = ['Month', 'Hour', 'Irradiance(W/m^2)', 'Latitude', 'Longitude',
|
121 |
'Panel_Capacity(W)', 'Panel_Efficiency', 'Wind_Speed(km/h)',
|
122 |
'Cloud_Cover(%)', 'temperature (°f)']
|
123 |
+
if not all(col in data.columns for col in expected_columns):
|
124 |
+
return f"Error: Missing expected columns. Required: {expected_columns}"
|
125 |
|
126 |
+
# Select the relevant columns (ensure all 43 features are included)
|
127 |
+
last_row = data.tail(1)[expected_columns] # Use only the last row of data
|
|
|
128 |
|
129 |
+
# Fill missing values
|
130 |
+
last_row.fillna(0, inplace=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
|
132 |
+
# Reshape the data to match the model's input shape
|
133 |
+
sequence = last_row.values.astype(np.float32)
|
134 |
+
sequence = sequence.reshape((1, 1, 43)) # (batch_size, time_step, features)
|
135 |
|
136 |
return sequence
|
137 |
except Exception as e:
|
138 |
return f"Error in preprocessing CSV: {str(e)}"
|
139 |
|
140 |
|
141 |
+
|
142 |
# Function to process image and forecast energy using CSV file
|
143 |
# Function to process image and forecast energy using CSV file
|
144 |
def process_image_and_forecast(image, min_area, pixel_area, clip_limit, tile_size, panel_type,
|
145 |
+
panel_length, panel_width, irradiance, electricity_rate, historical_data_csv):
|
146 |
try:
|
147 |
# Process the uploaded image
|
148 |
if image is None:
|