def show_files(files): dset = sum_arrays_from_files(files) plt.figure(figsize=[11,5]) print np.max(dset['nprof']) for i,layer in enumerate(['low', 'mid', 'high', 'total']): nprof = dset['nprof'] cprof = dset[vcm_name + '_cprof_' + layer] cf = np.ma.masked_invalid(100. * cprof.values / nprof.values) plt.subplot(2,2,i+1) pcolor_cf(cprof.lon, cprof.lat, cf, title=layer, label='Cloud Fraction [%]') plt.suptitle(files) plt.savefig('maps.png') plt.figure(figsize=[11,4]) for i, layer in enumerate(['low', 'mid', 'high', 'total']): nprof = dset['nprof'].sum('lon') cprof = dset[vcm_name + '_cprof_' + layer].sum('lon') cf = np.ma.masked_invalid(100. * cprof.values / nprof.values) plt.plot(cprof.lat, cf, lw=0.5, label=layer) plt.ylabel('Cloud Fraction [%]') plt.xlabel('Latitude') plt.xlim(-90, 90) plt.xticks(np.r_[-90:120:30]) plt.ylim(0, 100) plt.grid() plt.legend() plt.savefig('zonal.png')
def show_files(files): dset = sum_arrays_from_files(files) plt.figure(figsize=[11, 5]) print np.max(dset['nprof']) for i, layer in enumerate(['low', 'mid', 'high', 'total']): nprof = dset['nprof'] cprof = dset[vcm_name + '_cprof_' + layer] cf = np.ma.masked_invalid(100. * cprof.values / nprof.values) plt.subplot(2, 2, i + 1) pcolor_cf(cprof.lon, cprof.lat, cf, title=layer, label='Cloud Fraction [%]') plt.suptitle(files) plt.savefig('maps.png') plt.figure(figsize=[11, 4]) for i, layer in enumerate(['low', 'mid', 'high', 'total']): nprof = dset['nprof'].sum('lon') cprof = dset[vcm_name + '_cprof_' + layer].sum('lon') cf = np.ma.masked_invalid(100. * cprof.values / nprof.values) plt.plot(cprof.lat, cf, lw=0.5, label=layer) plt.ylabel('Cloud Fraction [%]') plt.xlabel('Latitude') plt.xlim(-90, 90) plt.xticks(np.r_[-90:120:30]) plt.ylim(0, 100) plt.grid() plt.legend() plt.savefig('zonal.png')
def main(year, window=40, step=1, indir='out.daily'): import glob import os year = int(year) start = datetime(year, 1, 1) end = datetime(year + 1, 1, 1) current = start outdir = 'out.{:02d}'.format(window) if not os.path.isdir(outdir): print 'Creating ' + outdir os.mkdir(outdir) while current < end: # create list of files for current averaging window c = current - timedelta(days=window / 2) this_end = current + timedelta(days=window / 2) files = [] while c < this_end: this_mask = indir + '/{:04d}{:02d}/cflon_{:04d}-{:02d}-{:02d}*.nc4'.format( c.year, c.month, c.year, c.month, c.day) files += glob.glob(this_mask) c += timedelta(days=1) if len(files) == 0: print 'no dailies for {:04d}{:02d}, skipping'.format( c.year, c.month) current += timedelta(weeks=step) continue # average files aggregated = sum_arrays_from_files(files, [vcm_name + '_cprof', 'nprof']) # create output filename fulloutdir = outdir + '/{:04d}/'.format(year) if not os.path.isdir(fulloutdir): os.mkdir(fulloutdir) outname = 'cf_%04d%02d%02d.nc4' % (current.year, current.month, current.day) outpath = fulloutdir + outname print('Saving to ' + outpath) aggregated.write_nc(outpath, 'w') current += timedelta(weeks=step)
def show_files(files, title): dset = vcm.sum_arrays_from_files(files) nprof = dset['nprof'] cprof = dset['cal333+cal05+cal20+cal80+csat'] cf_lat = np.ma.masked_invalid(100. * cprof.values.T / nprof.values) cf_lat = cf_lat.T if title is None: if '*' in files: title = files else: title = files[0] title = 'Cloud fraction ' + title pcolor_cf(cprof.lat, cprof.altitude, cf_lat, title) plt.savefig(title + '.png')
def main(year, window=40, step=1, indir='out.daily'): import glob import os year = int(year) start = datetime(year, 1, 1) end = datetime(year+1, 1, 1) current = start outdir = 'out.{:02d}'.format(window) if not os.path.isdir(outdir): print 'Creating ' + outdir os.mkdir(outdir) while current < end: # create list of files for current averaging window c = current - timedelta(days=window/2) this_end = current + timedelta(days=window/2) files = [] while c < this_end: this_mask = indir + '/{:04d}{:02d}/cflon_{:04d}-{:02d}-{:02d}*.nc4'.format(c.year, c.month, c.year, c.month, c.day) files += glob.glob(this_mask) c += timedelta(days=1) if len(files)==0: print 'no dailies for {:04d}{:02d}, skipping'.format(c.year, c.month) current += timedelta(weeks=step) continue # average files aggregated = sum_arrays_from_files(files, [vcm_name + '_cprof', 'nprof']) # create output filename fulloutdir = outdir + '/{:04d}/'.format(year) if not os.path.isdir(fulloutdir): os.mkdir(fulloutdir) outname = 'cf_%04d%02d%02d.nc4' % (current.year, current.month, current.day) outpath = fulloutdir + outname print('Saving to ' + outpath) aggregated.write_nc(outpath, 'w') current += timedelta(weeks=step)