How to use set_outdir method in tappy

Best Python code snippet using tappy_python

plottypes.py

Source:plottypes.py Github

copy

Full Screen

...36 except OSError as exc: # Python >2.537 if exc.errno == errno.EEXIST:38 pass39 else: raise40def set_outdir(plot_info,outdir,domain,datatype='field'):41 if plot_info == None:42 return None43 outdir_dom = os.path.join(outdir,44 plot_info['source_short'],45 str(plot_info['date']),46 suf3(plot_info['time'],suf=2),47 plot_info['shortname'],48 str(plot_info['level']),49 datatype,50 domain)51 return outdir_dom52def prec_plot(grib_index,grib_index_previous,source,map_list,outdir = './'):53 #print 'oprec_ploty',grib_index54 print 'intprec'55 intprec = get_grib_plotinfo(grib_index,settings.PCP_i,source)56 print 'accprec',settings.PCP_acc57 accprec = get_grib_plotinfo(grib_index,settings.PCP_acc,source)58 print 'accprec_prev'59 accprec_prev = get_grib_plotinfo(grib_index_previous,settings.PCP_acc,source)60 print 'intsnow'61 intsnow = get_grib_plotinfo(grib_index,settings.SNOW,source,par = 'int')62 print 'accsnow'63 accsnow = get_grib_plotinfo(grib_index,settings.SNOW,source)64 accsnow_prev = get_grib_plotinfo(grib_index_previous,settings.SNOW,source)65 intgraup = get_grib_plotinfo(grib_index,settings.GRAUP,source,par='int')66 accgraup = get_grib_plotinfo(grib_index,settings.GRAUP,source)67 accgraup_prev = get_grib_plotinfo(grib_index_previous,settings.GRAUP,source)68 #print intprec['values']; sys.exit(0)69 #print accprec['values']; sys.exit(0)70 71 totalprecint = None72 if None not in (intprec,intgraup,intsnow):73 totalprecint = intprec.copy()74 totalprecint['values'] = 3.6e3 * ( intprec['values'] * 1. + intgraup['values'] * 1. + intsnow['values'] )75 elif intprec is not None:76 totalprecint = intprec.copy()77 totalprecint['values'] = 3.6e3 * ( intprec['values']) 78 totalaccprec = None79 if accprec:80 totalaccprec = accprec.copy()81 totalaccsolid = accprec.copy()82 totalaccsolid['name'] = 'Solid precipitation'83 totalaccsolid['shortname'] = 'solid'84 if None not in (accprec_prev,accgraup_prev,accsnow_prev): 85 totalaccprec['values'] = accprec['values'] + accgraup['values'] + accsnow['values'] \86 - accprec_prev['values'] - accgraup_prev['values'] - accsnow_prev['values']87 88 totalaccsolid['values'] = accgraup['values'] + accsnow['values'] \89 - accgraup_prev['values'] - accsnow_prev['values']90 elif accgraup and accsnow:91 totalaccprec['values'] = accprec['values'] + accgraup['values'] + accsnow['values'] 92 totalaccsolid['values'] = accgraup['values'] + accsnow['values'] 93 elif accprec_prev is not None:94 totalaccprec['values'] = accprec['values'] - accprec_prev['values']95 totalaccsolid = None96 else:97 totalaccprec['values'] = accprec['values']98 totalaccsolid = None99 else:100 print 'No accprec? ',accprec,grib_index_previous; #sys.exit(0)101 for domain in map_list:102 outdir_dom = set_outdir(intprec,outdir,domain)103 contourplot(intprec,domain = domain,outdir = outdir_dom)104 if 0:105 outdir_dom = set_outdir(accprec,outdir,domain)106 contourplot(accprec,domain = domain,outdir = outdir_dom)107 108 if totalprecint:109 outdir_dom = set_outdir(totalprecint,outdir,domain)110 contourplot(totalprecint,domain = domain,outdir = outdir_dom)111 if totalaccprec:112 outdir_dom = set_outdir(totalaccprec,outdir,domain)113 contourplot(totalaccprec,domain = domain,outdir = outdir_dom)114 115 outdir_dom = set_outdir(totalaccsolid,outdir,domain)116 contourplot(totalaccsolid,domain = domain,outdir = outdir_dom)117 118 return 'Done'119def temp_plot(grib_index,source,map_list,outdir = './'):120 t2m = get_grib_plotinfo(grib_index,settings.T2M,source)121 try:122 t2m['values'] = t2m['values'] - 273.15123 except:124 print 'No temp output'125 return None126 relh = get_grib_plotinfo(grib_index,settings.RELH,source)127 for domain in map_list:128 outdir_dom = set_outdir(t2m,outdir,domain)129 contourplot(t2m,domain = domain,outdir = outdir_dom)130 return 0131def cloud_plot(grib_index,source,map_list,outdir = './'):132 clc = get_grib_plotinfo(grib_index,settings.CLOUD,source)133 brtemp = get_grib_plotinfo(grib_index,settings.BRTEMP,source) # 118 8 sfc 39680 0134 # process:135 try:136 brtemp['values'] = numpy.power( -1 * 17636684 * brtemp['values'], 1/4.) - 273.15137 except:138 print 'No brightness temperature output'139 for domain in map_list:140 outdir_dom = set_outdir(clc,outdir,domain)141 contourplot(clc,domain = domain,outdir = outdir_dom,lsmask_colour = 'red')142 outdir_dom = set_outdir(brtemp,outdir,domain)143 contourplot(brtemp,domain = domain,outdir = outdir_dom,lsmask_colour = 'red')144def vis_plot(grib_index,source,map_list,outdir = './',ftree = True):145 def take_lowest_ml(setting):146 mlset = copy.deepcopy(setting)147 mlset['leveltype'] = 109148 mlset['level'] = 60149 mlset['tr_ind'] = 0150 return mlset151 152 #print settings.PCP_acc153 #print type(settings.PCP_acc)154 #print take_lowest_ml(settings.PCP_acc)155 #print take_lowest_ml(settings.SNOW)156 #sys.exit(1)157 settings.PCP_acc['time'] = 'ml'158 settings.SNOW['time'] = 'ml'159 settings.GRAUP['time'] = 'ml'160 clwat = get_grib_plotinfo(grib_index,settings.CLWAT,source) 161 tpcp = get_grib_plotinfo(grib_index,take_lowest_ml(settings.PCP_acc),source,par = 'ml') 162 tsnow = get_grib_plotinfo(grib_index,take_lowest_ml(settings.SNOW),source,par = 'ml')163 tgraup = get_grib_plotinfo(grib_index,take_lowest_ml(settings.GRAUP),source,par = 'ml')164 if None in (clwat,tpcp,tsnow,tgraup):165 print 'No visibility output ',source['shortname'] 166 return None167 else:168 vis = clwat.copy()169 # # make sure that arguments of power are non-negative, using numpy.select170 dl = 0.171 #dl = 1.e-16172 extinction = (173 144.7 * numpy.power(numpy.select([clwat['values']<0.,clwat['values'] >=0],174 [dl,1.2e3*clwat['values']] ),0.88) + 175 1.1 * numpy.power(numpy.select([tpcp['values']<0.,tpcp['values']>=0],176 [dl,1.2e3*tpcp['values']]),0.75) +177 10.4 * numpy.power(numpy.select([tsnow['values']<0.,tsnow['values']>=0],178 [dl,1.2e3*tsnow['values']]),0.78) + 179 2.4 * numpy.power(numpy.select([tgraup['values']<0.,tgraup['values']>=0],180 [dl,1.2e3*tgraup['values']]),0.78)181 )182 183 vis['values'] = 1000.*3.912 / (extinction + dl) # -ln(0.02) * 1000 / extinction184 185 # get available plot settings186 vis = param_lists.set_plotsettings(settings.VIS,vis)187 188 for domain in map_list:189 if ftree:190 outdir_dom = set_outdir(vis,outdir,domain)191 contourplot(vis, domain = domain,outdir = outdir_dom)192 else:193 contourplot(vis, domain = domain,outdir = outdir)194def windplot(grib_index,source,map_list,outdir = './'):195 #from settings import U10,V10,UGST,VGST196 u10 = get_grib_plotinfo(grib_index,settings.U10,source)197 v10 = get_grib_plotinfo(grib_index,settings.V10,source)198 ugst = get_grib_plotinfo(grib_index,settings.UGST,source)199 vgst = get_grib_plotinfo(grib_index,settings.VGST,source)200 # from m/s to knots: 201 knotfactor = 1852/3600202 knotfactor = 3600./1852.203 totalwind,totalgust = None,None204 try:205 totalwind = u10.copy()206 totalwind = param_lists.set_plotsettings(settings.WIND,totalwind)207 except:208 print 'No wind output'209 return None210 totalwind['values'] = numpy.sqrt( u10['values']**2 + v10['values']**2 ) * knotfactor211 212 try: # only works if gust is in data files213 totalgust = ugst.copy()214 totalgust['values'] = numpy.sqrt( ugst['values']**2 + vgst['values']**2 )215 totalgust = param_lists.set_plotsettings(settings.GUST,totalgust)216 except:217 print 'ugst,vgst (162,163) not available'218 for domain in map_list:219 if totalwind:220 outdir_dom = set_outdir(totalwind,outdir,domain)221 contourplot(totalwind,domain = domain,outdir = outdir_dom)222 totalwind['shortname'] = 'windvector'223 outdir_dom = set_outdir(totalwind,outdir,domain )224 vectorplot(u10, v10, domain = domain,outdir = outdir_dom)225 if totalgust:226 outdir_dom = set_outdir(totalgust,outdir,domain)227 contourplot(totalgust,domain = domain,outdir = outdir_dom)228def hdf_plot(source,map_types,latestrun,outdir = './'):229 from verif.tools import h5tools230 if 'Radar' in source['model']:231 hdf_files = sorted( glob.glob( os.path.join(source['dir'],232 source['rexp'])) )233 # as above: choose all (hdf_files) or just the necessary (nhdf_files) files234 for h5file in hdf_files[-18:]:235 print 'opening ',h5file236 # do not put images in separate directory237 if 'Radar' in source['model']:238 path = os.path.join(outdir,'obs/radar') 239 elif 'MSG' in source['model']:240 path = os.path.join(outdir,'obs/msg')...

Full Screen

Full Screen

noscope_split.py

Source:noscope_split.py Github

copy

Full Screen

1import argparse2from functools import partial3import os4import pandas as pd5from shutil import copyfile6from tqdm import tqdm7def get_frame_vals(key, infile):8 df = pd.read_csv(args.infile)9 total_num_frames = max(df["frame"]) + 110 frames_with_key = df.loc[df["object_name"] == key]["frame"].unique()11 frames = [False] * total_num_frames12 for f in frames_with_key:13 frames[f] = True14 return frames15config = {16 "coral": {17 "frame_fn": partial(get_frame_vals, "person"),18 "fraction_split": 1/8,19 "start_split": 520 },21 "night": {22 "frame_fn": partial(get_frame_vals, "car"),23 "fraction_split": 1/8,24 "start_split": 125 },26 "roundabout": {27 "frame_fn": partial(get_frame_vals, "car"),28 "fraction_split": 1/8,29 "start_split": 130 },31 "taipei": {32 "frame_fn": partial(get_frame_vals, "bus"),33 "fraction_split": 1/16,34 "start_split": 035 }36 }37if __name__ == "__main__":38 parser = argparse.ArgumentParser()39 parser.add_argument("config", type=str, choices=config.keys(),40 help="NoScope configuration to use")41 parser.add_argument("outdir", type=str,42 help="Directory to write dataset to")43 parser.add_argument("--infile", type=str,44 default="coral-reef-long.csv",45 help="Input CSV file from NoScope")46 parser.add_argument("--indir", type=str,47 default="noscope-frames-all",48 help="Directory containing all NoScope frames")49 parser.add_argument("--print_stats", action="store_true",50 help="Whether to print fraction of frames with object")51 args = parser.parse_args()52 if not os.path.exists(args.infile):53 raise Exception("Input CSV file '{}' does not exist".format(args.indir))54 if not os.path.isdir(args.indir):55 raise Exception("Input directory '{}' does not exist".format(args.indir))56 cfg = config[args.config]57 fraction_split = cfg["fraction_split"]58 start_split = cfg["start_split"]59 num_splits = int(1 / fraction_split)60 if start_split > (num_splits - 3):61 raise Exception("Start split of {} is too high for set with {} splits".format(62 start_split, num_splits))63 frames = cfg["frame_fn"](args.infile)64 total_num_frames = len(frames)65 frames_per_split = int(total_num_frames * fraction_split)66 train_start = start_split * frames_per_split67 val_start = (start_split + 1) * frames_per_split68 test_start = (start_split + 2) * frames_per_split69 test_end = (start_split + 3) * frames_per_split70 train_frame_nos = (train_start, val_start)71 val_frames_nos = (val_start, test_start)72 test_frames_nos = (test_start, test_end)73 if not os.path.isdir(args.outdir):74 os.makedirs(args.outdir)75 dirs = [("train", train_frame_nos), ("val", val_frames_nos), ("test", test_frames_nos)]76 if args.print_stats:77 for name, frames_start_end in dirs:78 start, end = frames_start_end79 num_true = len([f for f in frames[start:end] if f])80 print(name, num_true / (end - start))81 for name, frames_start_end in dirs:82 set_outdir = os.path.join(args.outdir, name)83 if not os.path.isdir(set_outdir):84 os.makedirs(set_outdir)85 # Make the class subdirectories. 0 represents frames without the object86 # of interest. 1 represents those with the objeect of interest.87 dir0 = os.path.join(set_outdir, "0")88 dir1 = os.path.join(set_outdir, "1")89 if not os.path.isdir(dir0):90 os.makedirs(dir0)91 if not os.path.isdir(dir1):92 os.makedirs(dir1)93 # Iterate through each frame in the set, determine whether its class,94 # determine its location in the input dataset, and copy it to the95 # corresponding location in the output directory.96 for frame_no in tqdm(range(frames_start_end[0], frames_start_end[1])):97 if frames[frame_no]:98 class_outdir = dir199 else:100 class_outdir = dir0101 frame_in_path = os.path.join(args.indir, "{}.png".format(frame_no))102 frame_out_path = os.path.join(class_outdir, "{}.png".format(frame_no))...

Full Screen

Full Screen

dmtg.py

Source:dmtg.py Github

copy

Full Screen

1__doc__ = '''Module for DMTG (Draft Magic the Gathering) Globals'''2import os, sys3### Module Constants ###4card_colors = ['green', 'blue', 'red', 'white', 'black']5card_rarities = ['c', 'u', 'r', 'm']6base_dir = os.path.dirname(os.path.relpath(__file__))7lua_dir = os.path.join(os.path.dirname(base_dir), 'lmtg')8out_dir = os.path.join(os.path.dirname(base_dir), 'out')9tmpl_dir = os.path.join(os.path.dirname(base_dir), 'tmpl')10### Module Functions ###11def make_set_dirs(set_code):12 set_indir = os.path.join(out_dir, '%s-in' % set_code)13 set_outdir = os.path.join(out_dir, '%s-out' % set_code)14 for set_dir in (set_indir, set_outdir):15 if not os.path.exists(set_dir):16 os.makedirs(set_dir)17 return set_indir, set_outdir18def display_status(set_code, set_index, set_num):19 sys.stdout.write('\r')20 sys.stdout.write(' fetching %s %d/%d...' % (set_code, set_index+1, set_num))21 if set_index + 1 >= set_num: sys.stdout.write('\n')22 sys.stdout.flush()23def to_utf8(raw_text):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tappy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful