From 2b20519dbb35aa2105e564122c926229a0966afe Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Tue, 1 Aug 2023 12:33:30 +0500 Subject: [PATCH] Arctic sea surface temp anomaly visualization --- python_scripts/arc_sst_anom.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 python_scripts/arc_sst_anom.py diff --git a/python_scripts/arc_sst_anom.py b/python_scripts/arc_sst_anom.py new file mode 100644 index 0000000..8a8b40e --- /dev/null +++ b/python_scripts/arc_sst_anom.py @@ -0,0 +1,24 @@ +import json +import matplotlib.pyplot as plt +import numpy, pandas +import requests + +res = requests.get('https://climatereanalyzer.org/clim/sst_daily/json/oisst2.1_world2_sst_day.json') +if res.status_code == 200: + data = json.loads(res.text) + +data = data[:-3] # remove final three cols (avg and sds) + +temps = numpy.array([i['data'] for i in data], numpy.float32).T +cols = [i['name'] for i in data] + +df = pandas.DataFrame(temps, columns = cols) +diffs = pandas.DataFrame(columns = cols, dtype=numpy.float32) +for col in cols[20:]: + i = cols.index(col) + means = df[df.columns[0:20]].mean(axis=1) # 1981 - 2001 mean sst + diffs[col] = df[col] - means +series = diffs.melt().drop('variable', axis=1) +series.plot(figsize=(20,5)) +plt.xticks(numpy.arange(0,len(series),366)[20:], (numpy.arange(0, len(series), 366)[20:] / 366 + 1981).astype(int)) +plt.show()