示例#1
0
           '_height-' + heightstr + '_nens-' + str(args.nens) + '_tstart-' +
           str(args.tstart) + '_tend-' + str(args.tend) + '_tinc-' +
           str(args.tinc) + '_minmem-' + str(args.minmem) + '_dr-' +
           str(args.dr) + '.nc')
if args.det == 'True':
    savestr += '_det'

print savestr
# Convert times to timedelta objects
tstart = timedelta(
    hours=args.tstart)  # Cannot be 0 because of tau_c calculation!
tend = timedelta(hours=args.tend)
tinc = timedelta(minutes=args.tinc)  # temporal resolution for analysis

# Setup - Create or define lists
timelist = make_timelist(tstart, tend, tinc)
print len(timelist)
itlist = range(len(timelist))

nlist = [256, 128, 64, 32, 16, 8, 4]
histbinedges = [0, 0.1, 0.2, 0.5, 1, 2, 5, 10, 1000]

# Setup - Directories for input data
ensdir = '/home/scratch/users/stephan.rasp/' + args.date + '/deout_ceu_pspens/'
radarpref = '/project/meteo/w2w/A6/radolan/netcdf_cosmo_de/raa01-rw_10000-'
radarsufx = '-dwd---bin.nc'

# Analysis-specific setup
dx = 2800.  # Grid Spacing ATTENTION: Hard coded and wrong as of now

# Get analysis level
                    help='Recompute pre-processed files.')
parser.set_defaults(recompute=False)
args = parser.parse_args()

assert args.n_kernel % 2 == 1, 'n_kernel must be odd'
kernel = (np.ones((args.n_kernel, args.n_kernel)) / float(
    (args.n_kernel * args.n_kernel)))

# Loop over time
tstart = yyyymmddhhmmss_strtotime(args.date_ana_start)
tend = yyyymmddhhmmss_strtotime(args.date_ana_stop)
tint = timedelta(hours=1)
if tstart == tend:
    timelist = [tstart]
else:
    timelist = make_timelist(tstart, tend, tint)

# Set up figure
fig, axarr = plt.subplots(1, 2, figsize=(10, 6))

# Loop over experiments
expid_str = ''
exp_list = []
for ie, expid in enumerate(args.expid):
    print 'expid = ', expid
    expid_str += expid + '_'
    DATA_DIR = datadir + expid

    # Check if saved data is available
    savedir = savedir_base + expid + '/verif_ana_prec/'
    if not os.path.exists(savedir): os.makedirs(savedir)
def plot_prec_stamps(inargs):
    """
    Plots precipitation stamps of obs, det and ensemble every hour for each
    date and time specified

    Parameters
    ----------
    inargs : argparse object
      Argparse object with all input arguments

    """

    # Loop over dates
    for idate, date in enumerate(make_datelist(inargs)):
        print('Date ' + date)
        # Loop over times
        for t in make_timelist(timedelta(hours=inargs.time_start),
                               timedelta(hours=inargs.time_end),
                               timedelta(hours=1)):
            print('Time ' + str(t))
            # Load all CU objects
            fobjlist = []
            titlelist = []

            # 1st: Radar
            radarpref = (get_config(inargs, 'paths', 'radar_data') +
                         get_config(inargs, 'paths', 'radar_prefx'))
            radarsufx = get_config(inargs, 'paths', 'radar_sufix')
            dtradar = timedelta(minutes=10)

            radartime = yymmddhhmm(yyyymmddhh_strtotime(date) + t - dtradar)
            radarfn = radarpref + radartime + radarsufx
            radar_fobj = getfobj_ncdf(radarfn, fieldn='pr', dwdradar=True)
            # Crop data
            l11, l12, l21, l22, l11_rad, l12_rad, l21_rad, l22_rad = \
                get_domain_limits(inargs)
            l11_diff = l11_rad - l11
            l12_diff = l12_rad - l12
            l21_diff = l21_rad - l21
            l22_diff = l22_rad - l22
            radar_fobj.data = radar_fobj.data[l11_diff:l12_diff,
                                              l21_diff:l22_diff]
            radar_fobj.lats = radar_fobj.lats[l11_diff:l12_diff,
                                              l21_diff:l22_diff]
            radar_fobj.lons = radar_fobj.lons[l11_diff:l12_diff,
                                              l21_diff:l22_diff]
            fobjlist.append(radar_fobj)
            titlelist.append('Radar')

            # 2nd: det
            ncdffn_pref = (get_config(inargs, 'paths', 'raw_data') + date +
                           '/deout_ceu_pspens/' + 'det' + '/OUTPUT/lfff')
            fobjlist.append(
                getfobj_ncdf(ncdffn_pref + ddhhmmss(t) + '.nc_30m_surf',
                             'PREC_ACCUM'))
            titlelist.append('Det')

            # 3rd: ens
            ncdffn = 'lfff' + ddhhmmss(t) + '.nc_30m_surf'
            date_dir = (get_config(inargs, 'paths', 'raw_data') + date +
                        '/deout_ceu_pspens/')
            fobjlist.extend(
                getfobj_ncdf_ens(date_dir,
                                 'sub',
                                 inargs.nens,
                                 ncdffn,
                                 dir_suffix='/OUTPUT/',
                                 fieldn='PREC_ACCUM',
                                 nfill=1))
            titlelist.extend(
                ['Member ' + str(i + 1) for i in range(inargs.nens)])

            # Now plot
            n_panels = len(fobjlist)
            n_cols = 4
            n_rows = int(np.ceil(float(n_panels) / n_cols))

            pw = get_config(inargs, 'plotting', 'page_width')
            fig, axmat = plt.subplots(n_rows,
                                      n_cols,
                                      figsize=(pw, 3.0 * n_rows))
            axflat = np.ravel(axmat)

            for i in range(len(fobjlist)):
                plt.sca(axflat[i])
                cf = plot_stamp(inargs, fobjlist[i], cmPrec, levelsPrec,
                                axflat[i], 'PREC_ACCUM')
                axflat[i].set_title(titlelist[i])
            cb = fig.colorbar(cf,
                              cax=fig.add_axes([0.4, 0.15, 0.2, 0.02]),
                              orientation='horizontal')
            cb.set_label('Accumulation [mm/h]')
            titlestr = ((yyyymmddhh_strtotime(date) +
                         t).strftime('%d %b - %H UTC'))
            fig.suptitle(titlestr)
            plt.subplots_adjust(wspace=0.02, left=0.02, right=0.98)

            # Save figure and log
            save_fig_and_log(fig,
                             None,
                             inargs,
                             'prec_stamps',
                             datestr=((yyyymmddhh_strtotime(date) +
                                       t).strftime('%Y%m%d_%H')))
示例#4
0
def plot_prec_stamps(inargs):
    """
    Plots precipitation stamps of obs, det and ensemble every hour for each
    date and time specified
    
    Parameters
    ----------
    inargs : argparse object
      Argparse object with all input arguments

    """

    # TODO: Update colors
    cmPrec = ((1, 1, 1), (0, 0.627, 1), (0.137, 0.235, 0.98),
              (0.392, 0, 0.627), (0.784, 0, 0.627))
    # (0.1  , 0.1   , 0.784),
    levelsPrec = [0, 1, 3, 10, 30, 100.]

    # Loop over dates
    for idate, date in enumerate(make_datelist(inargs)):

        # Loop over times
        for t in make_timelist(timedelta(hours=inargs.time_start),
                               timedelta(hours=inargs.time_end),
                               timedelta(hours=1)):

            # Load all CU objects
            fobjlist = []
            titlelist = []

            # 1st: Radar
            fobjlist.append(get_and_crop_radar_fobj(inargs, date, t))
            titlelist.append('Radar')

            # 2nd: det
            ncdffn_pref = (get_config(inargs, 'paths', 'raw_data') + date +
                           '/deout_ceu_pspens/' + 'det' + '/OUTPUT/lfff')
            fobjlist.append(
                getfobj_ncdf(ncdffn_pref + ddhhmmss(t) + '.nc_30m_surf',
                             'PREC_ACCUM'))
            titlelist.append('Det')

            # 3rd: ens
            ncdffn = 'lfff' + ddhhmmss(t) + '.nc_30m_surf'
            date_dir = (get_config(inargs, 'paths', 'raw_data') + date +
                        '/deout_ceu_pspens/')
            fobjlist.extend(
                getfobj_ncdf_ens(date_dir,
                                 'sub',
                                 inargs.nens,
                                 ncdffn,
                                 dir_suffix='/OUTPUT/',
                                 fieldn='PREC_ACCUM',
                                 nfill=1))
            titlelist.extend(['Mem ' + str(i + 1) for i in range(inargs.nens)])

            # Now plot
            n_panels = len(fobjlist)
            n_cols = 4
            n_rows = int(np.ceil(float(n_panels) / n_cols))
            fig, axmat = plt.subplots(n_rows,
                                      n_cols,
                                      figsize=(10, 3.5 * n_rows))
            axflat = np.ravel(axmat)

            for i in range(len(fobjlist)):
                plt.sca(axflat[i])
                cf, tmp = ax_contourf(axflat[i],
                                      fobjlist[i],
                                      colors=cmPrec,
                                      pllevels=levelsPrec,
                                      ji0=(50 + inargs.zoom_lat1,
                                           50 + inargs.zoom_lon1),
                                      ji1=(357 - 51 + inargs.zoom_lat2,
                                           357 - 51 + inargs.zoom_lon2),
                                      sp_title=titlelist[i],
                                      Basemap_drawrivers=False,
                                      npars=0,
                                      nmers=0)
            cb = fig.colorbar(cf,
                              cax=fig.add_axes([0.4, 0.1, 0.2, 0.02]),
                              orientation='horizontal')
            cb.set_label('Accumulation [mm/h]')
        titlestr = (yyyymmddhh_strtotime(date).strftime(
            get_config(inargs, 'plotting', 'date_fmt')) + ' ' +
                    str(t.seconds / 3600).zfill(2) + 'UTC')
        fig.suptitle(titlestr)
        plt.tight_layout(rect=[0, 0.1, 1, 0.93])

        # Save figure and log
        save_fig_and_log(fig,
                         None,
                         inargs,
                         'prec_stamps',
                         date=date,
                         time=str(t.seconds / 3600).zfill(2))