def runGridgen(cfginfo): """ Select and run gridgen actions based on .cfg file namelist """ if cfginfo['action'] == 'smcbase': # generate the base grid print('') print('*** Creating SMC base grid') basesmc = grd.createBasesmc(cfginfo['bathyfile'], cfginfo['extents'], cfginfo['dx'], cfginfo['dy'], name=cfginfo['name'], label=cfginfo['label'], mindepth=cfginfo['mindepth'], dlim=cfginfo['drydepthlim'], drymin=cfginfo['drypcmin'], drymax=cfginfo['drypcmax'], bathytype=cfginfo['bathytype'], getpland=cfginfo['getpcland'], setadj=cfginfo['setadj']) # write base grid file basefile = basesmc.writeNC(writedir=cfginfo['workdir']) # visualize the grid grd.plotGridsmc(basesmc, latlon=False) elif cfginfo['action'] == 'mark': # mark actions run through a loop to allow composite actions for lp, proc in enumerate(cfginfo['marklist']): if lp == 0: # load the parent grid print('') print('*** Loading SMC base grid') basefile = cfginfo[proc]['workdir'] + '/' + cfginfo[proc]['basefile'] basesmc = grd.loadNCsmc(basefile) print('') print('*** Marking cells for SMC grid') # marking actions if cfginfo[proc]['action'] == 'markdepths': basesmc.markDepths(cfginfo[proc]['depthlim'], marker=cfginfo[proc]['markertype']) elif cfginfo[proc]['action'] == 'markregion': basesmc.markRegion(cfginfo[proc]['extents'][0], cfginfo[proc]['extents'][1], cfginfo[proc]['extents'][2], cfginfo[proc]['extents'][3], marker=cfginfo[proc]['markertype'], depthlim=cfginfo[proc]['depthlim']) elif cfginfo[proc]['action'] == 'unmark': basesmc.unmarkCells(marker=cfginfo[proc]['markertype'], box=[cfginfo[proc]['extents'][0], cfginfo[proc]['extents'][1], cfginfo[proc]['extents'][2], cfginfo[proc]['extents'][3]], osbox=cfginfo[proc]['osbox'], thruzero=cfginfo[proc]['thruzero']) # deldry option removes dry cells as part of unmark action if cfginfo[proc]['deldry']: basesmc.delCells(celltype='dry') if lp == len(cfginfo['marklist'])-1: # write the marked grid after final marking action basesmc.label = cfginfo[proc]['label'] markfile = basesmc.writeNC(writedir=cfginfo[proc]['workdir']) # visualise the new marked grid grd.plotGridsmc(basesmc) elif cfginfo['action'] == 'tiergen': # load the parent grid print('') print('*** Loading SMC base grid') basefile = cfginfo['workdir'] + '/' + cfginfo['basefile'] basesmcrm = grd.loadNCsmc(basefile) # generate the new tier grid print('') print('*** Creating tier for SMC grid') tiersmc = grd.createTiersmc(cfginfo['bathyfile'], basesmcrm, label=cfginfo['label'], mindepth=cfginfo['mindepth'], dlim=cfginfo['drydepthlim'], drymin=cfginfo['drypcmin'], drymax=cfginfo['drypcmax'], bathytype=cfginfo['bathytype'], getpland=cfginfo['getpcland'], setadj=cfginfo['setadj'], deldry=cfginfo['deldry']) # save the new tier grid tierfile = tiersmc.writeNC(writedir=cfginfo['workdir']) # visualise the new tier grid grd.plotGridsmc(tiersmc) elif cfginfo['action'] == 'tiercombine': # load the parent grid print('') print('*** Loading SMC base grid') basefile = cfginfo['workdir'] + '/' + cfginfo['basefile'] basesmcrm = grd.loadNCsmc(basefile) # load the tier print('') print('*** Loading SMC tier') tierfile = cfginfo['workdir'] + '/' + cfginfo['tierfile'] tiersmc = grd.loadNCsmc(tierfile) # combine the grids print('') print('*** Combining tier and base') combbaset = grd.joinTiersmc(basesmcrm, tiersmc, cfginfo['bathyfile'], tiernext=cfginfo['tiernext']) combbaset.label = cfginfo['label'] # save the combined grid combbasetfile = combbaset.writeNC(writedir=cfginfo['workdir']) # visualise the grid grd.plotGridsmc(combbaset, latlon=False) elif cfginfo['action'].lower() == 'writeww3': # load the grid for writing to ww3 format print('') print('*** Loading combined grid') gridfile = cfginfo['workdir'] + '/' + cfginfo['gridfile'] combsmc = grd.loadNCsmc(gridfile) # remove any dry cells from the grid print('') print('*** Removing dry cells') combsmc.delCells(celltype='alldry') # visualize the grid grd.plotGridsmc(combsmc, latlon=True) # write out ww3 format files print('') print('*** Writing smc cells to text file') combsmc.sortCells() combsmc.writeWW3(writedir=cfginfo['writedir'], mindepth=cfginfo['mindepth'], writemindepth=cfginfo['writemindepth'], arctic=cfginfo['arctic'], arclat=cfginfo['arclat']) return
writedir = '/project/ofrd/waves/wavegrids/atlantic/grid_netCDF' project = 'atlantic' #---- # generate the first SMC tier if gentier: print('') print('*** Loading SMC base grid') basesmcrm = grd.loadNCsmc(writedir+'/atlantic_AS512L1EUK.nc') # visualise the grid grd.plotGridsmc(basesmcrm,latlon=False) print('') print('*** Creating tier for SMC grid') tier1smc = grd.createTiersmc(bathyfile, basesmcrm, label='AS512L2EUK-sub', mindepth=None, dlim=3.0, drymin=None, drymax=0.7, bathytype='gebco', getpland=True) # save the grid tier1file = tier1smc.writeNC(writedir=writedir) print('Data written to %s' %tier1file) # visualise the grid grd.plotGridsmc(tier1smc) #--- # combined the (cropped) basegrid and tier1 if combtier: print('') print('*** Loading SMC base grid') basesmcrm = grd.loadNCsmc(writedir+'/atlantic_AS512L1EUK.nc') # visualise the grid grd.plotGridsmc(basesmcrm,latlon=False)