def run(fov_idx, dir_lbl=os.path.join(DIR_PROD, 'LBL-RTM'), file_seg=None, label='hs3', **kwargs): ''' idx defines which profile index to run simulation on ''' from lblrtm_utils import run_lblrtm_profile from hs3_utils import Flight_segment import pickle #_read in run options file_kwarg = os.path.join(dir_lbl, 'kwarg_lblrtm.pk') kw = pickle.load(open(file_kwarg, 'rb')) #_read in flight data flight = Flight_segment(file_seg=file_seg, **kwargs) #_output and run directory label = '{3:s}_{1:s}.{2:s}_fov{0:06d}'.format(fov_idx, flight.dtg0, flight.dtg1, label) path_out = os.path.join(dir_lbl, label) src = kwargs.get('profile_source', 'GDAS') pressure = flight.__getattribute__('{0}_pressure'.format(src)) kwargs.update({ 'label': label, 'dir_lblrtm_out': path_out, 'pressure': pressure }) kwargs.update(kw) #_run lblrtm from profile profile = flight[fov_idx] run_lblrtm_profile(profile, h1=profile.SHIS_altitude, **kwargs) return 0
def lbldis_hs3(fov_idx, kw_idx, fname, kname, path_hs3=DIR_HS3, experiment='hs3', **kwargs): ''' submission script for running with defined r_eff, optical depth and layer height ''' from lblrtm_utils import run_lbldis from hs3_utils import Flight_segment import pickle #_read in flight options flight = Flight_segment(file_seg=fname) #_read in run options file_kwarg = os.path.join(path_hs3, kname) kw = pickle.load(open(file_kwarg, 'rb'))[kw_idx] #_pull out cloud info if present for labeling if 'clddef' in kw: clddef = kw['clddef'] ref = clddef[0]['r_eff'] aod = clddef[0]['tau'][0] zkm = [clddef[0]['z'], clddef[0]['z_top']] else: ref, aod, zkm = 0., 0., [0., 0.] #_output and run directory lblrtm_out = kw['dir_lblrtm_fmt'].format(fov_idx, flight.dtg0, flight.dtg1, experiment) run_lbldis(lblrtm_out, **kw) ###_run_lbldis(lblrtm_out, out_lbldis=out_lbldis, **kw) return 0
if 0: #_WITH RETRIEVALS ppath = namelist.get('dir_plot') namelist.update( {' dir_plot': os.path.join(ppath, out_label, 'DASHBOARD')}) for dtg, values in segments.iteritems(): #_plot comparisons between OD from SHIS and CPL # SEPARATE! CANNOT RUN WITH real_case_qsub() dbg(dtg) final = 'lbldis_output.{0}.final.cdf'.format(out_label) clear = 'lbldis_output.{0}.clear.cdf'.format(out_label) namelist.update({ 'lbldis_output': final, 'lbldis_clear': clear, }) namelist.update(values) flight = Flight_segment(dtg) flight.plot(**namelist) #_replot everything if 0: #_GENERATE SUMMARY for out_label in out_labels: for dtg, values in segments.iteritems(): namelist['dtg'] = dtg final = 'lbldis_output.{0}.final.cdf'.format(out_label) clear = 'lbldis_output.{0}.clear.cdf'.format(out_label) namelist.update({ 'lbldis_output': final, 'lbldis_clear': clear, 'out_label': out_label }) namelist.update(values)
def run_main(dtg='', **kwargs): from libtools import dummy_sbatch from hs3_utils import Flight_segment flight = Flight_segment(dtg) flight.plot(**kwargs)
#!/usr/bin/env python #_wrapper to plot all flight segments with COLLOC files import os from glob import glob from hs3_utils import Flight_segment import re re_dtg = re.compile('COLLOC.(\d{12}).') #dir_col = os.path.join(os.environ['PRODUCTS'], 'tc4') dir_col = os.path.join(os.environ['PRODUCTS'], 'hs3') files = glob(dir_col + '/*COLLOC*nc') kwargs = {'nproc' : 20, 'out_label' : 'FLIGHT-ONLY-JULY01'} files.sort() for fname in files: dtg = '20{0}'.format(re_dtg.search(fname).group(1)) ## if dtg < '20130825000000': ## print 'ALREADY DONE', dtg ## continue flight = Flight_segment(file_seg=fname) try: flight.plot_flight(dir_out=dir_col, **kwargs) except: os.system('echo {0} >> PLOT_ALL.err'.format(fname))
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()