-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New model: Multi quantile regression neural network (MQRNN)
- Loading branch information
1 parent
cd516dc
commit 6c4cb0c
Showing
11 changed files
with
889 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
""" | ||
The following script downloads all data that was relevant for my master thesis. | ||
""" | ||
|
||
from ninolearn.download import download, sources | ||
from ninolearn.utils import print_header | ||
|
||
print_header("Download Data") | ||
|
||
#%% | ||
# ============================================================================= | ||
# Single files | ||
# ============================================================================= | ||
download(sources.SST_ERSSTv5) | ||
download(sources.ONI) | ||
download(sources.NINOindices) | ||
download(sources.IOD) | ||
download(sources.OLR_NOAA) | ||
download(sources.WWV) | ||
download(sources.WWV_West) | ||
download(sources.UWIND_NCEP) | ||
download(sources.VWIND_NCEP) | ||
download(sources.otherForecasts) | ||
|
||
# ============================================================================= | ||
# Multiple files | ||
# ============================================================================= | ||
for i in range(1958, 2018): | ||
sources.ORAS4['filename'] = f'zos_oras4_1m_{i}_grid_1x1.nc' | ||
download(sources.ORAS4, outdir = 'ssh_oras4') | ||
|
||
for i in range(1980, 2019): | ||
#ssh | ||
sources.GODAS['filename'] = f'sshg.{i}.nc' | ||
download(sources.GODAS, outdir = 'sshg_godas') | ||
|
||
#u-current | ||
sources.GODAS['filename'] = f'ucur.{i}.nc' | ||
download(sources.GODAS, outdir = 'ucur_godas') | ||
|
||
#v-current | ||
sources.GODAS['filename'] = f'vcur.{i}.nc' | ||
download(sources.GODAS, outdir = 'vcur_godas') | ||
|
||
for year_int in range(1948, 2019): | ||
year_str = str(year_int) | ||
sources.SAT_daily_NCEP['filename'] = 'air.sig995.%s.nc' % year_str | ||
download(sources.SAT_daily_NCEP, outdir='sat') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
""" | ||
The downloaded data needed to be prepared to have the similiar time-axis. | ||
All spatial data is regridded to the 2.5x2.5 grid of the NCEP | ||
reanalysis data. | ||
Some variables are computed, i.e the wind stress field, the wind speed and | ||
the warm pool edge. | ||
""" | ||
import numpy as np | ||
|
||
from ninolearn.utils import print_header | ||
from ninolearn.preprocess.prepare import prep_oni, prep_nino_month, prep_wwv | ||
from ninolearn.preprocess.prepare import prep_iod, prep_K_index, prep_wwv_proxy | ||
from ninolearn.preprocess.prepare import calc_warm_pool_edge, prep_other_forecasts | ||
|
||
print_header("Prepare Data") | ||
|
||
# ============================================================================= | ||
# Prepare the incedes | ||
# ============================================================================= | ||
prep_oni() | ||
prep_nino_month(index="3.4") | ||
prep_nino_month(index="3") | ||
prep_nino_month(index="1+2") | ||
prep_nino_month(index="4") | ||
prep_wwv() | ||
prep_wwv(cardinal_direction="west") | ||
prep_iod() | ||
prep_K_index() | ||
prep_wwv_proxy() | ||
|
||
# ============================================================================= | ||
# Prepare the gridded data | ||
# ============================================================================= | ||
from ninolearn.IO import read_raw | ||
from ninolearn.preprocess.anomaly import postprocess, saveAnomaly | ||
from ninolearn.preprocess.regrid import to2_5x2_5 | ||
|
||
# postprocess sst data from ERSSTv5 | ||
sst_ERSSTv5 = read_raw.sst_ERSSTv5() | ||
sst_ERSSTv5_regrid = to2_5x2_5(sst_ERSSTv5) | ||
postprocess(sst_ERSSTv5_regrid) | ||
|
||
# NCEP reanalysis | ||
uwind = read_raw.uwind() | ||
postprocess(uwind) | ||
|
||
vwind = read_raw.vwind() | ||
postprocess(vwind) | ||
|
||
# post process values from ORAS4 ssh | ||
ssh_oras4 = read_raw.oras4() | ||
ssh_oras4_regrid = to2_5x2_5(ssh_oras4) | ||
postprocess(ssh_oras4_regrid) | ||
|
||
# OLR | ||
olr_ncar = read_raw.olr() | ||
olr_ncar_regrid = to2_5x2_5(olr_ncar) | ||
postprocess(olr_ncar_regrid) | ||
|
||
# ============================================================================= | ||
# Calculate some variables | ||
# ============================================================================= | ||
wspd = np.sqrt(uwind**2 + vwind**2) | ||
wspd.attrs = uwind.attrs.copy() | ||
wspd.name = 'wspd' | ||
wspd.attrs['long_name'] = 'Monthly Mean Wind Speed at sigma level 0.995' | ||
wspd.attrs['var_desc'] = 'wind-speed' | ||
postprocess(wspd) | ||
|
||
taux = uwind * wspd | ||
taux.attrs = uwind.attrs.copy() | ||
taux.name = 'taux' | ||
taux.attrs['long_name'] = 'Monthly Mean Zonal Wind Stress at sigma level 0.995' | ||
taux.attrs['var_desc'] = 'x-wind-stress' | ||
taux.attrs['units'] = 'm^2/s^2' | ||
postprocess(taux) | ||
|
||
tauy = vwind * wspd | ||
tauy.attrs = uwind.attrs.copy() | ||
tauy.name = 'tauy' | ||
tauy.attrs['long_name'] = 'Monthly Mean Meridional Wind Stress at sigma level 0.995' | ||
tauy.attrs['var_desc'] = 'y-wind-stress' | ||
tauy.attrs['units'] = 'm^2/s^2' | ||
postprocess(tauy) | ||
|
||
# ============================================================================= | ||
# Postprocessing based on already postprocessd data | ||
# ============================================================================= | ||
calc_warm_pool_edge() | ||
|
||
# ============================================================================= | ||
# Prepare the other forecasts | ||
# ============================================================================= | ||
prep_other_forecasts() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from ninolearn.preprocess.pca import pca | ||
from ninolearn.IO.read_processed import data_reader | ||
import matplotlib.pyplot as plt | ||
|
||
plt.close("all") | ||
|
||
# ============================================================================= | ||
# Decadel PCAs | ||
# ============================================================================= | ||
|
||
|
||
reader = data_reader(startdate='1955-01', enddate='2018-12',lon_min=120, lon_max=300) | ||
sst = reader.read_netcdf('sst', dataset='ERSSTv5', processed='anom') | ||
|
||
sst_decadel = sst.rolling(time=60, center=False).mean() | ||
sst_decadel.attrs = sst.attrs.copy() | ||
sst_decadel.name = f'dec_{sst.name}' | ||
|
||
pca_sst_decadel = pca(n_components=6) | ||
|
||
pca_sst_decadel.set_eof_array(sst_decadel) | ||
pca_sst_decadel.compute_pca() | ||
pca_sst_decadel.plot_eof() | ||
pca_sst_decadel.save(extension='.csv', filename='dec_sst_ERSSTv5_anom') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from ninolearn.utils import print_header | ||
from ninolearn.preprocess.network import networkMetricsSeries | ||
|
||
print_header("Network Metrics") | ||
# | ||
#nms_ssh_godas = networkMetricsSeries('sshg', 'GODAS', processed="anom", | ||
# threshold=0.9, startyear=1980, endyear=2018, | ||
# window_size=12, lon_min=120, lon_max=280, | ||
# lat_min=-30, lat_max=30, verbose=1) | ||
#nms_ssh_godas.computeTimeSeries() | ||
|
||
nms_ssh_oras4 = networkMetricsSeries('zos', 'ORAS4', processed="anom", | ||
threshold=0.9, startyear=1959, endyear=2017, | ||
window_size=12, lon_min=120, lon_max=280, | ||
lat_min=-30, lat_max=30, verbose=1) | ||
nms_ssh_oras4.computeTimeSeries() |
Oops, something went wrong.