Skip to content

Instantly share code, notes, and snippets.

@7yl4r
Created August 18, 2025 21:12
Show Gist options
  • Save 7yl4r/b1c3e34d765b9656d4c3d094e3f4decb to your computer and use it in GitHub Desktop.
Save 7yl4r/b1c3e34d765b9656d4c3d094e3f4decb to your computer and use it in GitHub Desktop.
# analysis of west_of_canal and east_of_canal
import pandas as pd
import matplotlib.pyplot as plt
from pathlib import Path
# --- CONFIG ---
INDEX = "NDMoI"
files = {
"west" : f"RB_west_of_canal_l8.csv",
"east" : f"RB_east_of_canal_l8.csv",
}
date_col = "system:time_start"
# Colorblind-friendly choices (blue & orange)
colors = {
"west" : "#0072B2", # blue
"east" : "#E69F00", # orange
}
def makePlot(value_col):
plt.figure(figsize=(12, 6))
for label, fpath in files.items():
f = Path(fpath)
df = pd.read_csv(f, thousands=",")
# Parse and clean
df[date_col] = pd.to_datetime(df[date_col], errors="coerce")
df[value_col] = pd.to_numeric(df[value_col], errors="coerce")
df = df.dropna(subset=[date_col, value_col]).sort_values(date_col)
# Raw points
plt.plot(
df[date_col], df[value_col], "x",
alpha=1, color=colors[label], label=f"{label} raw"
)
# 1-month moving average
monthly = df.set_index(date_col)[value_col].resample("QS").mean() # QS = quarterly
ma = monthly.rolling(window=3).mean()
plt.plot(
ma.index, ma.values, "-",
linewidth=4, color=colors[label], label=f"{label} moving avg"
)
plt.title(f"Landsat {value_col} Time Series with 3-Month Moving Average")
plt.xlabel("Date")
plt.ylabel(value_col)
plt.legend()
plt.grid(True, linestyle="--", alpha=0.6)
plt.tight_layout()
plt.show()
makePlot("NDMoI")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment