Beispiel #1
0
 def test_make_plot(self, mock):
     h = Hgrid(self.nodes, self.elements)
     h.make_plot(
         show=True,
         extent=[0, 1, 0, 1],
         title='test',
         cbar_label='elevation [m]',
         vmax=0.
         )
     self.assertIsInstance(h, Hgrid)
Beispiel #2
0
 def test_add_boundary_raise(self):
     h = Hgrid(self.nodes, self.elements)
     h.add_boundary_type('ibtype')
     indexes = ['10000']
     self.assertRaises(
         AssertionError,
         h.set_boundary_data,
         'ibtype',
         0,
         indexes,
     )
Beispiel #3
0
 def test_add_boundary_custom_raise(self):
     h = Hgrid(self.nodes, self.elements)
     h.add_boundary_type('ibtype')
     indexes = [('2', '7'), ('3', '10000'), ('4', '9')]
     props = {'flow': [1, 2, 3]}
     self.assertRaises(
         AssertionError,
         h.set_boundary_data,
         'ibtype',
         0,
         indexes,
         **props
     )
Beispiel #4
0
 def test_make_plot_wet_only(self):
     nodes = {
         0: ((0., 0.), 0.),
         1: ((1., 0.), -1.),
         2: ((1., 1.), -2.),
         3: ((0., 1.), -3.),
         4: ((0.5, 1.5), -4.),
     }
     elements = {
         0: [2, 4, 3],
         1: [0, 1, 2, 3],
     }
     h = Hgrid(nodes, elements)
     h.make_plot()
     self.assertIsInstance(h, Hgrid)
Beispiel #5
0
    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}.')
Beispiel #6
0
 def test_add_existing_boundary_type_raises(self):
     msh = Hgrid(self.nodes, self.elements)
     self.assertRaises(Exception, msh.add_boundary_type, None)