Пример #1
0
from matplotlib import pyplot as plt
import mpl_toolkits.basemap as bm

import marineHeatWaves as mhw

import ecoliver as ecj

#
# observations
#

pathroot = '/data/home/oliver/'
header = pathroot + 'data/sst/noaa_oi_v2/avhrr/'
file0 = header + '1982/avhrr-only-v2.19820101.nc'
t, dates, T, year, month, day, doy = ecj.timevector([1982, 1, 1],
                                                    [2017, 12, 31])
tt_1982_2005 = year <= 2005
t, dates, T, year, month, day, doy = ecj.timevector([1982, 1, 1],
                                                    [2005, 12, 31])

#
# lat and lons of obs
#

fileobj = Dataset(file0, mode='r')
lon = fileobj.variables['lon'][:].astype(float)
lat = fileobj.variables['lat'][:].astype(float)
fill_value = fileobj.variables['sst']._FillValue.astype(float)
scale = fileobj.variables['sst'].scale_factor.astype(float)
offset = fileobj.variables['sst'].add_offset.astype(float)
fileobj.close()
Пример #2
0
        'IPSL-CM5A-MR', 'CanESM2'
]:
    if model == 'ACCESS1-3':
        header = [
            [
                pathroot +
                'data/CMIP5/CSIRO-BOM/ACCESS1-3/rcp45/day/ocean/day/r1i1p1/files/tos_20120413/'
            ],
            [
                pathroot +
                'data/CMIP5/CSIRO-BOM/ACCESS1-3/rcp85/day/ocean/day/r1i1p1/files/tos_20120413/'
            ]
        ]
        # Time and date vectors
        Ly = 365.25
        t, tmp, T, year, month, day, doy = ecj.timevector([2006, 1, 1],
                                                          [2100, 12, 31])
    elif model == 'CSIRO-Mk3-6-0':
        header = [
            [
                pathroot +
                'data/CMIP5/CSIRO-QCCCE/CSIRO-Mk3-6-0/rcp45/day/ocean/day/r1i1p1/v20111222/tos/',
                pathroot +
                'data/CMIP5/CSIRO-QCCCE/CSIRO-Mk3-6-0/rcp45/day/ocean/day/r2i1p1/v20111222/tos/',
                pathroot +
                'data/CMIP5/CSIRO-QCCCE/CSIRO-Mk3-6-0/rcp45/day/ocean/day/r3i1p1/v20111222/tos/',
                pathroot +
                'data/CMIP5/CSIRO-QCCCE/CSIRO-Mk3-6-0/rcp45/day/ocean/day/r4i1p1/v20111222/tos/',
                pathroot +
                'data/CMIP5/CSIRO-QCCCE/CSIRO-Mk3-6-0/rcp45/day/ocean/day/r5i1p1/v20111222/tos/',
                pathroot +
                'data/CMIP5/CSIRO-QCCCE/CSIRO-Mk3-6-0/rcp45/day/ocean/day/r6i1p1/v20111222/tos/',
Пример #3
0
lat_R1 = np.flipud(fileobj.variables['lat'][:])
fileobj.close()
modefile = '/home/ecoliver/Desktop/MHW/data/modes/PDO.nc'
fileobj = Dataset(modefile, mode='r')
PDO_R1 = np.flipud(fileobj.variables['skt'][0, :, :])
fileobj.close()
# Interpolate to SST grid and apply land mask
#AMO = datamask*interp.RectBivariateSpline(lon_R1, lat_R1, AMO_R1.T)(lon_map, lat_map).T
#PDO = datamask*interp.RectBivariateSpline(lon_R1, lat_R1, PDO_R1.T)(lon_map, lat_map).T

# Load time series

PDO_ts = np.genfromtxt('../../data/modes/pdo.ncdcnoaa.csv',
                       delimiter=',',
                       skip_header=2)[:, 1]
t_PDO, tmp, tmp, year_PDO, month_PDO, day_PDO, tmp = ecj.timevector(
    [1854, 1, 1], [2016, 12, 31])
t_PDO = t_PDO[day_PDO == 15]
dates_PDO = [date.fromordinal(t_PDO[tt]) for tt in range(len(t_PDO))]
Ny = 5  # Number of years over which to smooth index
PDO_ts = ecj.runavg(PDO_ts, 12 * Ny + 1)
PDO_ts = PDO_ts - PDO_ts.mean()
PDO_ts = signal.detrend(PDO_ts)

AMO_ts = np.genfromtxt('../../data/modes/amon.us.long.data',
                       skip_header=1,
                       skip_footer=4)[:-1, 1:].flatten()
t_AMO, tmp, tmp, year_AMO, month_AMO, day_AMO, tmp = ecj.timevector(
    [1856, 1, 1], [2016, 12, 31])
t_AMO = t_AMO[day_AMO == 15]
dates_AMO = [date.fromordinal(t_AMO[tt]) for tt in range(len(t_AMO))]
Ny = 5  # Number of years over which to smooth index
Пример #4
0
    site = locations['name'][n]
    #sst[site] = np.NaN*np.zeros((T,))
    print locations['name'][n]
    i = np.where(lon > locations['lon'][n])[0][0]
    j = np.where(lat > locations['lat'][n])[0][0]
    matobj = io.loadmat(header + 'timeseries/avhrr-only-v2.ts.' +
                        str(i + 1).zfill(4) + '.mat')
    sst[site] = matobj['sst_ts'][j, :]

#site = 'E_Tas'
site = 'WA'
site = 'Med'
site = 'NW_Atl'
site = 'Blob'

t_obs, dates_obs, T_obs, year_obs, month_obs, day_obs, doy_obs = ecj.timevector(
    [1982, 1, 1], [2016, 12, 31])
sst_obs = sst[site]  #np.loadtxt('data/sst_' + site + '.csv', delimiter=',')
mhws_obs, clim_obs = mhw.detect(t_obs, sst_obs)
mhwBlock_obs = mhw.blockAverage(t_obs, mhws_obs)
mean_obs, trend_obs, dtrend_obs = meanTrend_TS(
    mhwBlock_obs)  #mhw.meanTrend(mhwBlock_obs)

# SST trend

years = mhwBlock_obs['years_centre']
SST_block = np.zeros(years.shape)
for yr in range(len(years)):
    SST_block[yr] = np.mean(sst_obs[year_obs == years[yr]])
X = np.array([np.ones(years.shape), years - years.mean()]).T
beta = linalg.lstsq(X, SST_block)[0]
sst_trend_obs = beta[1] * 10
Пример #5
0
import trendSimAR1

import ecoliver as ecj

#
# observations
#

pathroot = '/mnt/erebor/'
pathroot = '/mnt/EREBOR/'
pathroot = '/mnt/tmp/'
#pathroot = '/bs/projects/geology/Oliver/'
#pathroot = '/home/ecoliver/Desktop/'
header = pathroot + 'data/sst/noaa_oi_v2/avhrr/'
file0 = header + '1982/avhrr-only-v2.19820101.nc'
t, dates, T, year, month, day, doy = ecj.timevector([1982, 1, 1],
                                                    [2017, 12, 31])

#
# lat and lons of obs
#

fileobj = Dataset(file0, mode='r')
lon = fileobj.variables['lon'][:].astype(float)
lat = fileobj.variables['lat'][:].astype(float)
fill_value = fileobj.variables['sst']._FillValue.astype(float)
scale = fileobj.variables['sst'].scale_factor.astype(float)
offset = fileobj.variables['sst'].add_offset.astype(float)
fileobj.close()

#
# Size of mhwBlock variable
Пример #6
0
    'data/CMIP5/CSIRO-BOM/ACCESS1-3/historicalNat/day/ocean/day/r2i1p1/files/tos_20130912/',
    pathroot +
    'data/CMIP5/CSIRO-BOM/ACCESS1-3/historicalNat/day/ocean/day/r3i1p1/files/tos_20140501/'
]
header[model]['rcp85'] = [
    pathroot +
    'data/CMIP5/CSIRO-BOM/ACCESS1-3/rcp85/day/ocean/day/r1i1p1/files/tos_20120413/'
]
header[model]['rcp45'] = [
    pathroot +
    'data/CMIP5/CSIRO-BOM/ACCESS1-3/rcp45/day/ocean/day/r1i1p1/v20120413/tos/'
]
# Time and date vectors
Ly[model] = 365.25
t[model]['hist'], tmp, T[model]['hist'], year[model]['hist'], month[model][
    'hist'], day[model]['hist'], doy[model]['hist'] = ecj.timevector(
        [1850, 1, 1], [2005, 12, 31])
t[model]['histNat'], tmp, T[model]['histNat'], year[model]['histNat'], month[
    model]['histNat'], day[model]['histNat'], doy[model][
        'histNat'] = ecj.timevector([1850, 1, 1], [2005, 12, 31])
t[model]['rcp85'], tmp, T[model]['rcp85'], year[model]['rcp85'], month[model][
    'rcp85'], day[model]['rcp85'], doy[model]['rcp85'] = ecj.timevector(
        [2006, 1, 1], [2100, 12, 31])
t[model]['rcp45'], tmp, T[model]['rcp45'], year[model]['rcp45'], month[model][
    'rcp45'], day[model]['rcp45'], doy[model]['rcp45'] = ecj.timevector(
        [2006, 1, 1], [2100, 12, 31])
for exp in experiments:
    years[model][exp] = np.unique(year[model][exp])
    Ty[model][exp] = len(years[model][exp])
# Kelvin -> Celcius (only not required for ACCESS hist ens > 0 and non RCP)
# ALL OTHER MODELS WILL NEED A -273.15 OFFSET FOR K->C
KelvinFix[model]['hist'] = [-273.15, 0., 0.]
Пример #7
0
# Load MITS
#

# BGC data
file = header + 'IMOS_NRSMAI/IMOS_NRSMAI_BGC_daily.mat'
matobj = io.loadmat(file)
t_temp = matobj['t_d'].flatten()
dates_temp = matobj['dates_d']
depth_temp = np.nanmean(matobj['depth_d'], axis=0)
temp = matobj['temp_d']
salt = matobj['salt_d']
dox1 = matobj['dox1_d']
dox2 = matobj['dox2_d']
cphl = matobj['cphl_d']
turb = matobj['turb_d']
t_temp, dates_temp, T_temp, year_temp, month_temp, day_temp, doy_temp = ecj.timevector([dates_temp[0,0], dates_temp[0,1], dates_temp[0,2]], [dates_temp[-1,0], dates_temp[-1,1], dates_temp[-1,2]])

# VEL data
file = header + 'IMOS_NRSMAI/IMOS_NRSMAI_VEL_daily_deTided.mat'
matobj = io.loadmat(file)
t_u = matobj['t_d'].flatten()
dates_u = matobj['dates_d']
depth_u = np.nanmean(matobj['depth_d'], axis=0)
u = matobj['u_d']
v = matobj['v_d']
t_u, dates_u, T_u, year_u, month_u, day_u, doy_u = ecj.timevector([dates_u[0,0], dates_u[0,1], dates_u[0,2]], [dates_u[-1,0], dates_u[-1,1], dates_u[-1,2]])

#
# Calculate deseasonalized data
#
Пример #8
0
 station = stations[i]
 if sw_write:
     outfile_train.write(station + ', ')
     outfile_valid.write(station + ', ')
 sst0 = np.genfromtxt(header + filenames[station],
                      delimiter=',',
                      skip_header=1)[:, 4]
 sst0[sst0 == 99.9] = np.nan
 datestring = np.genfromtxt(header + filenames[station],
                            delimiter=',',
                            skip_header=1,
                            dtype='S')[:, 0]
 yearStart = np.int(datestring[0][0:4])
 yearEnd = np.int(datestring[-1][0:4])
 # Flesh out full array based on dates
 t, dates, T, year, month, day, doy = ecj.timevector([yearStart, 1, 1],
                                                     [yearEnd, 12, 31])
 sst = np.nan * np.zeros(t.shape)
 for tt in range(len(sst0)):
     y = np.int(datestring[tt][0:4])
     m = np.int(datestring[tt][5:7])
     d = np.int(datestring[tt][8:10])
     sst[np.where(t == date(y, m, d).toordinal())[0][0]] = sst0[tt]
 #valid = np.where(~np.isnan(sst))[0]
 #tt0 = valid[0]
 #tt1 = valid[-1]
 #sst = sst[tt0:tt1+1]
 #t = t [tt0:tt1+1]
 if climPeriodFull:
     climPeriod = [yearStart + 1, yearEnd - 1]
 else:
     climPeriod = [1980, 2009]
 # Load in 1918-2008 data (daily)
 file = header + 'flode_daily_1918-2008.asc'
 dat = np.genfromtxt(file, delimiter=',')
 sst1 = dat[:,3]
 ymd1 = dat[:,0:3].astype(int)
 t1 = [date(ymd1[tt][0], ymd1[tt][1], ymd1[tt][2]).toordinal() for tt in range(len(sst1))]
 sst1[sst1==-99] = np.nan
 # Load in 2009-2016 data (hourly)
 file = header + 'flode_hourly_2009-today.asc'
 dat = np.genfromtxt(file, delimiter=',')
 sst2 = dat[:,4]
 ymd2 = dat[:,0:3].astype(int)
 t2 = [date(ymd2[tt][0], ymd2[tt][1], ymd2[tt][2]).toordinal() for tt in range(len(sst2))]
 sst2[sst2==-99] = np.nan
 # Flesh out full array based on dates (restrict to 1924-2016)
 t, dates, T, year, month, day, doy = ecj.timevector([1924,1,1], [2016,12,31])
 sst = np.zeros(t.shape)
 count = np.zeros(sst.shape)
 # Insert sst1
 for tt in range(len(sst1)):
     tmp = np.where(t == t1[tt])[0]
     if len(tmp) > 0:
         ttt = tmp[0]
         sst[ttt] += sst1[tt]
         count[ttt] += 1
 # Insert sst2
 for tt in range(len(sst2)):
     tmp = np.where(t == t2[tt])[0]
     if len(tmp) > 0:
         ttt = tmp[0]
         sst[ttt] += sst2[tt]
        'data/CMIP5/CSIRO-BOM/ACCESS1-3/historical/day/ocean/day/r2i1p1/files/tos_20121112/',
        pathroot +
        'data/CMIP5/CSIRO-BOM/ACCESS1-3/historical/day/ocean/day/r3i1p1/files/tos_20121112/'
    ],
    [
        pathroot +
        'data/CMIP5/CSIRO-BOM/ACCESS1-3/historicalNat/day/ocean/day/r1i1p1/files/tos_20130906/',
        pathroot +
        'data/CMIP5/CSIRO-BOM/ACCESS1-3/historicalNat/day/ocean/day/r2i1p1/files/tos_20130912/',
        pathroot +
        'data/CMIP5/CSIRO-BOM/ACCESS1-3/historicalNat/day/ocean/day/r3i1p1/files/tos_20140501/'
    ]
]
# Time and date vectors
Ly = 365.25
t, tmp, T, year, month, day, doy = ecj.timevector([1850, 1, 1], [2005, 12, 31])

# Model
model = 'CSIRO-Mk3-6-0'
header = [
    [
        pathroot +
        'data/CMIP5/CSIRO-QCCCE/CSIRO-Mk3-6-0/historical/day/ocean/day/r1i1p1/v20111222/tos/',
        pathroot +
        'data/CMIP5/CSIRO-QCCCE/CSIRO-Mk3-6-0/historical/day/ocean/day/r2i1p1/v20111222/tos/',
        pathroot +
        'data/CMIP5/CSIRO-QCCCE/CSIRO-Mk3-6-0/historical/day/ocean/day/r3i1p1/v20111222/tos/',
        pathroot +
        'data/CMIP5/CSIRO-QCCCE/CSIRO-Mk3-6-0/historical/day/ocean/day/r4i1p1/v20111222/tos/',
        pathroot +
        'data/CMIP5/CSIRO-QCCCE/CSIRO-Mk3-6-0/historical/day/ocean/day/r5i1p1/v20111222/tos/',
Пример #11
0
from scipy import signal
from datetime import date
from netCDF4 import Dataset

from matplotlib import pyplot as plt
import mpl_toolkits.basemap as bm

import marineHeatWaves as mhw
import trendSimAR1

import ecoliver as ecj

# Load MEI

MEI = np.genfromtxt('../../data/modes/mei.dat', skip_header=10)[:,1:].flatten()
t_mth, tmp, tmp, year_mth, month_mth, day_mth, tmp = ecj.timevector([1950, 1, 1], [2016, 12, 31])
t_mth = t_mth[day_mth==15]
dates_mth = [date.fromordinal(t_mth[tt]) for tt in range(len(t_mth))]
MEI = ecj.runavg(signal.detrend(MEI), 3)

# Find EN and LN periods
sc = 1. #0.75
EN = ecj.runavg(MEI>= sc*np.std(MEI), 3) > 0
LN = ecj.runavg(MEI<=-sc*np.std(MEI), 3) > 0

# Plot

plt.clf()
plt.fill_between(dates_mth, np.ones(MEI.shape), where=LN, color='b')
plt.fill_between(dates_mth, np.ones(MEI.shape), where=EN, color='r')
plt.xlim(date(1982,1,1).toordinal(), date(2017,1,1).toordinal())
# Load obs
#outfile = '/data/MHWs/Tasmania_2015_2016/NOAAOISST/mhw_SEAus_NOAAOISST_HadSST'
outfile = '/data/MHWs/Tasmania_2015_2016/NOAAOISST/' + str(
    locations['lon'][0]) + '_' + str(locations['lon'][1]) + '_' + str(
        locations['lat'][0]) + '_' + str(
            locations['lat'][1]) + '/mhw_SEAus_NOAAOISST_HadSST'
data = np.load(outfile + '.npz')
t_sst = data['t']
dates_sst = data['dates']
year_sst = data['year']
month_sst = data['month']
day_sst = data['day']

tt1 = np.where(t_sst == t[0])[0][0]
t_sst, dates_sst, T_sst, year_sst, month_sst, day_sst, doy_sst = ecj.timevector(
    [dates_sst[tt1].year, dates_sst[tt1].month, dates_sst[tt1].day],
    [dates_sst[-1].year, dates_sst[-1].month, dates_sst[-1].day])

sst = data['sst'][tt1:]
#sst_had = data['sst_had']
#sst_had_clim = data['sst_had_clim']
sst_ds = np.array(ds.deseason_harmonic(sst, 2, 365.25)[0])

#
# Plot some timeseries
#

plt.figure(figsize=(16, 8))

ts = date(2013, 1, 1).toordinal()
te = date(2016, 7, 1).toordinal()