pcpib = ffib.variables['pcp'][:] lons = ffib.variables['longitude'][:] lats = ffib.variables['latitude'][:] cdaysib = ffib.getncattr( 'contributing_days' ) #contributing days is a global attribute rather than a variable fftr = Dataset(infiletr, 'r') pcptr = fftr.variables['pcp'][:] cdaystr = fftr.getncattr( 'contributing_days' ) #contributing days is a global attribute rather than a variable print cdaystr print np.max(pcpib) print np.max(pcptr) perc_cont = np.zeros_like(pcptr) perc_cont[:, :] = np.nan perc_cont = (pcpib / pcptr) * 100. print np.nanmax(perc_cont) label = " " #""TC contribution to precipitation (%) " + str(y1) + "-" + str(y2) bounds = np.linspace(0, 100, 11) pl.map_composite_data(perc_cont, lats, lons, outfile, "SIO2", 'BuPu', label, bounds, 'perc') np.savetxt(datadirib + outfile_data, perc_cont, '%.4f')
print 'here' pcp_sum_dict[res] = pcp_tot cdays_sum_dict[res] = cdays lons_overall_dict[res] = lons lats_overall_dict[res] = lats #print pcp_sum_dict pcp=np.zeros((xr,yr)) for x in range(xr): for y in range(yr): pcp[x,y] = pcp_tot[x,y]/cdays #divide the precip total by the number of days print np.max(pcp) label = res #""TRMM precipitation (mm/day) " + str(y1) + "-" + str(y2) bounds = np.linspace(0, 16, 9) pl.map_composite_data(pcp, lats, lons, outfile, "SIO2", 'Blues', label, bounds) if lt == 6: continue else: infile = datadir + str(lt) + "/ukmo_nwp.comp_pcp_total."+str(lt)+"-days.2009-2010.n320.nc" print infile outfile = "ukmo_nwp.comp_pcp_total."+str(lt)+"-days.2009-2010.n320_mmday.png" ff = Dataset(infile, 'r') lons = ff.variables['longitude'][:] lats = ff.variables['latitude'][:] cdays = ff.getncattr('contributing_days') # contributing days is a global attribute rather than a variable pcp_tot = ff.variables['unknown'][:] print pcp_tot pcp_sum_dict['n320'] += pcp_tot cdays_sum_dict['n320'] += cdays
infile = datadir + "analysis.comp_pcp_tc.201903_idai.nc" # infile = datadir + "2019/analysis.comp_pcp_tc.201903.nc" print infile outfile = "analysis.gpm_imerg.comp_pcp_tc.idai.png" ff = Dataset(infile, 'r') pcp = ff.variables['pcp'][:] lons = ff.variables['lon'][:] #lons = lons + 180 lats = ff.variables['lat'][:] cdays = ff.getncattr( 'contributing_days' ) # contributing days is a global attribute rather than a variable print cdays pcp_new = np.zeros((1800, 3600)) for x in range(3600): for y in range(1800): pcp_new[y, x] = pcp[ x, y] # /cdays #divide the precip total by the number of days print pcp_new print np.max(pcp_new) label = " " # ""TC-related precipitation (mm) " + str(y1) + "-" + str(y2) bounds = np.linspace(0, 1000, 11) pl.map_composite_data(pcp_new, lats, lons, outfile, "SIO2", 'Blues', label, bounds) #
print np.nanmax(trmmpcp) print np.nanmax(dens_sum_an) trmm_obs_precip_per_tc_mmper6h = trmmpcp / dens_sum_an trmm_obs_precip_per_tc_mmph = trmm_obs_precip_per_tc_mmper6h / 6 print np.nanmax(trmm_obs_precip_per_tc_mmper6h) print np.nanmax(trmm_obs_precip_per_tc_mmph) bounds1 = np.linspace(0, 50, 11) label1=' ' outfile = "trmm_pcp_per_tc.analysis_tracks.mmph_2006-2016.png" pl.map_composite_data(trmm_obs_precip_per_tc_mmph, lats, lons, outfile, "SIO3", 'Purples', label1, bounds1,"contour") #get the forecast track density for the whole period, for each lead time (saved as yearly files) fcst_dens_sum = np.zeros((7,72,144)) #lead time, lat, lon for lt in [0,1,2,3,4,5,6]: for y1, y2 in zip(year1s, year2s): densfile = ukmodensdir + str(lt) + "/" + str(y1)+str(y2) + "/ukmo_nwp.density.lt"+str(lt)+"_days."+str(y1)+str(y2)+".nc" ffdens = Dataset(densfile,'r') dens = ffdens.variables['density'][:] fcst_dens_sum[lt,:,:] += dens[:,:] print fcst_dens_sum
#avgtotpcp = totalpcp / 10 ff20182019 = Dataset(file20182019, 'r') pcp20182019 = ff20182019.variables['pcp'][:] print np.shape(pcp20182019) pcp20182019_new = np.zeros((481, 640)) for x in range(640): for y in range(481): pcp20182019_new[y, x] = pcp20182019[x, y] cdays20182019 = ff20182019.getncattr('contributing_days') pcp20182019_mm = pcp20182019_new / cdays20182019 #bias = avgtotpcp - pcp20182019_new pcp20182019_ma = np.ma.masked_where(pcp20182019_new == 0, pcp20182019_new) totalpcp_ma = np.ma.masked_where(totalpcp == 0, totalpcp) bias = pcp20182019_ma - (totalpcp_ma / 10) perc = (bias / (totalpcp_ma / 10)) * 100 print bias label3 = " " #""UKMO - TRMM precipitation bias (mm/day) " + res + " " + str(lt) + " days lead time" bounds3 = np.linspace(-100, 100, 21) pl.map_composite_data(perc, lats, lons, outfile_bias, "SIO2", 'RdBu', label3, bounds3, 'bias')
bias = ecpcp_mmday - gpmpcp_mmday print "bias max: ", np.nanmax(bias) print "bias min: ", np.nanmin(bias) #print ecpcp #print gpmpcp_mmday #print bias label1 = " " #""UKMO precipitation (mm/day) "+res+" "+str(lt)+" days lead time" label2 = " " #""TRMM precipitation (mm/day) "+res label3 = " " #""UKMO - TRMM precipitation bias (mm/day) " + res + " " + str(lt) + " days lead time" bounds1 = np.linspace(0, 60, 7) bounds3 = np.linspace(-30, 30, 7) pl.map_composite_data(ecpcp_mmday, lats, lons, outfile_ec, "SIO2", 'Purples', label1, bounds1) pl.map_composite_data(gpmpcp_mmday, lats, lons, outfile_gpm, "SIO2", 'Purples', label2, bounds1) pl.map_composite_data(bias, lats, lons, outfile_bias, "SIO2", 'RdBu', label3, bounds3, 'bias') #AND THEN FOR SUM, RATHER THAN MM/DAY: ecfilesum = ecdir + "/idai_precip_sum_mm_ensmean_lt_" + str(lt) + "days.nc" ffecsum = Dataset(ecfilesum, 'r') ecpcpsum = ffecsum.variables['tc_precip'][:] print np.nanmax(ecpcpsum) biassum = ecpcpsum - gpmpcp
cdaystrmm = fftrmm.getncattr('contributing_days') trmmpcp_mm = trmmpcp / cdaystrmm bias = ukmopcp_mm - trmmpcp_mm print ukmopcp_mm print trmmpcp_mm print bias label1 = " " #""UKMO precipitation (mm/day) "+res+" "+str(lt)+" days lead time" label2 = " " #""TRMM precipitation (mm/day) "+res label3 = " " #""UKMO - TRMM precipitation bias (mm/day) " + res + " " + str(lt) + " days lead time" bounds1 = np.linspace(0, 2, 9) bounds3 = np.linspace(-1.5, 1.5, 7) pl.map_composite_data(ukmopcp_mm, lats, lons, outfile_ukmo, "SIO2", 'Blues', label1, bounds1) pl.map_composite_data(trmmpcp_mm, lats, lons, outfile_trmm, "SIO2", 'Blues', label2, bounds1) pl.map_composite_data(bias, lats, lons, outfile_bias, "SIO2", 'RdBu', label3, bounds3, 'bias') #here, add the composites for the total across the entire period, once remapping is finished #here, add the composites for the total across the entire period, once remapping is finished for lt in [0, 1, 2, 3, 4, 5, 6]: ukmofile = ukmodir + str(lt) + "/ukmo_nwp.comp_pcp_tc." + str( lt) + "_days.072006-122016.n320.nc" trmmfile = trmmdir + "trmm.comp_pcp_tc.072006-122016_n320.nc" outfile_ukmo = "ukmo_nwp.comp_pcp_tc.072006-122016.n320." + str( lt) + "-days.png" outfile_trmm = "trmm.comp_pcp_tc.072006-1220160.n320.png"
trmm_data=np.genfromtxt(trmmfile) bias = ukmo_data - trmm_data print ukmo_data print trmm_data print bias label = " "#""UKMO - TRMM precipitation bias (mm/day) " + res + " " + str(lt) + " days lead time" bounds = np.linspace(-25, 25, 11) #pl.map_composite_data(bias, lats, lons, outfile_bias, "SIO2", 'PuOr', label, bounds,'bias') for season in ['DJFM','NDJFMA','MJJASO']: ukmofile = ukmodir + str(lt) + "/ukmo_nwp.perc_cont_tc_rainfall."+str(lt)+"-days.072006-122016"+season+".n320.txt" trmmfile = trmmdir + "trmm_ibtracs.perc_cont_tc_rainfall.072006-122016."+season+"_n320.txt" outfile_bias = "ukmo_bias.perc_cont_tc_rainfall.072006-122016."+str(lt)+"-days."+season+".n320.png" lonlatfile = trmmdir+"trmm.comp_pcp_tc.072006-122016_n320.nc" fflatlon = Dataset(lonlatfile, 'r') lons = fflatlon.variables['longitude'][:] lats = fflatlon.variables['latitude'][:] ukmo_data = np.genfromtxt(ukmofile) trmm_data = np.genfromtxt(trmmfile) bias = ukmo_data - trmm_data label = " " # ""UKMO - TRMM precipitation bias (mm/day) " + res + " " + str(lt) + " days lead time" bounds = np.linspace(-25, 25, 11) pl.map_composite_data(bias, lats, lons, outfile_bias, "SIO2", 'PuOr', label, bounds, 'bias')
#pl.map_composite_data(dens, lats,lons, outfile, "SIO3", 'Greens', label,bounds,"contour") lons_overall = lons lats_overall = lats dens_sum_nwp += dens infile_ib = datadir_ib + "analysis.density." + str(y1) + str( y2) + ".nc" outfile_ib = "analysis_track_density." + str(y1) + str(y2) + ".png" ffib = Dataset(infile_ib, 'r') dens_ib = ffib.variables['density'][:] label = ' ' bounds = np.linspace(0, 20, 11) pl.map_composite_data(dens_ib, lats, lons, outfile_ib, "SIO3", 'Greens', label, bounds, "contour") dens_sum_ib += dens_ib outfile_bias = "ukmo_nwp.track_density_bias.vs_analysis.lt" + str( lt) + "_days." + str(y1) + str(y2) + ".png" bias = dens - dens_ib #bounds_bias = np.linspace(-5, 5, 11) bounds_bias = np.array([-5, -4, -3, -2, -1, 1, 2, 3, 4, 5]) pl.map_composite_data(bias, lats, lons, outfile_bias, "SIO3", 'BrBG', label, bounds_bias, "contour", 'bias') #map the track density across all the years/TC seasons #print dens_sum #print lons_overall