""" Created on Wed Apr 22 10:02:45 2020 @author: josmarti """ import matplotlib.pyplot as plt import cartopy.crs as ccrs import rms_plots as rpl import nc as nc import numpy as np import re #import cdo; c=cdo.Cdo() syear=1980; eyear=1995 obsin=nc.getvar('/home/josmarti/Data/Observations/NSIDC_1979_2010_nh_siea.nc', 'sia').squeeze() start=(1990-1979)*12; end=start+12 mean_obs=np.mean(np.reshape(obsin[((1980-1979)*12):((1995-1979)*12)],(15,12)).transpose(), axis=1) gridpoint=nc.getvar('/home/josmarti/Data/areacella_fx_CanCM4_decadal2001_r0i0p0.nc','areacella') PIOMAS=np.loadtxt('/home/josmarti/Data/Observations/PIOMAS_SIV_monthly_1979-2020.txt',usecols=range(1,13)) mean_obs=np.mean(PIOMAS[(syear-1979):(eyear-1979)], axis=0) years=[2312, 2435, 2413, 2356, 2387, 2332] ensembles=["%03d" % i for i in range(1,13)] #ensembles=["001"] run_length=1 #years daily_matrix=np.zeros((6,12,1095)) days=365*3 for e in ensembles:
#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Sat Oct 3 13:56:25 2020 @author: josmarti """ import sys sys.path.append('/HOME/rms/PMODS') import os as os import nc as nc import numpy as np import matplotlib.pyplot as plt from scipy import signal os.system('cdo selmon,3 ~/Data/Observations/had2cis_1x1_198001_202004_sicn.nc ./tmp1.nc') os.system('cdo remapbil,1x1_reg_mask.nc tmp1.nc tmp2.nc') #regrid os.system('cdo -gtc,0.15 tmp2.nc tmp3.nc') # SIE mask: 1's where sic>0.15, 0 elsewhere os.system('cdo -setctomiss,0 -eqc,1 1x1_reg_mask.nc 1centralarctic.nc') # create central arctic mask os.system('cdo mul 1centralarctic.nc tmp3.nc tmp4.nc') # mask out everything outside central Arctic os.system('cdo -fldmean -sellonlatbox,0,360,0,90 tmp4.nc tmp5.nc') # Average fraction per km^2 in NH SIE_im03_ca=nc.getvar('tmp5.nc','SICN').squeeze()*2*np.pi*6371.*6371./1e6 plt.plot(signal.detrend(SIE_im03_ca)) print np.std(signal.detrend(SIE_im03_ca))
import cartopy.crs as ccrs import rms_plots as rpl import numpy as np import numpy.ma as ma import nc as nc import matplotlib as mpl #from netCDF4 import Dataset clevslab = np.arange(16) - 1 #from rms_plots.py r = 0 jet3 = colors.ListedColormap( loadmat('/home/josmarti/Downloads/cmap_jet3.mat')['cmap'], name='jet3') ####### read data infile = '/home/josmarti/Data/reg_grid_iceregions.nc' lsmask = nc.getvar('/home/josmarti/Data/lsmask_cansipsv2_sea.nc', 'LSMASK') #infile ='/home/josmarti/Data/Observations/had2cis_1x1_198001_202004_sicn.nc' #infile ='/home/josmarti/Data/sic_monthly_CCCma-CanCM4_NEW_1x1_grid_i20171201.nc' #infile = '/home/josmarti/Data/Observations/had2cis_1x1_198001_202004_sicn.nc' #data=Dataset(infile) #data.set_auto_mask(False) lon = nc.getvar(infile, 'lon').squeeze() lat = nc.getvar(infile, 'lat').squeeze() region = nc.getvar(infile, 'region').squeeze() #skill=np.load('/home/josmarti/Data/GeoACC_NEW.npy', allow_pickle=True).astype(float) #mask=nc.getvar('/home/josmarti/Data/1x1_reg_mask.nc', 'region').squeeze() #mask[mask != ]=0 #region=nc.getvar('/home/josmarti/Data/lsmask_cansipsv2_sea.nc', 'LSMASK') #landsea mask troubleshooting regionlabs = [ '0land', '1ARC', '2GIN', '3BAR', '4KAR', '5LAP', '6ESI', '7CHU', '8BER',
import calendar import rms_utils_boot as bt import CCMA_plot from scipy.io import loadmat import math as math years = range(1979, 2011) monthly_matrix = np.zeros(((10 * (max(years) + 1 - min(years))), 12)) model = np.zeros(((10 * (max(years) + 1 - min(years))), 12)) control = np.zeros((12, max(years) + 1 - min(years))) ACC = np.zeros(12, dtype=np.ndarray) for y in years: for i in range(1, 11): monthly_matrix[((y - min(years)) * 10 + (i - 1)), :] = nc.getvar(( '/home/josmarti/Data/APPOSITE/pred/Jul/SIE/SIE_Omon_pred_%iJul%i.nc' % (y, i)), 'sic').squeeze() * 2 * math.pi * 6.371**2 for k in years: control[:, k - min(years)] = nc.getvar( ('/home/josmarti/Data/APPOSITE/ctrl/sie_Omon_ctrl_%i.nc' % k), 'sic').squeeze() * 2 * math.pi * 6.371**2 clim_mean = np.mean(control, axis=1) #%% for y in range(len(years)): for e in range(10): model[(y * 10 + e), :] = np.mean(np.delete( monthly_matrix[y * 10:y * 10 + 10, :], e, axis=0), axis=0)
@author: Joseph Martin, University of Victoria (edited by Michael Sigmond) """ from netCDF4 import Dataset import math as math import nc as nc import numpy as np import array as ar import matplotlib.colors import matplotlib.pyplot as plt import pandas as pd import calendar basedir = '/home/josmarti/Data/SIE' obsin = nc.getvar( '/home/josmarti/Data/Observations/NSIDC_1979_2010_nh_siea.nc', 'sie').squeeze() sim = np.zeros((12, 12, 31)) #Shape observations obs = np.reshape(obsin, (32, 12)).transpose() #Build model array for months in range(1, 13): if months < 10: m = "0%s" % months else: m = str(months) for years in range(1979, 2009 + 1): y = str(years)
""" import nc as nc import matplotlib.pyplot as plt import numpy as np import pandas as pd #regionlabs=['0land','1ARC','2GIN','3BAR','4KAR','5LAP','6ESI','7CHU','8BER','9OKH','10BEA','11CAN','12HUD','13BAF','14LAB','15OTHER'] region = "3BAR" if region[1].isdigit(): r = int(region[0:2]) else: r = int(region[0]) mask = nc.getvar('/home/josmarti/Data/iceregions_128_64.nc', 'REG').squeeze() mask[mask != float(r)] = 0 mask[mask == float(r)] = 1 years = range(2300, 2449) siv = pd.DataFrame(0, index=range(12), columns=years) gridpoint = nc.getvar( '/home/josmarti/Data/areacella_fx_CanCM4_decadal2001_r0i0p0.nc', 'areacella') for year in years: var = nc.getvar(( '/home/josmarti/Data/CanCM4_control/sc_dhfp1e_e001_%s_m01_%s_m12_sic.nc' % (year, year)), 'sic').squeeze() sit = var / 913.0 #SIT=SIC/913 kg/m3
obsin[obsin == -9999] = np.nan if metric == 'SIA': for m in ["%02d" % i for i in range(1, 13)]: obsin[int(m) - 1, :] = np.loadtxt( '/home/josmarti/Data/Observations/NSIDC/north/N_%s_extent_v3.0.csv' % m, usecols=5, skiprows=1, delimiter=',', max_rows=40) obsin[obsin == -9999] = np.nan mean_obs = np.nanmean(obsin[:, (syear - 1979):(eyear - 1979)], axis=1) * 1e12 annual_mean_obs = np.nanmean(obsin[:, (syear - 1979):(eyear - 1979)], axis=0) * 1e12 gridpoint = nc.getvar( '/home/josmarti/Data/areacella_fx_CanCM4_decadal2001_r0i0p0.nc', 'areacella') PIOMAS = np.loadtxt( '/home/josmarti/Data/Observations/PIOMAS_SIV_monthly_1979-2020.txt', usecols=range(1, 13)) if metric == 'SIV': mean_obs = np.mean(PIOMAS[(syear - 1979):(eyear - 1979)], axis=0) * 1e12 years = [2312, 2435, 2413, 2356, 2387, 2332] ensembles = ["%03d" % i for i in range(1, 13)] #ensembles=["001"] run_length = 1 #years daily_matrix = np.zeros((6, 12, 1095)) days = 365 * 3
'Pan-Arctic', 'Central Arctic', 'GIN Seas', 'Barents Sea', 'Kara Sea', 'Laptev Sea', 'East Siberian Sea', 'Chukchi Sea', 'Bering Sea', 'Sea of Okhotsk', 'Beaufort Sea', 'Canadian Archipelago', 'Hudson Bay', 'Baffin Bay', 'Labrador Sea' ] #regionlabs=['0land','1ARC','2GIN','3BAR','4KAR','5LAP','6ESI','7CHU','8BER','9OKH','10BEA','11CAN','12HUD','13BAF','14LAB','15OTHER'] region = "0NONE" if region[1].isdigit(): r = int(region[0:2]) else: r = int(region[0]) std_mask = True if std_mask: mask = nc.getvar('/home/josmarti/Data/1x1_reg_mask.nc', 'region').squeeze() gridpoint = nc.getvar('/home/josmarti/Data/gridpoint_1x1.nc', 'areacella') mask[mask != r] = 0 mask[mask == r] = 1 area = np.sum(np.multiply(gridpoint, mask)) #%% cyears = range(2300, 2449) control = np.zeros((12, len(cyears))) if r != 0: for year in cyears: control[:, cyears.index(year)] = nc.getvar(( '/home/josmarti/Data/CanCM4_control/SIE/%s/sc_dhfp1e_e001_%s_%i_SIE.nc' % (region, region, year)), 'sicn').squeeze() * 2 * math.pi * 6.371**2 else:
## ## AUTHOR: Michael Sigmond (CCCma) ## ## INPUT ##################################################### import numpy as np import cdo#; cdo = cdo.Cdo() import matplotlib.pyplot as plt # for basic plotting import rms_plots as rpl import nc as nc ############################################################################### #######READ########## ######################################################### ############################################################################### infile = '/home/josmarti/Data/iceregions_128_64.nc' lon=nc.getvar(infile,'lon') lat=nc.getvar(infile,'lat') region=nc.getvar(infile,'REG').squeeze() regionlabs=['-1ocean','0land','1ARC','2BER','3STL','4BAF','5GRE','6BAR','7KAR','8LAP','9ESI','10CHU','11BEA','12CAN','13HUD','14OKH'] ############################################################################### #######PLOT#################################################################### ############################################################################### ###colors#################################################################### clevs=np.arange(17)-1.5 clevslab=np.arange(17)-1 full_cmap = plt.get_cmap('jet') colors=full_cmap([0,20,40,60,80,100,110,120,130,140,160,180,200,220,240,255]) ####open figs#################################################################### ncol=1; nrow=1; fig, axs = plt.subplots(nrow,ncol); fig.set_size_inches(ncol*2,nrow*2.75)
if r != 0: """obsingeo=nc.getvar('/home/josmarti/Data/Observations/had2cis_1x1_198001_202004_sicn.nc', 'SICN').squeeze() #obsingeo[obsingeo.mask==True]=1 #CHECK WITH MICHAEL!!!!!! if metric=="SIE": obsingeo[obsingeo <= 0.15] = 0 obsingeo[obsingeo > 0.15] = 1 mask=nc.getvar('/home/josmarti/Data/1x1_reg_mask.nc', 'region').squeeze() gridpoint=nc.getvar('/home/josmarti/Data/gridpoint_1x1.nc','areacella') mask[mask != r]=0 mask[mask == r]=1 obs1=np.multiply(obsingeo.astype(float),mask.astype(float)) #changes to dtype=float64 to avoid run time error #obs2=obs1 #Select Northern Hemisphere obsnh=np.multiply(obs1,gridpoint.astype(float)) obstemp=np.sum(np.sum((obsnh/(1e6*2.8**2)), axis=1), axis=1) #CHANGED FROM MEAN""" obsin = nc.getvar( ('/home/josmarti/Data/Observations/Observed_SIE_%i.nc' % r), 'SICN').squeeze() * 2 * math.pi * 6.371**2 #obsin=mitch['regionalSIE'][0:456,(r-1)] obs2mask = obsin[((min(years) - 1980) * 12):((max(years) + 2 - 1980) * 12)] obs = np.reshape(obs2mask, ((period + 2), 12)).transpose() else: obsingeo = np.delete( nc.getvar( '/home/josmarti/Data/Observations/had2cis_128_64_195901_202004_sic.nc', 'SICN').squeeze(), 128, 2) gridpoint = nc.getvar( '/home/josmarti/Data/areacella_fx_CanCM4_decadal2001_r0i0p0.nc', 'areacella') obs1 = np.multiply(obsingeo, gridpoint) obsnh = np.delete(obs1, range(32), axis=1) obstemp = np.mean(np.mean(obsnh, axis=1), axis=1)