def goes_codes( dtg ): ''' Returns goes east and west codes based upon dtg dtg : str*10, date time group of interest Just having it loop instead.... if they're there, they're there ''' epoch = lt.dtg2epoch( dtg ) if epoch < lt.dtg2epoch('2003021300'): #_2000.09.01 to 2003.02.13 code_east = 'g8' code_west = 'g10' elif epoch < lt.dtg2epoch('2006062600'):#_2003.02.13 to 2006.06.26 code_east = 'g12' code_west = 'g10' elif epoch < lt.dtg2epoch('2010040100'):#_2006.06.26 to 2010.04.01 code_east = 'g12' code_west = 'g11' elif epoch < lt.dtg2epoch('2011120600'):#_2010.04.01 to 2011.12.06 code_east = 'g13' code_west = 'g11' elif epoch < lt.dtg2epoch('2012092400'):#_2011.12.06 to 2012.09.24 code_east = 'g13' code_west = 'g15' elif epoch < lt.dtg2epoch("2012102300"):#_2012.09.24 to 2012.10.23 code_east = 'g14' code_west = 'g15' else: #epoch < lt.dtg2epoch('2030120600') #_2012.10.23 to ??? code_east = 'g13' code_west = 'g15' return code_west, code_east
def _get_time_bounds(fcdf): ''' open netcdf file and get start and end times ''' from netCDF4 import Dataset from libtools import julian2dtg, dtg2epoch, epoch2dtg with Dataset(fcdf, 'r') as cdf: jday = cdf.variables['Jday'][0] year = cdf.variables['Year'][0] time = cdf.variables['Time'][:] #_convert from julian to dtg dtg = julian2dtg(year, jday) ymd = dtg[2:-2] #_get start and end times epoch = dtg2epoch(dtg) + (time - jday) * 86400 start = epoch2dtg(epoch.min(), full=True)[-6:] final = epoch2dtg(epoch.max(), full=True)[-6:] return ymd, start, final
def read_exp2(aod_thresh=0.5, **kwargs): from libtools import epoch2dtg, dtg2epoch, subset, unique from numpy import vstack #_read icap data icap = read_forecasts(**kwargs) #_read GDAS data at same times dust = subset(icap, variable='dust_aod', fhr=24) #_drop missing values iiii = vstack(dust.values).mean(axis=1) dust = dust[iiii>0.5] #_get gdas dtgs = epoch2dtg(dust.epoch) gdas = read_GDASGRIB(dtgs=dtgs, **kwargs) #_limit to when times are same dust = subset(dust, epoch=dtg2epoch(gdas.dtg)) return dust, gdas
def main(dir_cpl='{0}/cpl'.format(os.environ['PRODUCTS']), start_dtg=None, dir_plot='.', end_dtg=None, type_coa='a', **kwargs): ''' start_dtg str{14}, Starting date-time-group for subsetting end_dtg str{14}, Can you solve the mystery? ''' from glob import glob from hs3_utils import Flight_segment import matplotlib.pyplot as plt from libtools import shrink_ticks, epoch2iso, dtg2epoch, mkdir_p from numpy import arange, array, ceil, linspace from numpy.ma import mean from libcmap import rgbcmap from flight_namelists import experiments mkdir_p(dir_plot) #_get segments segments = experiments['HS3'] #_convert bounding limits if start_dtg is not None: ep0 = dtg2epoch(start_dtg, full=True) ep1 = dtg2epoch(end_dtg, full=True) else: ep0 = '19000101000000' ep1 = '99999999999999' #_image setup smooth = False label = 'nosmooth' files = glob('{0}/nc/*nc'.format(dir_cpl)) files.sort() nrow = 6 ncol = 2 npag = ceil(len(files) / (nrow/ncol)) calipso = rgbcmap('calipso') dtgs = segments.keys() dtgs.sort() #_loop over all cpl files (netcdf) # for i, fname in enumerate(files): for i, dtg in enumerate(dtgs): #_start new page if not i % (nrow*ncol): fig = plt.figure() fig.suptitle('CPL 532 Backscatter', size='small') #_calc column index #_calc row index ax_backscatter = fig.add_subplot(nrow, ncol, i%(nrow*ncol)+1) ax = ax_backscatter.twinx() #_read in cpl data # cpl = read_cpl(f, None) cpl = Flight_segment(dtg=dtg) #_check if file is within limits if cpl.CPL_epoch.min() > ep1 and cpl.CPL_epoch.max() < ep0: continue #_get values of just aerosl aod = calc_aod(cpl, type_coa) bck = calc_backscatter(cpl) if smooth: aod = smooth_aod(aod) #_generate list of times time = [epoch2iso(e) for e in cpl.CPL_epoch] #_get number of fovs nfov = aod.size nt = nfov / 2 ax.set_xticks(arange(aod.size)[nt:-nt:nt]) ax.set_xticklabels(time[nt:-nt:nt]) ax.xaxis.set_visible(False) props = dict(boxstyle='round', facecolor='white', alpha=.5) # ax.text(nt/4., 3, f, color='k', size='x-small', bbox=props) f = '{0} - {1}'.format(time[0], time[-1]) ax.text(nt/4., .75, f, color='k', size='xx-small', bbox=props) ax.set_ylim(0, 1) #_plotbackscatter cb=ax_backscatter.pcolormesh(bck,vmin=-4e-7,vmax=1e-4,cmap=calipso, zorder=0) ax.plot(aod, linewidth=0.2, zorder=1, color=(1,1,1,.5)) if i % ncol: # ax.set_ylabel('aod', size='xx-small') ax_backscatter.yaxis.set_visible(False) elif not i % ncol: ax.yaxis.set_visible(False) xlim=ax_backscatter.xaxis.get_data_interval() ax_backscatter.set_xlim(xlim) ax_backscatter.set_yticks(linspace(170,900,9)) ax_backscatter.set_yticklabels(linspace(0,20,9)) ax_backscatter.set_ylim(170,900) shrink_ticks(ax) shrink_ticks(ax_backscatter) #_I think this is bailing if (i % (nrow*ncol)) == ((nrow*ncol) - 1): page_num = i / (nrow*ncol) pname = 'page_{1}_{0:02d}_{2}OD_segments.png'.format(page_num, label, type_coa) pname = os.path.join(dir_plot, pname) print pname #_make a common y label fig.text(0.04, 0.5, 'altitude (km)', va='center', rotation='vertical', size='x-small') fig.text(0.96, 0.5, '{0}OD'.format(type_coa.upper()), va='center', rotation=270, size='x-small') fig.savefig(pname) plt.close() #_after everything is done else: page_num = i / (nrow*ncol) pname = 'page_{1}_{0:02d}_{2}OD_segments.png'.format(page_num, label, type_coa) pname = os.path.join(dir_plot, pname) print pname #_make a common y label fig.text(0.04, 0.5, 'altitude (km)', va='center', rotation='vertical', size='x-small') fig.text(0.96, 0.5, 'AOD', va='center', rotation=270, size='x-small') fig.savefig(pname) plt.close()
# DATE 2016.04.28 # PURPOSE Look at some of this shit. import os import sys from libtools import dtg2epoch, dbg if 'DISPLAY' not in os.environ: import matplotlib matplotlib.use('Agg') namelist = { 'out_label' : 'NVACLIMO1_tau-ref_M2_DV28_CLD_NOCTP_ATP-NAAPS_3KM', #_start and end times for period 'e0' : dtg2epoch('2013082400'), 'e1' : dtg2epoch('2013082500'), #_location of collocation files 'dir_colloc' : os.path.join(os.environ['PRODUCTS'], 'colloc'), #_name of experiment used in determining lblrtm location 'dir_lblrtm_fmt' : os.path.join(os.environ['PRODUCTS'], 'LBL-RTM','{0}_{1}'), 'experiment' : 'AIRSCAL', #_bounding box of interest 'latlon' : [-30, 30, -90, 20], #_What to put into comparison
def main(dir_cpl='{0}/cpl'.format(os.environ['PRODUCTS']), start_dtg=None, dir_plot='.', end_dtg=None, **kwargs): ''' start_dtg str{14}, Starting date-time-group for subsetting end_dtg str{14}, Can you solve the mystery? ''' from glob import glob from hs3_utils import read_cpl import matplotlib.pyplot as plt from libtools import shrink_ticks, epoch2iso, dtg2epoch, mkdir_p from numpy import arange, array, ceil, linspace from numpy.ma import mean from libcmap import rgbcmap mkdir_p(dir_plot) #_convert bounding limits if start_dtg is not None: ep0 = dtg2epoch(start_dtg, full=True) ep1 = dtg2epoch(end_dtg, full=True) else: ep0 = '19000101000000' ep1 = '99999999999999' #_image setup smooth = False label = 'nosmooth' files = glob('{0}/nc/*nc'.format(dir_cpl)) files.sort() nrow = 6 npag = ceil(len(files) / nrow) calipso = rgbcmap('calipso') #_loop over all cpl files (netcdf) i = 0 for q, fname in enumerate(files): f = fname.split('/')[-1] #_read in cpl data cpl = read_cpl(f, None) #_check if file is within limits if cpl.epoch.min() > ep1 or cpl.epoch.max() < ep0: continue #_start new page if not i % nrow: fig = plt.figure() ax_backscatter = fig.add_subplot(nrow, 1, i % nrow + 1) ax = ax_backscatter.twinx() print 'MADE IT' #_get values of just aerosl aod = calc_aod(cpl) bck = calc_backscatter(cpl) if smooth: aod = smooth_aod(aod) #_generate list of times time = [epoch2iso(e) for e in cpl.epoch] #_get number of fovs nfov = aod.size nt = nfov / 5 ax.set_xticks(arange(aod.size)[nt:-nt:nt]) ax.set_xticklabels(time[nt:-nt:nt]) props = dict(boxstyle='round', facecolor='white', alpha=.5) ax.text(nt / 4., 3, f, color='k', size='x-small', bbox=props) ax.set_ylim(0, 4) #_plotbackscatter cb = ax_backscatter.pcolormesh(bck, vmin=-4e-7, vmax=1e-4, cmap=calipso, zorder=0) ax.plot(aod, linewidth=0.2, zorder=1, color=(1, 1, 1, .5)) ax.set_ylabel('aod', size='xx-small') xlim = ax_backscatter.xaxis.get_data_interval() ax_backscatter.set_xlim(xlim) ## ax_backscatter.set_ylim(0,900) ax_backscatter.set_yticks(linspace(170, 900, 11)) ax_backscatter.set_yticklabels(linspace(0, 20, 11)) ax_backscatter.set_ylim(170, 900) shrink_ticks(ax) shrink_ticks(ax_backscatter) i += 1 if (i % nrow) == (nrow - 1): page_num = i / nrow pname = 'page_{1}_{0:02d}_0.png'.format(page_num, label) pname = os.path.join(dir_plot, pname) print pname #_make a common y label fig.text(0.04, 0.5, 'altitude (km)', va='center', rotation='vertical', size='x-small') fig.savefig(pname) plt.close() else: page_num = i / nrow pname = 'page_{1}_{0:02d}_0.png'.format(page_num, label) pname = os.path.join(dir_plot, pname) print pname #_make a common y label fig.text(0.04, 0.5, 'altitude (km)', va='center', rotation='vertical', size='x-small') fig.savefig(pname) plt.close()