def importLEV(self): file_name = QFileDialog.getOpenFileName(self, "Load nlev.gr3 file", "", "SCHSIM grid file(*.gr3)") self.nlev = Hgrid.open(str(file_name)) self.change_nlev() self.draw_map() self.draw_vgrid()
def open(hgrid: Union[str, os.PathLike], fgrid: Union[str, os.PathLike], vgrid: os.PathLike = None, hgrid_crs: Union[str, CRS] = None, fgrid_crs: Union[str, CRS] = None): """Open files from disk""" return ModelDomain(Hgrid.open(hgrid, hgrid_crs), Vgrid.open(vgrid) if vgrid is not None else Vgrid(), Fgrid.open(fgrid, fgrid_crs))
def __init__(self, args: Namespace): if args.sub_action == 'generate': outdir = args.out_dir if not outdir: outdir = Path(args.hgrid).parent outdir = Path(outdir) hgrid = Hgrid.open(args.hgrid, crs=args.hgrid_crs) if args.constant is not None: mann_obj = ManningsN.constant(hgrid, args.constant) elif args.linear is not None: # NOTE: args.linear can be empty list in which case # we need to use defaults keys = ["min_value", "max_value", "min_depth", "max_depth"] linear_args = { keys[i]: val for i, val in enumerate(args.linear) } mann_obj = ManningsN.linear_with_depth(hgrid, **linear_args) for i, (shpfile, value) in enumerate(args.region_specific): try: shpfile = Path(shpfile) except TypeError: raise TypeError(f"Invalid input type ({type(value)}) for" f" region shapefile path") try: value = float(value) except ValueError: raise TypeError(f"Invalid input type ({type(value)}) for" f" constant value across region") gdf = gpd.read_file(shpfile) if gdf.crs and mann_obj.crs and not gdf.crs.equals( mann_obj.crs): gdf = gdf.to_crs(mann_obj.crs) multipolygon = gdf.unary_union if not isinstance(multipolygon, (Polygon, MultiPolygon)): raise ValueError(f"Invalid input shape for region {i}") mann_obj.add_region(multipolygon, value) mann_obj.write(outdir / 'manning.gr3', overwrite=args.overwrite) return raise NotImplementedError(f'Unhandled CLI action: {args.action}.')
def __init__(self, app): QMainWindow.__init__(self) Ui_MainWindow.__init__(self) self.setupUi(self) self.bot_layer_thickness.valueChanged.connect(self.refresh_it_all) self.avqs0.valueChanged.connect(self.refresh_it_all) self.sigma_type.currentChanged.connect(self.refresh_it_all) self.thetab.valueChanged.connect(self.refresh_it_all) self.thetaf.valueChanged.connect(self.refresh_it_all) self.rtheta_b.valueChanged.connect(self.refresh_it_all) self.rtheta_s.valueChanged.connect(self.refresh_it_all) self.tcline.valueChanged.connect(self.refresh_it_all) self.vstreching.activated.connect(self.refresh_it_all) self.rutgers.toggled.connect(self.refresh_it_all) self.hsm.returnPressed.connect(self.refresh_it_all) self.nv_vqs.returnPressed.connect(self.refresh_it_all) self.thetaf_exp.returnPressed.connect(self.refresh_it_all) self.thetab_exp.returnPressed.connect(self.refresh_it_all) self.import_vgrid.triggered.connect(self.importV) self.import_nlev.triggered.connect(self.importLEV) self.import_hgrid.triggered.connect(self.importH) self.export_vgrid.triggered.connect(self.exportV) self.export_vgrid_params.triggered.connect(self.exportVparams) self.export_trs.triggered.connect(self.exportTRS) self.export_nlev.triggered.connect(self.exportLEV) self.Xtrs = [] self.Ytrs = [] self.Ztrs = [] self.Ntrs = [] self.nlev = [] self.gr = Hgrid.open(os.path.expanduser(app.arguments()[1])) self.gr.values[:] = self.gr.values[:] * -1. self.nlev = copy.deepcopy(self.gr) self.nlev.values[:] = self.nlev.values[:] * 0 self.create_transect() #self.hsm.setText('0:%i:50'% (np.ceil(self.gr.mesh.nodes[:,2].max())+50)) self.hsm.setText('2 12 22 32 42 52 62 72 82 200 2000') self.vgrid = self.create_vgrid(maxdepth=np.ceil(self.gr.values.max()), hsm=self.get_hsm(self.hsm.text())) self.vgrid.compute_zcor(self.gr.values, a_vqs0=-0.3, opt=1) self.nlev.values[:] = self.vgrid.kbp[:, 0] self.vgrid.extract_trs(self.Xtrs, self.Ytrs, self.Ntrs) self.create_main_frame() self.create_vertical_frame() self.draw_map() self.draw_vgrid()
def plot_hgrid(args): hgrid = Hgrid.open(args.path, crs=args.crs) ax = None if not args.no_topobathy: ax = hgrid.make_plot( vmin=args.vmin, vmax=args.vmax, ) if args.show_elements: ax = hgrid.triplot(axes=ax) # if args.plot_boundaries: # hgrid.plot_boundaries(axes=ax) plt.show()
def process(filein, hgrid_file, var, epsg, T, L): nd, ne, ns, nc, v = read_hotstart(filein, var) gr = Hgrid.open(hgrid_file, crs="EPSG:%i" % epsg) #gr = load_g3(os.path.expanduser()) Easting = gr.x Northing = gr.y elems = gr.elements.elements Face = numpy.ndarray((len(elems), 3)) for elem_i, elem in enumerate(elems.keys()): Face[elem_i] = [int(x) - 1 for x in elems[elem][:-1]] # gr=build_edges_from_elems(gr) # gr.xs,gr.ys=build_edgecenters(gr) # Side= numpy.array([edge[:2] for edge in gr.mesh._edges]) if len(v.shape) == 1: #node Z = v[:] elif len(v.shape) == 2: if v.shape[0] == ne: #elem + vert Ze = v[:, L] Z = np.zeros((nd)) for i in range(0, len(Face)): Z[Face[i]] = Ze[i] elif v.shape[0] == ns: # side +vert Ze = v[:, L] Z = np.zeros((nd)) for i in range(0, len(Side)): Z[Side[i]] = Ze[i] elif v.shape[0] == nd: #node + vert Z = v[:, L] else: if v.shape[0] == ne: #elem + vert Ze = v[:, L, T] Z = np.zeros((nd)) for i in range(0, len(Face)): Z[Face[i]] = Ze[i] elif v.shape[0] == nd: #node + vert Z = v[:, L, T] plot2D(Easting, Northing, Face, Z, var)
def test_open(self): tmpfile = tempfile.NamedTemporaryFile() with open(tmpfile.name, 'w') as f: f.write('\n') f.write(f'{len(self.elements):d} ') f.write(f'{len(self.nodes):d}\n') for id, ((x, y), z) in self.nodes.items(): f.write(f"{id} ") f.write(f"{x} ") f.write(f"{y} ") f.write(f"{z}\n") for id, geom in self.elements.items(): f.write(f"{id} ") f.write(f"{len(geom)} ") for idx in geom: f.write(f"{idx} ") f.write(f"\n") self.assertIsInstance(Hgrid.open(tmpfile.name), Hgrid)
def process(filein, hgrid_file, var, epsg, T, L): nd, nc, v = read_nudge(filein, var) gr = Hgrid.open(hgrid_file, crs="EPSG:%i" % epsg) #gr = load_g3(os.path.expanduser()) Easting = gr.x Northing = gr.y elems = gr.elements.elements Face = numpy.ndarray((len(elems), 3)) for elem_i, elem in enumerate(elems.keys()): Face[elem_i] = [int(x) - 1 for x in elems[elem][:-1]] # gr=build_edges_from_elems(gr) # gr.xs,gr.ys=build_edgecenters(gr) # Side= numpy.array([edge[:2] for edge in gr.mesh._edges]) Z = v[0, :, L, -1] plot2D(Easting, Northing, Face, Z, var)
def __init__(self, args: Namespace): # logging.basicConfig(level=logging._nameToLevel[args.log_level.upper()]) root_logger = logging.getLogger() root_logger.setLevel(logging._nameToLevel[args.log_level.upper()]) _logger.setLevel(logging._nameToLevel[args.log_level.upper()]) _logger.info(f'Open hgrid file: {args.hgrid}') start = time() hgrid = Hgrid.open(args.hgrid, crs=args.hgrid_crs) _logger.info(f'Reading hgrid file took {time()-start} seconds.') bctides = Bctides( hgrid, args.start_date, args.run_days, tidal_database=args.tidal_database, velocity=args.include_velocity, ) if args.Z0 is not None: bctides.Z0 = args.Z0 if args.output_file is not None: bctides.write(args.output_file, overwrite=args.overwrite) else: print(str(bctides))
def load_mesh(self, filgrid): hgrid = Hgrid.open(filgrid, crs="EPSG:%i" % 2193) return hgrid
def load_mesh(self,filgrid,epsg): hgrid = Hgrid.open(filgrid,crs="EPSG:%i" % epsg) return hgrid
mkdir -p outputs time srun pschism_TVD-VL } main """ # https://eev.ee/blog/2012/05/23/python-faq-descriptors/ PARENT = pathlib.Path(__file__).parent if __name__ == '__main__': # open gr3 file logger.info('Reading hgrid file...') _tic = time() hgrid = Hgrid.open(PARENT / 'hgrid.gr3', crs='EPSG:4326') logger.info(f'Reading hgrind file took {time()-_tic}.') vgrid = Vgrid() fgrid = Fgrid.open(PARENT / 'drag.gr3', crs='EPSG:4326') # setup model domain domain = ModelDomain(hgrid, vgrid, fgrid) logger.info('Model domain setup finished') # set tidal boundary conditions elevbc = Tides() elevbc.use_all() # activate all forcing constituents logger.info('Tidal boundary setup finished') # connect the boundary condition to the domain
mkdir -p outputs time srun pschism_TVD-VL } main """ # https://eev.ee/blog/2012/05/23/python-faq-descriptors/ PARENT = pathlib.Path(__file__).parent if __name__ == '__main__': # open gr3 file hgrid = Hgrid.open(PARENT / 'hgrid.gr3') vgrid = Vgrid() fgrid = Fgrid.open(PARENT / 'manning.gr3') # setup model domain domain = ModelDomain(hgrid, vgrid, fgrid) # set tidal boundary conditions elevbc = Tides() elevbc.use_all() # activate all forcing constituents # connect the boundary condition to the domain domain.add_boundary_condition(elevbc) # from pyschism.forcing.atmosphere.nws.nws2 import NWS2 # from pyschism.forcing.atmosphere.gfs import GlobalForecastSystem as GFS
def __init__(self,app): QMainWindow.__init__(self) Ui_MainWindow.__init__(self) self.setupUi(self) self.bot_layer_thickness.valueChanged.connect(self.refresh_it_all) self.avqs0.valueChanged.connect(self.refresh_it_all) self.sigma_type.currentChanged.connect(self.refresh_it_all) self.thetab.valueChanged.connect(self.refresh_it_all) self.thetaf.valueChanged.connect(self.refresh_it_all) self.rtheta_b.valueChanged.connect(self.refresh_it_all) self.rtheta_s.valueChanged.connect(self.refresh_it_all) self.tcline.valueChanged.connect(self.refresh_it_all) self.vstreching.activated.connect(self.refresh_it_all) self.rutgers.toggled.connect(self.refresh_it_all) self.hsm.returnPressed.connect(self.refresh_it_all) self.nv_vqs.returnPressed.connect(self.refresh_it_all) self.thetaf_exp.returnPressed.connect(self.refresh_it_all) self.thetab_exp.returnPressed.connect(self.refresh_it_all) self.import_vgrid.triggered.connect(self.importV) self.import_nlev.triggered.connect(self.importLEV) self.import_hgrid.triggered.connect(self.importH) self.export_vgrid.triggered.connect(self.exportV) self.export_vgrid_params.triggered.connect(self.exportVparams) self.export_trs.triggered.connect(self.exportTRS) self.export_nlev.triggered.connect(self.exportLEV) self.Xtrs=[] self.Ytrs=[] self.Ztrs=[] self.Ntrs=[] self.nlev=[] epsg=app.arguments()[2] self.gr = Hgrid.open(os.path.expanduser(app.arguments()[1]),crs="EPSG:%i" % int(epsg)) if int(epsg)==4326: epsgout=app.arguments()[3] self.gr.transform_to(int(epsgout)) self.gr.values[:]=self.gr.values[:]*-1. self.nlev=copy.deepcopy(self.gr) self.nlev.values[:]=self.nlev.values[:]*0 self.gr.tri = np.array( [list(map(self.gr.nodes.get_index_by_id, element[:-1])) for element in self.gr.elements.elements.values() if len(element) == 4]) self.create_transect() #self.hsm.setText('0:%i:50'% (np.ceil(self.gr.mesh.nodes[:,2].max())+50)) dp='' dp0=50 dz=20 I=0 while dp0+(I*dz)<np.ceil(self.gr.values.max())+(I*dz): dp+=str(dp0+(I*dz))+' ' dp0=dp0+(I*dz) I+=1 self.hsm.setText(dp) self.vgrid=self.create_vgrid(maxdepth=np.ceil(self.gr.values.max()),hsm=self.get_hsm(self.hsm.text())) self.vgrid.compute_zcor(self.gr.values,a_vqs0=-0.3,opt=1) self.nlev.values[:]=self.vgrid.kbp[:,0] self.vgrid.extract_trs(self.Xtrs,self.Ytrs,self.Ntrs) self.create_main_frame() self.create_vertical_frame() self.draw_map() self.draw_vgrid()
from pyschism.mesh import Hgrid from pyschism.forcing.hydrology import Hydrology from pyschism.forcing.hydrology.nwm import (NWMElementPairings, AWSDataInventory, streamflow_lookup, localize_datetime, nearest_cycle_date) if __name__ == '__main__': logging.getLogger().setLevel(logging.INFO) logging.info('Read hgrid.') start = time() hgrid = Hgrid.open(os.getenv('NWM_TEST_MESH'), crs='EPSG:4326') logging.info(f'Read hgrid took {time() - start}.') pairings = NWMElementPairings(hgrid) start = time() inventory = AWSDataInventory(rnday=0.25) logging.info(f'Download AWS data took {time() - start}.') nprocs = cpu_count() source_indexes, sinks_indexes = inventory.get_nc_pairing_indexes(pairings) if nprocs > 1: logging.info('Running parallelized streamflow_lookup.') start = time() with Pool(processes=cpu_count()) as pool: sources = pool.starmap(streamflow_lookup,
def load(self,epsg): '''Docstring''' return Hgrid.open(self.path_gr3,crs="EPSG:%i" % epsg)