├── utils.py ├── cnn_lstm_model.h5 ├── predict_anomaly.py ├── SST_Exploration.ipynb ├── requirements.txt ├── Sea-Surface-Temperature-SST-Anomaly-Prediction.zip ├── train_model.py ├── README.md └── data_preprocessing.py /utils.py: -------------------------------------------------------------------------------- 1 | # utils.py placeholder 2 | -------------------------------------------------------------------------------- /cnn_lstm_model.h5: -------------------------------------------------------------------------------- 1 | # cnn_lstm_model.h5 placeholder 2 | -------------------------------------------------------------------------------- /predict_anomaly.py: -------------------------------------------------------------------------------- 1 | # predict_anomaly.py placeholder 2 | -------------------------------------------------------------------------------- /SST_Exploration.ipynb: -------------------------------------------------------------------------------- 1 | # SST_Exploration.ipynb placeholder 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | pandas 3 | matplotlib 4 | seaborn 5 | netCDF4 6 | xarray 7 | tensorflow 8 | keras 9 | scikit-learn 10 | h5py 11 | -------------------------------------------------------------------------------- /Sea-Surface-Temperature-SST-Anomaly-Prediction.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Otutu11/Sea-Surface-Temperature-SST-Anomaly-Prediction/main/Sea-Surface-Temperature-SST-Anomaly-Prediction.zip -------------------------------------------------------------------------------- /train_model.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import tensorflow as tf 3 | from tensorflow.keras import layers, models 4 | from src.utils import load_data 5 | 6 | X_train, y_train, X_val, y_val = load_data() 7 | 8 | model = models.Sequential([ 9 | layers.Conv2D(32, (3, 3), activation='relu', input_shape=(64, 64, 1)), 10 | layers.MaxPooling2D((2, 2)), 11 | layers.TimeDistributed(layers.Flatten()), 12 | layers.LSTM(64, return_sequences=False), 13 | layers.Dense(1) 14 | ]) 15 | 16 | model.compile(optimizer='adam', loss='mse', metrics=['mae']) 17 | model.fit(X_train, y_train, epochs=30, validation_data=(X_val, y_val)) 18 | model.save('models/cnn_lstm_model.h5') 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🌊 Sea-Surface-Temperature (SST) Anomaly Prediction 2 | 3 | This project predicts SST anomalies using LSTM neural networks and historical SST data. It includes data preprocessing, feature engineering, training, evaluation, and visualization. 4 | 5 | ## 📁 Structure 6 | - `data/`: Dataset (NOAA or simulated) 7 | - `models/`: Trained models 8 | - `src/`: Scripts for preprocessing, modeling, and utility functions 9 | - `main.py`: Main script for end-to-end prediction 10 | 11 | ## 📊 Dataset 12 | We use SST monthly data from NOAA or synthetic data for demonstration. You can replace `sst_data.csv` with actual gridded SST time series. 13 | 14 | ## 🧠 Model 15 | LSTM-based sequence model to predict next-month SST anomaly. 16 | 17 | ## 🚀 Usage 18 | ```bash 19 | git clone https://github.com/yourusername/Sea-Surface-Temperature-SST-Anomaly-Prediction.git 20 | cd Sea-Surface-Temperature-SST-Anomaly-Prediction 21 | pip install -r requirements.txt 22 | python main.py 23 | 24 | -------------------------------------------------------------------------------- /data_preprocessing.py: -------------------------------------------------------------------------------- 1 | # 🌊 Sea Surface Temperature (SST) Anomaly Prediction using LSTM 2 | 3 | import os 4 | import pandas as pd 5 | import numpy as np 6 | import matplotlib.pyplot as plt 7 | from sklearn.preprocessing import MinMaxScaler 8 | from sklearn.metrics import mean_squared_error 9 | from tensorflow.keras.models import Sequential 10 | from tensorflow.keras.layers import LSTM, Dense 11 | 12 | # ------------------ Load Dataset ------------------ 13 | def load_data(file_path): 14 | df = pd.read_csv(file_path, parse_dates=['date']) 15 | df.set_index('date', inplace=True) 16 | return df 17 | 18 | # ------------------ Preprocessing ------------------ 19 | def preprocess_data(df, look_back=12): 20 | scaler = MinMaxScaler() 21 | scaled_data = scaler.fit_transform(df) 22 | X, y = [], [] 23 | for i in range(len(scaled_data) - look_back): 24 | X.append(scaled_data[i:i+look_back]) 25 | y.append(scaled_data[i+look_back]) 26 | return np.array(X), np.array(y), scaler 27 | 28 | # ------------------ Model ------------------ 29 | def build_lstm_model(input_shape): 30 | model = Sequential() 31 | model.add(LSTM(64, input_shape=input_shape, return_sequences=False)) 32 | model.add(Dense(1)) 33 | model.compile(optimizer='adam', loss='mse') 34 | return model 35 | 36 | # ------------------ Plot ------------------ 37 | def plot_predictions(y_true, y_pred): 38 | plt.figure(figsize=(12, 6)) 39 | plt.plot(y_true, label="Actual SST") 40 | plt.plot(y_pred, label="Predicted SST") 41 | plt.title("Sea Surface Temperature Anomaly Prediction") 42 | plt.xlabel("Time Step") 43 | plt.ylabel("Normalized SST") 44 | plt.legend() 45 | plt.grid(True) 46 | plt.tight_layout() 47 | plt.show() 48 | 49 | # ------------------ Main ------------------ 50 | def main(): 51 | # Replace with your path to the dataset 52 | file_path = "sst_data.csv" 53 | if not os.path.exists(file_path): 54 | print("ERROR: File sst_data.csv not found.") 55 | return 56 | 57 | df = load_data(file_path) 58 | print("Dataset loaded successfully.") 59 | 60 | X, y, scaler = preprocess_data(df, look_back=12) 61 | print("Data preprocessing completed.") 62 | 63 | split = int(0.8 * len(X)) 64 | X_train, X_test = X[:split], X[split:] 65 | y_train, y_test = y[:split], y[split:] 66 | 67 | model = build_lstm_model(X_train.shape[1:]) 68 | model.summary() 69 | model.fit(X_train, y_train, epochs=50, batch_size=16, validation_split=0.1, verbose=1) 70 | 71 | y_pred = model.predict(X_test) 72 | mse = mean_squared_error(y_test, y_pred) 73 | print(f"Test MSE: {mse:.6f}") 74 | 75 | plot_predictions(y_test, y_pred) 76 | 77 | os.makedirs("models", exist_ok=True) 78 | model.save("models/lstm_sst_model.h5") 79 | print("Model saved to models/lstm_sst_model.h5") 80 | 81 | # ------------------ Entry Point ------------------ 82 | if __name__ == "__main__": 83 | main() 84 | 85 | --------------------------------------------------------------------------------