Exemple #1
0
import os
import numpy
import datetime
import pickle

import matplotlib
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.patches import Rectangle

start = datetime.datetime(1851, 1, 1, 0, 0)
end = datetime.datetime(2018, 12, 31, 23, 59)

from get_sample import get_sample_cube

(ndata, dts) = get_sample_cube(start, end)

# Plot the resulting array as a 2d colourmap
fig = Figure(
    figsize=(19.2, 6),  # Width, Height (inches)
    dpi=300,
    facecolor=(0.5, 0.5, 0.5, 1),
    edgecolor=None,
    linewidth=0.0,
    frameon=False,
    subplotpars=None,
    tight_layout=None)
canvas = FigureCanvas(fig)
matplotlib.rc('image', aspect='auto')

# Add a textured grey background
Exemple #2
0
parser.add_argument("--endyear",
                    help="End Year",
                    type=int,
                    required=False,
                    default=1935)
parser.add_argument("--opdir", help="Directory for output files",
                    default="%s/20CR/version_3/analyses/Stripes_daily/PRMSL" % \
                                           os.getenv('SCRATCH'),
                    type=str,required=False)
args = parser.parse_args()
if not os.path.isdir(args.opdir):
    os.makedirs(args.opdir)

# Fix dask SPICE bug
import dask
dask.config.set(scheduler='single-threaded')

from get_sample import get_sample_cube

cday = args.day
if args.month == 2 and args.day == 29: cday = 28
cpkl = "%s/20CR/version_3/analyses/daily/PRMSL/clim_%04d-%04d/%02d%02d.pkl" % (
    os.getenv('SCRATCH'), args.startyear, args.endyear, args.month, cday)
climatology = pickle.load(open(cpkl, 'rb'))

ndata = get_sample_cube(args.year, args.month, args.day, climatology)
dts = datetime.datetime(args.year, args.month, args.day, 12)

cspf = "%s/%04d%02d%02d.pkl" % (args.opdir, args.year, args.month, args.day)
pickle.dump((ndata, dts), open(cspf, 'wb'))
Exemple #3
0
                                         cell.point.year < (2010+1))
    h=iris.load('%s/ERA5/monthly_averaged_ensemble_members/t2m.nc' % 
                                                   os.getenv('SCRATCH'),
                 iris.Constraint(name='2 metre temperature') & mc)
    # ERA5 data bug - get a masked copy along with the data
    #   pick the real version.
    if numpy.ma.is_masked(h[0].data):
        h = h[1]
    else:
        h = h[0]
    n.append(h.extract(mc).collapsed(['time','ensemble_member'],
                                     iris.analysis.MEAN))

# Process in batches or we'll run out of memory.
rst = numpy.random.RandomState(seed=0)
dts=[]
ndata=None
for year in range(1979,end.year+1,5):
    ey = min(year+5,end.year)
    (ndyr,dtyr) = get_sample_cube(datetime.datetime(year,1,1,0,0),
                                  datetime.datetime(ey,12,31,23,59),
                                  climatology=n,
                                  new_grid=egrid,rstate=rst)
    dts.extend(dtyr)
    if ndata is None:
        ndata = ndyr
    else:
        ndata = numpy.ma.concatenate((ndata,ndyr))

pickle.dump( (ndata,dts), open( "ERA5.pkl", "wb" ) )
Exemple #4
0
import matplotlib
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.patches import Rectangle

start = datetime.datetime(1851, 1, 1, 0, 0)
end = datetime.datetime(2018, 12, 31, 23, 59)

from get_sample import get_sample_cube

egrid = iris.load_cube("/scratch/hadcc/hadcrut5/build/HadCRUT5/analysis/"+
                     "HadCRUT.5.0.0.0.analysis.anomalies.%d.nc" % 1,
                       iris.Constraint(time=lambda cell: cell.point.year==1850 and\
                                                         cell.point.month==1))

(ndata, dts) = get_sample_cube(start, end, new_grid=egrid)

# Plot the resulting array as a 2d colourmap
fig = Figure(
    figsize=(19.2, 6),  # Width, Height (inches)
    dpi=600,
    facecolor=(0.5, 0.5, 0.5, 1),
    edgecolor=None,
    linewidth=0.0,
    frameon=False,
    subplotpars=None,
    tight_layout=None)
canvas = FigureCanvas(fig)
matplotlib.rc('image', aspect='auto')

# Add a textured grey background