cleanup
This commit is contained in:
parent
8a261f8174
commit
b96f6de4ed
1 changed files with 10 additions and 5 deletions
|
@ -3,9 +3,14 @@ import matplotlib.pyplot as plt
|
|||
import numpy, pandas
|
||||
import requests
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
start_range = 29
|
||||
start_year = 1982
|
||||
res = requests.get('https://climatereanalyzer.org/clim/sst_daily/json/oisst2.1_natlan1_sst_day.json')
|
||||
res = requests.get(sst_urls['world'])
|
||||
data = json.loads(res.text)
|
||||
data = data[1:-3]
|
||||
|
||||
|
@ -13,15 +18,15 @@ 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)
|
||||
for col in cols:
|
||||
if int(col) % 4 != 0:
|
||||
df[col].iloc[60:] = df[col].iloc[60:].shift(1)
|
||||
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:]:
|
||||
if int(col) % 4 != 0:
|
||||
df[col].iloc[60:] = df[col].iloc[60:].shift(1)
|
||||
i = cols.index(col)
|
||||
diffs[col] = (df[col] - mean) / sd
|
||||
series = diffs.melt().drop('variable', axis=1)
|
||||
series = diffs.melt().drop('variable', axis=1).rename(columns={'value': f'sd ({start_year}-{start_year + start_range})'})
|
||||
series.plot(figsize=(20,5))
|
||||
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
|
||||
plt.show()
|
||||
|
|
Loading…
Reference in a new issue