def load_di_icec(dte): dte1 = datetime.datetime(dte.year, dte.month, dte.day, 0) dte2 = dte1 + datetime.timedelta(days=1) try: icec = opfc.load('icec', dte1, model='global') tmp = opfc.load('icec', dte2, model='global') tmp.attributes = icec.attributes icec = iris.cube.CubeList((icec, tmp)).merge_cube() icec = icec.interpolate([('time', dte)], iris.analysis.Linear()) except: icec = opfc.load('icec', dte1 - datetime.timedelta(days=1), model='global') return icec
def load_recent_temperatures( dte, # current time (datetime.datetime) before=5, # use this many days before after=5): # use this many days after stt = dte - datetime.timedelta(days=before) ent = dte + datetime.timedelta(days=after) ct = stt tcount = 0 dcount = 0 tavg = None davg = None while ct < ent: try: ttmp = opfc.load('air.2m', ct, model='global') tcount += 1 if tavg is None: tavg = ttmp.copy() else: tavg.data += ttmp.data if ct.hour == dte.hour: dcount += 1 if davg is None: davg = ttmp.copy() else: davg.data += ttmp.data except: ct += datetime.timedelta(hours=1) continue ct += datetime.timedelta(hours=1) tavg.data /= tcount davg.data /= dcount davg.data -= tavg.data return (tavg, davg)
def load_li_precip(dte): # Time to plot (datetime.datetime) if dte.minute < 30: prevt = dte - datetime.timedelta(minutes=30 + dte.minute) else: prevt = dte - datetime.timedelta(minutes=dte.minute - 30) nextt = prevt + datetime.timedelta(hours=1) prevp = opfc.load('prate_a', prevt, model='global') prevp.data += 1.0e-7 prevp.data = numpy.log(prevp.data) nextp = opfc.load('prate_a', nextt, model='global') nextp.data += 1.0e-7 nextp.data = numpy.log(nextp.data) w = (dte - prevt).total_seconds() / (nextt - prevt).total_seconds() precip = prevp.copy() precip.data = prevp.data * (1 - w) + nextp.data * w precip.data += 15 precip.data /= 11 precip.data[precip.data < 0] = 0 precip.data[precip.data > 1] = 1 return precip
# Damp the latitude variation #t2m=damp_lat(t2m,factor=0.25) u10m = twcr.load('uwnd.10m', dte, version='2c') u10m = u10m.extract(iris.Constraint(member=1)) v10m = twcr.load('vwnd.10m', dte, version='2c') v10m = v10m.extract(iris.Constraint(member=1)) precip = twcr.load('prate', dte, version='2c') precip = precip.extract(iris.Constraint(member=1)) prmsl = twcr.load('prmsl', dte, version='2c') prmsl = prmsl.collapsed('member', iris.analysis.STD_DEV) precip = normalise_precip(precip) dte1 = datetime.datetime(2019, 2, 25, 12) try: mask = opfc.load('lsmask', dte1, model='global') except: mask = opfc.load('lsmask', dte1 - datetime.timedelta(days=1), model='global') # Define the figure (page size, background color, resolution, ... fig = Figure( figsize=(19.2, 10.8), # Width, Height (inches) dpi=100, facecolor=(0.5, 0.5, 0.5, 1), edgecolor=None, linewidth=0.0, frameon=False, # Don't draw a frame subplotpars=None, tight_layout=None)
dte = datetime.datetime(args.year, args.month, args.day, int(args.hour), int(args.hour % 1 * 60)) # In the temperature field, damp the diurnal cycle, and # boost the short-timescale variability. Load the # recent data to calculate this. stt = dte - datetime.timedelta(days=5) ent = dte + datetime.timedelta(days=5) ct = stt tcount = 0 dcount = 0 tavg = None davg = None while ct < ent: try: ttmp = opfc.load('air.2m', ct, model='global') tcount += 1 if tavg is None: tavg = ttmp.copy() else: tavg.data += ttmp.data if ct.hour == dte.hour: dcount += 1 if davg is None: davg = ttmp.copy() else: davg.data += ttmp.data except: ct += datetime.timedelta(hours=1) continue ct += datetime.timedelta(hours=1)
type=str,required=False) args = parser.parse_args() if not os.path.isdir(args.opdir): os.makedirs(args.opdir) dte = datetime.datetime(args.year, args.month, args.day, int(args.hour), int(args.hour % 1 * 60)) # In the temperature field, damp the diurnal cycle, and # boost the short-timescale variability. Load the # recent data to calculate this. (tavg, davg) = load_recent_temperatures(dte) # Load the model data t2m = opfc.load('air.2m', dte, model='global') # Remove the diurnal cycle t2m.data -= davg.data # Double the synoptic variability t2m.data += (t2m.data - tavg.data) * 1 # Add back a reduced diurnal cycle t2m.data += davg.data * 0.25 u10m = opfc.load('uwnd.10m', dte, model='global') v10m = opfc.load('vwnd.10m', dte, model='global') # We're plotting log precip - so interpolate in log space too precip = load_li_precip(dte) mask = iris.load_cube("%s/fixed_fields/land_mask/opfc_global_2019.nc" % os.getenv('SCRATCH'))
int(args.hour % 1 * 60)) # Scale down the latitudinal variation in temperature def damp_lat(sst, factor=0.5): s = sst.shape mt = numpy.min(sst.data) for lat_i in range(s[0]): lmt = numpy.mean(sst.data[lat_i, :]) if numpy.isfinite(lmt): sst.data[lat_i, :] -= (lmt - mt) * factor return (sst) # Load the Meto data sst = opfc.load('tsurf', dte, model='global') icec = opfc.load('icec', dte, model='global') orog = opfc.load('orog', dte, model='global') mask = opfc.load('lsmask', dte, model='global') # Apply the LS mask to turn tsurf into SST sst.data[mask.data >= 0.5] = numpy.nan sst.data = numpy.ma.array(sst.data, mask=mask.data > 0.5) sst = damp_lat(sst, factor=0.25) # Define the figure (page size, background color, resolution, ... fig = Figure( figsize=(19.2, 10.8), # HD video dpi=100, facecolor=(0.5, 0.5, 0.5, 1),
return (sst) # In the temperature field, damp the diurnal cycle, and # boost the short-timescale variability. Load the # recent data to calculate this. stt = dte - datetime.timedelta(days=5) ent = dte + datetime.timedelta(days=5) ct = stt tcount = 0 dcount = 0 tavg = None davg = None while ct < ent: try: ttmp = opfc.load('air.2m', ct, model='global') tcount += 1 if tavg is None: tavg = ttmp.copy() else: tavg.data += ttmp.data if ct.hour == dte.hour: dcount += 1 if davg is None: davg = ttmp.copy() else: davg.data += ttmp.data except: ct += datetime.timedelta(hours=1) continue ct += datetime.timedelta(hours=1)
import cartopy.crs as ccrs from pandas import qcut # Scale down the latitudinal variation in temperature def damp_lat(sst,factor=0.5): s=sst.shape mt=numpy.min(sst.data) for lat_i in range(s[0]): lmt=numpy.mean(sst.data[lat_i,:]) if numpy.isfinite(lmt): sst.data[lat_i,:] -= (lmt-mt)*factor return(sst) # Load the Meto SST sst=opfc.load('tsurf',dte,model='global') # And the sea-ice icec=opfc.load('icec',dte,model='global') # And the orography orog=iris.load_cube("%s/fixed_fields/orography/opfc_global_2019.nc" % os.getenv('SCRATCH')) # And the land-sea mask mask=iris.load_cube("%s/fixed_fields/land_mask/opfc_global_2019.nc" % os.getenv('SCRATCH')) # Apply the LS mask to turn tsurf into SST sst.data[mask.data>=0.5]=numpy.nan sst.data=numpy.ma.array(sst.data, mask=mask.data>0.5) sst=damp_lat(sst,factor=0.25)