{"id":1012,"date":"2018-01-22T19:44:21","date_gmt":"2018-01-22T19:44:21","guid":{"rendered":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/?page_id=1012"},"modified":"2018-01-22T20:35:34","modified_gmt":"2018-01-22T20:35:34","slug":"smc_namerica_normal1-py","status":"publish","type":"page","link":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/software-examples\/code-samples\/smc_namerica_normal1-py\/","title":{"rendered":"smc_1D-2D_1979-2012_NAmerica_Normal1.py"},"content":{"rendered":"<p>#\u00a0smc_1D-2D_1979-2012_NAmerica_Normal1.py<\/p>\n<div># This Python2.7 code was used on CEDA JASMIN to produce monthly<\/div>\n<div># animation frames for an animated gif that was then made into an MP4<\/div>\n<div># for showing the soil moisture and the seasonal anomaly of soil moisture<\/div>\n<div># as two time series over Normal, Illinois from 1979-2012<\/div>\n<div># using (as input) monthly-averaged JULES land-only 1D data.<\/div>\n<div># This Python2.7 code was adapted from the code given in Emma Robinson&#8217;s<\/div>\n<div># data visualization tutorial for plotting JULES data at http:\/\/jules.jchmr.org\/content\/training .<\/div>\n<div># The adaptation was done in November-December 2017 by Patrick McGuire and Pier Luigi Vidale<\/div>\n<div># at the University of Reading (email: p.mcguire@reading.ac.uk )<\/div>\n<div><\/div>\n<div>from netCDF4 import Dataset, num2date, date2num<\/div>\n<div># Import libraries useful for times<\/div>\n<div>import datetime as dt<\/div>\n<div>import calendar as cal<\/div>\n<div># widget library<\/div>\n<div>#from ipywidgets.widgets import *<\/div>\n<div>import numpy as np<\/div>\n<div>import matplotlib.pyplot as plt<\/div>\n<div>from mpl_toolkits.basemap import Basemap<\/div>\n<div># Import locators for fancying up plots<\/div>\n<div>from matplotlib.dates import YearLocator, MonthLocator<\/div>\n<div>from matplotlib.ticker import MultipleLocator<\/div>\n<div>from matplotlib.colors import LinearSegmentedColormap<\/div>\n<div>from matplotlib.colors import ListedColormap<\/div>\n<div><\/div>\n<div>def ReadData(fname, vname, rescale, compute_timebnds):<\/div>\n<div>\u00a0 \u00a0 # Open the file<\/div>\n<div>\u00a0 \u00a0 f = Dataset(fname,&#8217;r&#8217;)<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 # Print file headers<\/div>\n<div>\u00a0 \u00a0 #print f<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 # Print variable information<\/div>\n<div>\u00a0 \u00a0 #print f.variables[&#8216;fqw_gb&#8217;]<\/div>\n<div>\u00a0 \u00a0 #print f.variables[&#8216;ftl_gb&#8217;]<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 # Read the evaporation variable<\/div>\n<div>\u00a0 \u00a0 data = f.variables[vname][:]<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 # Get the shape<\/div>\n<div>\u00a0 \u00a0 nt, ny, nx = data.shape<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 # Since we know that the y dimension is degenerate, we select y=0 and collapse<\/div>\n<div>\u00a0 \u00a0 # the data to 2d (nt*nx)<\/div>\n<div>\u00a0 \u00a0 data = data[:,0,:]<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 # Get the fill value for later use<\/div>\n<div>\u00a0 \u00a0 fill_value = f.variables[vname]._FillValue<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 # Get latitude and longitude variables<\/div>\n<div>\u00a0 \u00a0 # latitude and longitude are ny*nx, so we select y=0 and collapse to a vector<\/div>\n<div>\u00a0 \u00a0 lat = f.variables[&#8216;latitude&#8217;][0,:]<\/div>\n<div>\u00a0 \u00a0 lon = f.variables[&#8216;longitude&#8217;][0,:]<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 # Find information about times<\/div>\n<div>\u00a0 \u00a0 startyr, startmn, startdy = [int(t) \\<\/div>\n<div>\u00a0 \u00a0 for t in f.variables[&#8216;time&#8217;].units.split()[2].split(&#8216;-&#8216;)]<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 calendar=f.variables[&#8216;time&#8217;].calendar<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 if(compute_timebnds):<\/div>\n<div>\u00a0 \u00a0 # Read the time and convert to datetime data structures<\/div>\n<div>\u00a0 \u00a0 # Since we&#8217;re looking at monthly averages, we use the time at the start of the<\/div>\n<div>\u00a0 \u00a0 # month. So we read the time_bounds array and use the lower value<\/div>\n<div># \u00a0 \u00a0time_bounds = f.variables[&#8216;time_bounds&#8217;][:]<\/div>\n<div>\u00a0 \u00a0 \u00a0 time_bounds = f.variables[&#8216;time_bnds&#8217;][:]<\/div>\n<div>\u00a0 \u00a0 \u00a0 time = [dt.datetime(startyr,startmn,startdy)+dt.timedelta(seconds=int(t)) \\<\/div>\n<div>\u00a0 \u00a0 \u00a0 for t in time_bounds[:,0] ]<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 # We want to rescale the precip from kg\/m2\/s to mm\/month, so we need to<\/div>\n<div>\u00a0 \u00a0 # know how long the month is<\/div>\n<div>\u00a0 \u00a0 \u00a0 days_in_month = np.array([ [cal.monthrange(t.year,t.month)[1],] for t in time ])<\/div>\n<div>\u00a0 \u00a0 \u00a0 secs_in_day = 86400<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 \u00a0 if(rescale):<\/div>\n<div>\u00a0 \u00a0 # Rescale precip<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 data *= (days_in_month * secs_in_day)<\/div>\n<div>\u00a0 \u00a0 else:<\/div>\n<div>\u00a0 \u00a0 \u00a0 time = 0<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 # Close the file<\/div>\n<div>\u00a0 \u00a0 f.close()<\/div>\n<div>\u00a0 \u00a0 return data, lon, lat, nt, nx, time, calendar, fill_value<\/div>\n<div><\/div>\n<div>def VectorToGrid(data,lon,lat,nt,nx,fill_value):<\/div>\n<div>\u00a0 \u00a0 # Define the grid we want to end up on<\/div>\n<div>\u00a0 \u00a0 lon_min = -180.0<\/div>\n<div>\u00a0 \u00a0 lon_max = 180.0<\/div>\n<div>\u00a0 \u00a0 dlon = 0.5<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 lat_min = -90.0<\/div>\n<div>\u00a0 \u00a0 lat_max = 90.0<\/div>\n<div>\u00a0 \u00a0 dlat = 0.5<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 # Create the grid<\/div>\n<div>\u00a0 \u00a0 grid_lon, grid_lat = np.meshgrid( np.arange( lon_min+dlon\/2., lon_max, dlon ), \\<\/div>\n<div>\u00a0 \u00a0 np.arange( lat_min+dlat\/2., lat_max, dlat ) )<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 # Grid shape<\/div>\n<div>\u00a0 \u00a0 ny_grid, nx_grid = grid_lon.shape<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 # Map the vector to the grid<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 # If it&#8217;s not a regular lat\/lon grid, then use the np.where function to find<\/div>\n<div>\u00a0 \u00a0 # the right point in the grid<\/div>\n<div>\u00a0 \u00a0 # indx = [np.where( np.logical_and( grid_lon == lon[i], grid_lat == lat[i] )) \\<\/div>\n<div>\u00a0 \u00a0 # for i in range(nx) ]<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 # But, since this is regular lat\/lon, we can save time and calculate where<\/div>\n<div>\u00a0 \u00a0 # each point will be relative to the minimum values<\/div>\n<div>\u00a0 \u00a0 # This is quicker than the np.where function call<\/div>\n<div>\u00a0 \u00a0 indx = zip(* [ [ int((lat[i] &#8211; lat_min)\/dlat), int((lon[i] &#8211; lon_min)\/dlon) ] \\<\/div>\n<div>\u00a0 \u00a0 for i in range(nx)] )<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 # Create a new masked array with no data in it<\/div>\n<div>\u00a0 \u00a0 data_grid = np.ma.masked_equal( np.ones([nt,ny_grid,nx_grid])*fill_value, \\<\/div>\n<div>\u00a0 \u00a0 fill_value )<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 # Put the vector data into the grid<\/div>\n<div>\u00a0 \u00a0 data_grid[:,indx[0],indx[1]] = data[:]<\/div>\n<div>\u00a0 \u00a0 return data_grid, grid_lon, grid_lat, lon_min, lon_max, lat_min, lat_max<\/div>\n<div><\/div>\n<div>def custom_div_cmap(numcolors=13, name=&#8217;custom_div_cmap&#8217;,<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 mincol=&#8217;darkred&#8217;, midcol=&#8217;white&#8217;, maxcol=&#8217;darkblue&#8217;):<\/div>\n<div>\u00a0 \u00a0 &#8220;&#8221;&#8221; Create a custom diverging colormap with three colors<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 Default is red to white to blue with 11 colors. \u00a0Colors can be specified<\/div>\n<div>\u00a0 \u00a0 in any way understandable by matplotlib.colors.ColorConverter.to_rgb()<\/div>\n<div>\u00a0 \u00a0 &#8220;&#8221;&#8221;<\/div>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 cmap2 = LinearSegmentedColormap.from_list(name=name,<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0colors =[mincol, midcol, maxcol],<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0N=numcolors)<\/div>\n<div>\u00a0 \u00a0 return cmap2<\/div>\n<div><\/div>\n<div>bwr_custom = custom_div_cmap()<\/div>\n<div>#Make sure to pick subset LAT\/LON&#8217;s to be a half a pixel off of where you want (0.25- or 0.75-degree offsets from a degree)<\/div>\n<div>#Africa<\/div>\n<div>#lon_min_Subset = -30.25<\/div>\n<div>#lon_max_Subset = 60.25<\/div>\n<div>#lat_min_Subset = -40.25<\/div>\n<div>#lat_max_Subset = 40.25<\/div>\n<div><\/div>\n<div>#NAmerica<\/div>\n<div>lon_min_Subset = -170.25<\/div>\n<div>lon_max_Subset = -49.75<\/div>\n<div>lat_min_Subset = 4.75<\/div>\n<div>lat_max_Subset = 80.25<\/div>\n<div><\/div>\n<div>#Normal, Illinois<\/div>\n<div>#to nearest quarter degree<\/div>\n<div>lon_Point = -89.00<\/div>\n<div>lat_Point = 40.50<\/div>\n<div><\/div>\n<div>#fvarname = [&#8216;EVAP&#8217;, &#8216;GPP&#8217;, &#8216;WAIR&#8217;]<\/div>\n<div>#ovarname= [&#8216;EnsembleLEcor_May12&#8242;,&#8217;gpp&#8217;,&#8217;WAI&#8217;]<\/div>\n<div>#mvarname= [&#8216;esoil_mean&#8217;,&#8217;gpp_mean&#8217;,&#8217;smc_avail_tot_mean&#8217;]<\/div>\n<div><\/div>\n<div>##Set JULES experiments start\/end dates<\/div>\n<div>#dStart = datetime.datetime(1979,1,1)<\/div>\n<div>#dEnd = datetime.datetime(1982,12,31)<\/div>\n<div>#dateIndex = pandas.date_range(start=dStart, end=dEnd, freq=&#8217;M&#8217;)<\/div>\n<div><\/div>\n<div>##Now set the plot limits<\/div>\n<div>##t0=datetime.datetime(1997,01,01,00,00) # x axis startpoint<\/div>\n<div>##t1=datetime.datetime(1999,01,01,00,00) # x axis endpoint<\/div>\n<div>#t0=datetime.datetime(1979,01,01,00,00) # x axis startpoint<\/div>\n<div>#t1=datetime.datetime(1982,12,31,00,00) # x axis endpoint<\/div>\n<div><\/div>\n<div>#obs_dir=&#8217;\/group_workspaces\/jasmin2\/ncas_generic\/users\/pmcguire\/analysis\/obs\/BGI_validation\/data\/BGI\/&#8217;<\/div>\n<div><\/div>\n<div>#vname = &#8216;precip&#8217;<\/div>\n<div>#vnamelong = &#8216;Precipitation&#8217;<\/div>\n<div>#vnamedir = &#8216;precip&#8217;<\/div>\n<div>#cmap0 = &#8216;gist_rainbow&#8217;<\/div>\n<div>##units = &#8216;mm\/s&#8217;<\/div>\n<div>##vmin0 = 0<\/div>\n<div>##vmax0 = 1e-4<\/div>\n<div>##tickformat = &#8216;%.0e&#8217;<\/div>\n<div>#units = &#8216;mm\/month&#8217;<\/div>\n<div>#vmin0 = 0<\/div>\n<div>#vmax0 = 300<\/div>\n<div>#tickformat = &#8216;%.0f&#8217;<\/div>\n<div>#rescale = 1<\/div>\n<div>#PlotArray = 0<\/div>\n<div>#PlotSeries = 1<\/div>\n<div><\/div>\n<div>vname = &#8216;smc_avail_tot&#8217;<\/div>\n<div>vnamelong = &#8216;Soil_moisture_avail_tot&#8217;<\/div>\n<div>vnamedir = &#8216;smc_NAmerica_Normal&#8217;<\/div>\n<div>#cmap0 = custom_div_cmap(numcolors=5)<\/div>\n<div>cmap0=ListedColormap([&#8216;DarkRed&#8217;,&#8217;Salmon&#8217;,&#8217;Orange&#8217;,&#8217;Yellow&#8217;,&#8217;LightGreen&#8217;,&#8217;Green&#8217;,&#8217;Cyan&#8217;,&#8217;LightBlue&#8217;,&#8217;Blue&#8217;,&#8217;DarkBlue&#8217;,&#8217;Indigo&#8217;,&#8217;DarkViolet&#8217;])<\/div>\n<div>units = &#8216;mm&#8217;<\/div>\n<div>vmin0 = 0<\/div>\n<div>vmax0 = 600<\/div>\n<div>tickformat = &#8216;%.0f&#8217;<\/div>\n<div>tickspacing = np.arange(0,650,50.0)<\/div>\n<div>rescale = 0<\/div>\n<div>PlotArray = 0<\/div>\n<div>PlotSeries = 1<\/div>\n<div>Location = &#8216;Normal, Illinois&#8217;<\/div>\n<div>YearMin = 1979<\/div>\n<div>YearMax = 2012<\/div>\n<div>YEARS = YearMax-YearMin+1<\/div>\n<div><\/div>\n<div># \u00a0vname = &#8216;npp_gb&#8217;<\/div>\n<div># \u00a0vnamelong = &#8216;Net_primary_production(NPP)&#8217;<\/div>\n<div># \u00a0vnamedir = &#8216;npp&#8217;<\/div>\n<div># \u00a0cmap0 = &#8216;PRGn&#8217;<\/div>\n<div># \u00a0units = &#8216;kg m-2 s-1&#8217;<\/div>\n<div># \u00a0vmin0 = -5e-8<\/div>\n<div># \u00a0vmax0 = 5e-8<\/div>\n<div># \u00a0tickformat = &#8216;%.0e&#8217;<\/div>\n<div># \u00a0rescale = 0<\/div>\n<div># \u00a0PlotArray = 0<\/div>\n<div># \u00a0PlotSeries = 1<\/div>\n<div><\/div>\n<div><\/div>\n<div>t0=dt.datetime(YearMin,01,01,00,00) # x axis startpoint<\/div>\n<div>t1=dt.datetime(YearMax,12,31,00,00) # x axis endpoint<\/div>\n<div><\/div>\n<div>fname_avg = &#8216;Euro44_bvv_nancil_CTL-BCJ-GL_jules-vn4.9p_u-as052globeE_monmean_1979_2012_ymonavg.nc&#8217;<\/div>\n<div>fname_std1 = &#8216;Euro44_bvv_nancil_CTL-BCJ-GL_jules-vn4.9p_u-as052globeE_monmean_1979_2012_ymonstd1.nc&#8217;<\/div>\n<div><\/div>\n<div>data_avg, lon_avg, lat_avg, nt_avg, nx_avg, time_avg, calendar_avg, fill_value_avg \u00a0 \u00a0 \u00a0 \u00a0= ReadData(fname_avg,vname,rescale,compute_timebnds=0)<\/div>\n<div>data_grid_avg,grid_lon_avg,grid_lat_avg,lon_min_avg,lon_max_avg,lat_min_avg,lat_max_avg = VectorToGrid(data_avg,lon_avg,lat_avg,nt_avg,nx_avg,fill_value_avg)<\/div>\n<div><\/div>\n<div>data_std1, lon_std1, lat_std1, nt_std1, nx_std1, time_std1, calendar_std1, fill_value_std1 \u00a0 \u00a0 \u00a0 \u00a0= ReadData(fname_std1,vname,rescale,compute_timebnds=0)<\/div>\n<div>data_grid_std1,grid_lon_std1,grid_lat_std1,lon_min_std1,lon_max_std1,lat_min_std1,lat_max_std1 = VectorToGrid(data_std1,lon_std1,lat_std1,nt_std1,nx_std1,fill_value_std1)<\/div>\n<div><\/div>\n<div><\/div>\n<div>dates \u00a0 \u00a0 \u00a0 \u00a0 = [dt.date(year,month,1) for year in range(YearMin,YearMax+1) for month in range(1,13)]<\/div>\n<div>data_series \u00a0 \u00a0 \u00a0 \u00a0 = np.zeros(12*YEARS)<\/div>\n<div>data_series_avg \u00a0 \u00a0 = np.zeros(12*YEARS)<\/div>\n<div>data_series_std1 \u00a0 \u00a0= np.zeros(12*YEARS)<\/div>\n<div>data_series_anom \u00a0 \u00a0= np.zeros(12*YEARS)<\/div>\n<div>data_series_ones \u00a0 \u00a0= np.ones(12*YEARS)<\/div>\n<div>data_series_zeros \u00a0 \u00a0= np.zeros(12*YEARS)<\/div>\n<div><\/div>\n<div>for year in range(YearMin,YearMax+1):<\/div>\n<div>#fname = &#8216;\/work\/scratch\/pmcguire\/config\/outputs\/wfdei_WRR2_4.9positiverain_16proc45min_U-aq934.monthly.2011.nc&#8217;<\/div>\n<div># \u00a0 \u00a0print &#8216;Year=&#8217;+str(year)<\/div>\n<div><\/div>\n<div>\u00a0 fname = &#8216;Euro44_bvv_nancil_CTL-BCJ-GL_jules-vn4.9p_u-as052globeE_monmean_&#8217;+str(year)+&#8217;.nc&#8217;<\/div>\n<div>\u00a0 fname_anom = &#8216;Euro44_bvv_nancil_CTL-BCJ-GL_jules-vn4.9p_u-as052globeE_monmean_&#8217;+str(year)+&#8217;__1979_2012_ymonstd1anom.nc&#8217;<\/div>\n<div><\/div>\n<div><\/div>\n<div>\u00a0 data, lon, lat, nt, nx, time, calendar0, fill_value \u00a0 \u00a0 \u00a0 \u00a0= ReadData(fname,vname,rescale, compute_timebnds=1)<\/div>\n<div>\u00a0 data_grid,grid_lon,grid_lat,lon_min,lon_max,lat_min,lat_max = VectorToGrid(data,lon,lat,nt,nx,fill_value)<\/div>\n<div><\/div>\n<div>\u00a0 data_anom, lon_anom, lat_anom, nt_anom, nx_anom, time_anom, calendar_anom, fill_value_anom \u00a0 \u00a0 \u00a0 \u00a0= ReadData(fname_anom,vname,rescale, compute_timebnds=1)<\/div>\n<div>\u00a0 data_grid_anom,grid_lon_anom,grid_lat_anom,lon_min_anom,lon_max_anom,lat_min_anom,lat_max_anom = VectorToGrid(data_anom,lon_anom,lat_anom,nt_anom,nx_anom,fill_value_anom)<\/div>\n<div>#print data_grid.shape<\/div>\n<div><\/div>\n<div>\u00a0 for month in range(0,12):<\/div>\n<div>\u00a0 \u00a0 dates[month+(year-1979)*12] = time[month]<\/div>\n<div>\u00a0 \u00a0 if(month&lt;9):<\/div>\n<div>\u00a0 \u00a0 \u00a0 month2=&#8217;0&#8217;+str(month+1)<\/div>\n<div>\u00a0 \u00a0 else:<\/div>\n<div>\u00a0 \u00a0 \u00a0 month2=str(month+1)<\/div>\n<div># \u00a0 \u00a0print &#8216;Year=&#8217;+str(year)+&#8217; Month=&#8217;+month2<\/div>\n<div># latitude lower and upper index<\/div>\n<div>\u00a0 \u00a0 latli = np.argmin( np.abs( grid_lat[:,0] &#8211; lat_min_Subset ) )<\/div>\n<div>\u00a0 \u00a0 latui = np.argmin( np.abs( grid_lat[:,0] &#8211; lat_max_Subset ) )<\/div>\n<div># \u00a0 \u00a0print &#8216;Lat index min\/max=&#8217;+str(latli)+&#8217; &#8216;+str(latui)<\/div>\n<div># \u00a0 \u00a0print &#8216;Lat min\/max=&#8217;+str(grid_lat[latli,0])+&#8217; &#8216;+str(grid_lat[latui,0])<\/div>\n<div>\u00a0 \u00a0 lati = np.argmin( np.abs( grid_lat[:,0] &#8211; lat_Point) )<\/div>\n<div># \u00a0 \u00a0print &#8216;Lat index =&#8217;+str(lati)<\/div>\n<div># \u00a0 \u00a0print &#8216;Lat =&#8217;+str(grid_lat[lati,0])<\/div>\n<div><\/div>\n<div># longitude lower and upper index<\/div>\n<div>\u00a0 \u00a0 lonli = np.argmin( np.abs( grid_lon[0,:] &#8211; lon_min_Subset) )<\/div>\n<div>\u00a0 \u00a0 lonui = np.argmin( np.abs( grid_lon[0,:] &#8211; lon_max_Subset) )<\/div>\n<div># \u00a0 \u00a0print &#8216;Lon index min\/max=&#8217;+str(lonli)+&#8217; &#8216;+str(lonui)<\/div>\n<div># \u00a0 \u00a0print &#8216;Lon min\/max=&#8217;+str(grid_lon[0,lonli])+&#8217; &#8216;+str(grid_lon[0,lonui])<\/div>\n<div>\u00a0 \u00a0 loni = np.argmin( np.abs( grid_lon[0,:] &#8211; lon_Point) )<\/div>\n<div># \u00a0 \u00a0print &#8216;Lon index =&#8217;+str(loni)<\/div>\n<div># \u00a0 \u00a0print &#8216;Lon =&#8217;+str(grid_lon[0,loni])<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 data_series[month+(year-1979)*12] = data_grid[month,lati,loni]<\/div>\n<div>\u00a0 \u00a0 data_series_avg[month+(year-1979)*12] = data_grid_avg[month,lati,loni]<\/div>\n<div>\u00a0 \u00a0 data_series_std1[month+(year-1979)*12] = data_grid_std1[month,lati,loni]<\/div>\n<div>\u00a0 \u00a0 data_series_anom[month+(year-1979)*12] = data_grid_anom[month,lati,loni]<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 if(PlotArray):<\/div>\n<div>\u00a0 \u00a0 \u00a0 fig = plt.figure(figsize=(12.,8.))<\/div>\n<div><\/div>\n<div># Create a new plot<\/div>\n<div>\u00a0 \u00a0 \u00a0 fig,ax = plt.subplots(1,1)<\/div>\n<div><\/div>\n<div># Make a world map<\/div>\n<div>\u00a0 \u00a0 \u00a0 m = Basemap(projection=&#8217;cyl&#8217;, resolution=&#8217;c&#8217;, ax = ax , \\<\/div>\n<div>llcrnrlat = lat_min_Subset, \\<\/div>\n<div>llcrnrlon = lon_min_Subset, \\<\/div>\n<div>urcrnrlat = lat_max_Subset, \\<\/div>\n<div>urcrnrlon = lon_max_Subset )<\/div>\n<div>\u00a0 \u00a0 \u00a0 m.drawcoastlines(zorder=2)<\/div>\n<div>\u00a0 \u00a0 \u00a0 m.fillcontinents([0.8,0.8,0.8],zorder=0)<\/div>\n<div><\/div>\n<div># Plot array as a colormap<\/div>\n<div>#im = ax.imshow(data_grid[7,:,:], cmap = &#8216;gist_ncar&#8217;, \\<\/div>\n<div>\u00a0 \u00a0 \u00a0 im = ax.imshow(data_grid[month,latli:latui,lonli:lonui], cmap = cmap0, \\<\/div>\n<div>interpolation = &#8216;nearest&#8217;, origin = &#8216;lower&#8217;, \\<\/div>\n<div>vmin = vmin0, vmax = vmax0, zorder=1, \\<\/div>\n<div>extent = [lon_min_Subset, lon_max_Subset, lat_min_Subset, lat_max_Subset])<\/div>\n<div><\/div>\n<div># Set grid<\/div>\n<div>\u00a0 \u00a0 \u00a0 ax.xaxis.set_major_locator(MultipleLocator(30))<\/div>\n<div>\u00a0 \u00a0 \u00a0 ax.yaxis.set_major_locator(MultipleLocator(30))<\/div>\n<div>\u00a0 \u00a0 \u00a0 ax.grid(True)<\/div>\n<div><\/div>\n<div># Create a colorbar<\/div>\n<div>\u00a0 \u00a0 \u00a0 cb=plt.colorbar(im, ax = ax, orientation=&#8217;horizontal&#8217;, \\<\/div>\n<div>label=&#8217;Monthly &#8216;+vnamelong+&#8217; (&#8216;+units+&#8217;): &#8216;+str(month2)+&#8217;-&#8216;+str(year), format = tickformat, ticks = tickspacing, extend=&#8217;both&#8217; )<\/div>\n<div><\/div>\n<div># Save the figure<\/div>\n<div>#fig.savefig(&#8216;python_sensible_map.png&#8217;,dpi=600)<\/div>\n<div>\u00a0 \u00a0 \u00a0 fig.savefig(vnamedir+&#8217;_pngs\/&#8217;+str(vname)+&#8217;_&#8217;+str(year)+&#8217;-&#8216;+str(month2)+&#8217;.png&#8217;,dpi=150)<\/div>\n<div><\/div>\n<div># Show the figures on screen<\/div>\n<div>#plt.show()<\/div>\n<div>\u00a0 \u00a0 \u00a0 plt.close(fig)<\/div>\n<div><\/div>\n<div>if(PlotSeries):<\/div>\n<div>\u00a0 \u00a0fig = plt.figure(figsize=(12.,8.))<\/div>\n<div># \u00a0 \u00a0 \u00a0dates2 = dates<\/div>\n<div># \u00a0 \u00a0 \u00a0dates2 = num2date(dates[:],units=&#8217;days since 1582-11-15 00:00:00&#8242;,calendar=calendar0)<\/div>\n<div># Create a new plot<\/div>\n<div>\u00a0 \u00a0fig,ax = plt.subplots(2,1)<\/div>\n<div>\u00a0 \u00a0fig.suptitle(&#8216;JULES Soil Moisture in &#8216;+Location, fontsize=14)<\/div>\n<div><\/div>\n<div># \u00a0 \u00a0 \u00a0years = dates.YearLocator() \u00a0 # every year<\/div>\n<div># \u00a0 \u00a0 \u00a0ax.xaxis.set_major_locator(years)<\/div>\n<div>\u00a0 \u00a0plt.subplot(2,1,1)<\/div>\n<div>\u00a0 \u00a0plt.xlim(t0,t1)<\/div>\n<div>\u00a0 \u00a0print data_series<\/div>\n<div>\u00a0 \u00a0p0, = plt.plot(dates, data_series, &#8216;k.-&#8216;,color=&#8217;red&#8217;, label=&#8217;JULES model&#8217;)<\/div>\n<div>\u00a0 \u00a0p1, = plt.plot(dates, data_series_avg, &#8216;k&#8217;,color=&#8217;black&#8217;, label=&#8217;1979-2012 JULES model avg.&#8217;)<\/div>\n<div>\u00a0 \u00a0plt.fill_between(dates, data_series_avg+data_series_std1, data_series_avg-data_series_std1, facecolor=&#8217;lightgrey&#8217;, edgecolor=&#8217;white&#8217;)<\/div>\n<div>\u00a0 \u00a0plt.ylabel(&#8216;Soil Moisture (mm)&#8217;)<\/div>\n<div>\u00a0 \u00a0plt.xlabel(&#8216;Time (yrs)&#8217;)<\/div>\n<div>\u00a0 \u00a0plt.legend(bbox_to_anchor=(0., 1.02, 1., .102),loc=3,ncol=2, mode=&#8221;expand&#8221;,borderaxespad=0.,fontsize=10)<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0plt.subplot(2,1,2)<\/div>\n<div>## \u00a0 \u00a0 \u00a0years = mdates.YearLocator() \u00a0 # every year<\/div>\n<div>## \u00a0 \u00a0 \u00a0ax.xaxis.set_major_locator(years)<\/div>\n<div>\u00a0 \u00a0plt.xlim(t0,t1)<\/div>\n<div>\u00a0 \u00a0plt.ylabel(&#8216;Anomaly in Soil Moisture (std. dev.)&#8217;)<\/div>\n<div>\u00a0 \u00a0plt.xlabel(&#8216;Time (yrs)&#8217;)<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0p0, = plt.plot(dates, data_series_anom, &#8216;k.-&#8216;,color=&#8217;red&#8217;, label=&#8217;anomaly of JULES model&#8217;)<\/div>\n<div>\u00a0 \u00a0p1, = plt.plot(dates, data_series_zeros, &#8216;k&#8217;,color=&#8217;black&#8217;, label=&#8217;1979-2012 JULES model avg.&#8217;)<\/div>\n<div>\u00a0 \u00a0plt.fill_between(dates, data_series_ones, -data_series_ones, facecolor=&#8217;lightgrey&#8217;, edgecolor=&#8217;white&#8217;)<\/div>\n<div><\/div>\n<div># Save the figure<\/div>\n<div>#fig.savefig(&#8216;python_sensible_map.png&#8217;,dpi=600)<\/div>\n<div>\u00a0 \u00a0fig.savefig(vnamedir+&#8217;_pngs\/&#8217;+str(vname)+&#8217;.png&#8217;,dpi=150)<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0plt.close(fig)<\/div>\n<div><\/div>\n<div>#air = f.variables[&#8216;esoil_gb&#8217;]<\/div>\n<div>#print air<\/div>\n<div>#lat = f.variables[&#8216;latitude&#8217;]<\/div>\n<div>#lon = f.variables[&#8216;longitude&#8217;]<\/div>\n<div>#print lat<\/div>\n<div>#print lon<\/div>\n<div>#m = Basemap(projection=&#8217;npstere&#8217;,boundinglat=60,lon_0=0,resolution=&#8217;l&#8217;)<\/div>\n<div>#nlon, nlat = np.meshgrid(lon[0,:], lat[0,:])<\/div>\n<div>#print nlon,nlat<\/div>\n<div>#x, y = m(lon, lat)<\/div>\n<div>#print x,y<\/div>\n<div>#m.fillcontinents(color=&#8217;gray&#8217;,lake_color=&#8217;gray&#8217;)<\/div>\n<div>#m.drawparallels(np.arange(-80.,81.,20.))<\/div>\n<div>#m.drawmeridians(np.arange(-180.,181.,20.))<\/div>\n<div>#m.drawmapboundary(fill_color=&#8217;white&#8217;)<\/div>\n<div>#cs = m.contourf(x,y,air[0,0,:])<\/div>\n<div>##imshow(vv[time,:,:])<\/div>\n<div>#m.colorbar()<\/div>\n<div><\/div>\n<div>#fig.savefig(figname2)<\/div>\n<div>#plt.close<\/div>\n<div>#plt.show()<\/div>\n<div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>#\u00a0smc_1D-2D_1979-2012_NAmerica_Normal1.py  # This Python2.7 code was used on CEDA JASMIN to produce monthly  # animation frames for an animated gif that was then made into an MP4  # for showing the soil moisture and the seasonal anomaly of soil moisture  # as two time series over Normal, Illinois from 1979-2012 <\/p>\n","protected":false},"author":12,"featured_media":0,"parent":998,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"__cvm_playback_settings":[],"__cvm_video_id":"","footnotes":""},"class_list":["post-1012","page","type-page","status-publish","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>smc_1D-2D_1979-2012_NAmerica_Normal1.py - Land Surface Processes Group<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/software-examples\/code-samples\/smc_namerica_normal1-py\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"smc_1D-2D_1979-2012_NAmerica_Normal1.py - Land Surface Processes Group\" \/>\n<meta property=\"og:description\" content=\"#\u00a0smc_1D-2D_1979-2012_NAmerica_Normal1.py # This Python2.7 code was used on CEDA JASMIN to produce monthly # animation frames for an animated gif that was then made into an MP4 # for showing the soil moisture and the seasonal anomaly of soil moisture # as two time series over Normal, Illinois from 1979-2012\" \/>\n<meta property=\"og:url\" content=\"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/software-examples\/code-samples\/smc_namerica_normal1-py\/\" \/>\n<meta property=\"og:site_name\" content=\"Land Surface Processes Group\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-22T20:35:34+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/software-examples\/code-samples\/smc_namerica_normal1-py\/\",\"url\":\"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/software-examples\/code-samples\/smc_namerica_normal1-py\/\",\"name\":\"smc_1D-2D_1979-2012_NAmerica_Normal1.py - Land Surface Processes Group\",\"isPartOf\":{\"@id\":\"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/#website\"},\"datePublished\":\"2018-01-22T19:44:21+00:00\",\"dateModified\":\"2018-01-22T20:35:34+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/software-examples\/code-samples\/smc_namerica_normal1-py\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/software-examples\/code-samples\/smc_namerica_normal1-py\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/software-examples\/code-samples\/smc_namerica_normal1-py\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Running JULES\",\"item\":\"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/software-examples\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Library of Plotting Code Samples\",\"item\":\"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/software-examples\/code-samples\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"smc_1D-2D_1979-2012_NAmerica_Normal1.py\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/#website\",\"url\":\"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/\",\"name\":\"Land Surface Processes Group\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"smc_1D-2D_1979-2012_NAmerica_Normal1.py - Land Surface Processes Group","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/software-examples\/code-samples\/smc_namerica_normal1-py\/","og_locale":"en_GB","og_type":"article","og_title":"smc_1D-2D_1979-2012_NAmerica_Normal1.py - Land Surface Processes Group","og_description":"#\u00a0smc_1D-2D_1979-2012_NAmerica_Normal1.py # This Python2.7 code was used on CEDA JASMIN to produce monthly # animation frames for an animated gif that was then made into an MP4 # for showing the soil moisture and the seasonal anomaly of soil moisture # as two time series over Normal, Illinois from 1979-2012","og_url":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/software-examples\/code-samples\/smc_namerica_normal1-py\/","og_site_name":"Land Surface Processes Group","article_modified_time":"2018-01-22T20:35:34+00:00","twitter_card":"summary_large_image","twitter_misc":{"Estimated reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/software-examples\/code-samples\/smc_namerica_normal1-py\/","url":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/software-examples\/code-samples\/smc_namerica_normal1-py\/","name":"smc_1D-2D_1979-2012_NAmerica_Normal1.py - Land Surface Processes Group","isPartOf":{"@id":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/#website"},"datePublished":"2018-01-22T19:44:21+00:00","dateModified":"2018-01-22T20:35:34+00:00","breadcrumb":{"@id":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/software-examples\/code-samples\/smc_namerica_normal1-py\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/software-examples\/code-samples\/smc_namerica_normal1-py\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/software-examples\/code-samples\/smc_namerica_normal1-py\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/"},{"@type":"ListItem","position":2,"name":"Running JULES","item":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/software-examples\/"},{"@type":"ListItem","position":3,"name":"Library of Plotting Code Samples","item":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/software-examples\/code-samples\/"},{"@type":"ListItem","position":4,"name":"smc_1D-2D_1979-2012_NAmerica_Normal1.py"}]},{"@type":"WebSite","@id":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/#website","url":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/","name":"Land Surface Processes Group","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"}]}},"_links":{"self":[{"href":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/wp-json\/wp\/v2\/pages\/1012","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/wp-json\/wp\/v2\/comments?post=1012"}],"version-history":[{"count":1,"href":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/wp-json\/wp\/v2\/pages\/1012\/revisions"}],"predecessor-version":[{"id":1013,"href":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/wp-json\/wp\/v2\/pages\/1012\/revisions\/1013"}],"up":[{"embeddable":true,"href":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/wp-json\/wp\/v2\/pages\/998"}],"wp:attachment":[{"href":"https:\/\/research.reading.ac.uk\/landsurfaceprocesses\/wp-json\/wp\/v2\/media?parent=1012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}