2023-08-01 12:33:30 +05:00
|
|
|
import json
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import numpy, pandas
|
|
|
|
import requests
|
2024-04-02 11:42:23 +05:00
|
|
|
import sys
|
2023-08-01 12:33:30 +05:00
|
|
|
|
2023-08-28 13:37:46 +05:00
|
|
|
sst_urls = {
|
|
|
|
"world": "https://climatereanalyzer.org/clim/sst_daily/json/oisst2.1_world2_sst_day.json",
|
|
|
|
"natlan": "https://climatereanalyzer.org/clim/sst_daily/json/oisst2.1_natlan1_sst_day.json"
|
|
|
|
}
|
|
|
|
|
2024-04-02 11:42:23 +05:00
|
|
|
print(sys.argv[1])
|
2023-08-02 12:08:51 +05:00
|
|
|
start_range = 29
|
|
|
|
start_year = 1982
|
2024-04-02 11:42:23 +05:00
|
|
|
res = requests.get(sst_urls[list(sst_urls)[int(sys.argv[1])]])
|
2023-08-02 12:08:51 +05:00
|
|
|
data = json.loads(res.text)
|
|
|
|
data = data[1:-3]
|
2023-08-01 12:33:30 +05:00
|
|
|
|
2023-08-02 12:08:51 +05:00
|
|
|
temps = numpy.array([i['data'] for i in data], numpy.float32).T
|
|
|
|
cols = [i['name'] for i in data]
|
2023-08-01 12:33:30 +05:00
|
|
|
|
|
|
|
df = pandas.DataFrame(temps, columns = cols)
|
2023-08-28 13:37:46 +05:00
|
|
|
for col in cols:
|
|
|
|
if int(col) % 4 != 0:
|
|
|
|
df[col].iloc[60:] = df[col].iloc[60:].shift(1)
|
2023-08-02 12:08:51 +05:00
|
|
|
mean = df[df.columns[:start_range + 1]].mean(axis=1)
|
|
|
|
sd = df[df.columns[:start_range + 1]].std(axis=1)
|
|
|
|
diffs = pandas.DataFrame(columns = cols, dtype=numpy.float32)
|
|
|
|
for col in cols[start_range:]:
|
|
|
|
diffs[col] = (df[col] - mean) / sd
|
2023-08-28 13:37:46 +05:00
|
|
|
series = diffs.melt().drop('variable', axis=1).rename(columns={'value': f'sd ({start_year}-{start_year + start_range})'})
|
2023-08-01 12:33:30 +05:00
|
|
|
series.plot(figsize=(20,5))
|
2023-08-02 12:08:51 +05:00
|
|
|
plt.xticks(numpy.arange(0,len(series),366)[start_range+1:], (numpy.arange(0, len(series), 366)[start_range+1:] / 366 + start_year).astype(int)) # fix labels
|
2023-08-01 12:33:30 +05:00
|
|
|
plt.show()
|