diff --git a/examples/04_Extracting_crosssection_velocities_and_discharge.ipynb b/examples/04_Extracting_crosssection_velocities_and_discharge.ipynb index caa4e1d..ef49ffb 100644 --- a/examples/04_Extracting_crosssection_velocities_and_discharge.ipynb +++ b/examples/04_Extracting_crosssection_velocities_and_discharge.ipynb @@ -295,14 +295,6 @@ "- Frames-per-second of a video are not as constant as we would like them to be and many cameras (in particular cheap IP cameras) are not good at keeping track of the time evolution per frame. This can cause a lot of variability which has nothing to do with real uncertainty. `pyorc` does read frame-specific timings in case frame rates are not constant.\n", "- last but not least, remaining uncertainties in the PIV solution can cause variability.\n" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "19", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/pyorc/service/velocimetry.py b/pyorc/service/velocimetry.py index 75aaaf1..3ad79ea 100644 --- a/pyorc/service/velocimetry.py +++ b/pyorc/service/velocimetry.py @@ -38,16 +38,8 @@ def vmin_vmax_to_norm(opts): """ if "vmin" in opts or "vmax" in opts: - if "vmin" in opts: - vmin = opts["vmin"] - del opts["vmin"] - else: - vmin = None - if "vmax" in opts: - vmax = opts["vmax"] - del opts["vmax"] - else: - vmax = None + vmin = opts.pop("vmin", None) + vmax = opts.pop("vmax", None) norm = Normalize(vmin=vmin, vmax=vmax) opts["norm"] = norm return opts @@ -93,14 +85,10 @@ def run_func_hash_io( Wrapper function to run a sub function if either output is not present or input has changed. If check is False then simply passes everything. """ - if attrs is None: - attrs = [] - if inputs is None: - inputs = [] - if configs is None: - configs = [] - if outputs is None: - outputs = [] + attrs = [] if attrs is None else attrs + inputs = [] if inputs is None else inputs + configs = [] if configs is None else configs + outputs = [] if outputs is None else outputs def decorator_func(processor_func): @functools.wraps(processor_func) @@ -164,7 +152,6 @@ def wrapper_func(ref, *args, **kwargs): fn_hash = os.path.join(path_out, f"{os.path.basename(getattr(ref, i))}.hash") # get hash hash256 = cli_utils.get_file_hash(getattr(ref, i)) - # print(hash256.hexdigest()) with open(fn_hash, "w") as f: f.write(hash256.hexdigest()) else: @@ -382,8 +369,7 @@ def frames(self, **kwargs): def velocimetry(self, method="get_piv", write=False, **kwargs): if len(kwargs) > 1: raise OverflowError(f"Too many arguments under velocimetry, only one allowed, but {len(kwargs)} given.") - if len(kwargs) == 0: - kwargs[method] = {} + kwargs[method] = kwargs.get(method, {}) if len(kwargs) == 0 else kwargs[method] # get velocimetry results self.velocimetry_obj = apply_methods(self.da_frames, "frames", logger=self.logger, **kwargs) m = list(kwargs.keys())[0] diff --git a/tests/test_cli.py b/tests/test_cli.py index da408a1..7b49285 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,59 +1,63 @@ import json -from matplotlib import backend_bases -import matplotlib.pyplot as plt import os.path + +import matplotlib.pyplot as plt import pytest -import warnings -from click.testing import CliRunner +from matplotlib import backend_bases import pyorc.service -from pyorc.cli.main import cli -from pyorc.cli.cli_elements import GcpSelect, AoiSelect, StabilizeSelect from pyorc.cli import cli_utils +from pyorc.cli.cli_elements import AoiSelect, GcpSelect, StabilizeSelect +from pyorc.cli.main import cli from pyorc.helpers import xyz_transform + +def test_cli_info(cli_obj): + result = cli_obj.invoke(cli, ["--info"], echo=True) + assert result.exit_code == 0 + + +def test_cli_license(cli_obj): + result = cli_obj.invoke(cli, ["--license"], echo=True) + assert result.exit_code == 0 + + def test_cli_cam_config(cli_obj): - result = cli_obj.invoke( - cli, [ - 'camera-config', - '--help' - ], - echo=True - ) + result = cli_obj.invoke(cli, ["camera-config", "--help"], echo=True) assert result.exit_code == 0 def test_cli_cam_config_video(cli_obj, vid_file, gcps_src, gcps_dst, lens_position, corners, cli_cam_config_output): result = cli_obj.invoke( - cli, [ - 'camera-config', - '-V', + cli, + [ + "camera-config", + "-V", vid_file, # '--src', # json.dumps(gcps_src), - '--dst', + "--dst", json.dumps(gcps_dst), - '--crs', - '32735', - '--z_0', - '1182.2', - '--h_ref', - '0.0', - '--lens_position', + "--crs", + "32735", + "--z_0", + "1182.2", + "--h_ref", + "0.0", + "--lens_position", json.dumps(lens_position), - '--resolution', - '0.03', - '--window_size', - '25', - '--corners', + "--resolution", + "0.03", + "--window_size", + "25", + "--corners", json.dumps(corners), - '-vvv', + "-vvv", cli_cam_config_output, - ], - echo=True + echo=True, ) - # assert result.exit_code == 0 + assert result.exit_code == 0 def test_cli_velocimetry(cli_obj, vid_file, cam_config_fn, cli_recipe_fn, cli_output_dir): @@ -61,21 +65,12 @@ def test_cli_velocimetry(cli_obj, vid_file, cam_config_fn, cli_recipe_fn, cli_ou print(f"current file is: {os.path.dirname(__file__)}") os.chdir(os.path.dirname(__file__)) result = cli_obj.invoke( - cli, [ - 'velocimetry', - '-V', - vid_file, - '-c', - cam_config_fn, - '-r', - cli_recipe_fn, - '-v', - cli_output_dir, - '-u' - ], - echo=True + cli, + ["velocimetry", "-V", vid_file, "-c", cam_config_fn, "-r", cli_recipe_fn, "-v", cli_output_dir, "-u"], + echo=True, ) import time + time.sleep(1) assert result.exit_code == 0 @@ -85,7 +80,7 @@ def test_cli_velocimetry(cli_obj, vid_file, cam_config_fn, cli_recipe_fn, cli_ou [ "recipe", "recipe_geojson", - ] + ], ) def test_service_video(recipe_, vid_file, cam_config, cli_prefix, cli_output_dir, request): recipe_ = request.getfixturevalue(recipe_) @@ -93,16 +88,13 @@ def test_service_video(recipe_, vid_file, cam_config, cli_prefix, cli_output_dir print(f"current file is: {os.path.dirname(__file__)}") os.chdir(os.path.dirname(__file__)) pyorc.service.velocity_flow( - recipe=recipe_, - videofile=vid_file, - cameraconfig=cam_config.to_dict(), - prefix=cli_prefix, - output=cli_output_dir + recipe=recipe_, videofile=vid_file, cameraconfig=cam_config.to_dict(), prefix=cli_prefix, output=cli_output_dir ) def test_gcps_interact(gcps_dst, frame_rgb): import matplotlib.pyplot as plt + # convert dst to crs = 32735 # crs = None @@ -115,7 +107,10 @@ def test_gcps_interact(gcps_dst, frame_rgb): # plt.show(block=True) # make a click event for testing callbacks event = backend_bases.MouseEvent( - name="click", canvas=selector.fig.canvas, x=5, y=5, + name="click", + canvas=selector.fig.canvas, + x=5, + y=5, ) selector.on_press(event) selector.on_move(event) @@ -125,6 +120,7 @@ def test_gcps_interact(gcps_dst, frame_rgb): selector.on_release(event) plt.close("all") + def test_aoi_interact(frame_rgb, cam_config_without_aoi): # convert dst to # del cam_config_without_aoi.crs @@ -138,7 +134,10 @@ def test_aoi_interact(frame_rgb, cam_config_without_aoi): # plt.show(block=True) # make a click event for testing callbacks event = backend_bases.MouseEvent( - name="click", canvas=selector.fig.canvas, x=5, y=5, + name="click", + canvas=selector.fig.canvas, + x=5, + y=5, ) selector.on_press(event) selector.on_move(event) @@ -152,7 +151,10 @@ def test_aoi_interact(frame_rgb, cam_config_without_aoi): def test_stabilize_interact(frame_rgb): selector = StabilizeSelect(frame_rgb) event = backend_bases.MouseEvent( - name="click", canvas=selector.fig.canvas, x=5, y=5, + name="click", + canvas=selector.fig.canvas, + x=5, + y=5, ) selector.on_press(event) @@ -167,7 +169,8 @@ def test_stabilize_interact(frame_rgb): # plt.show(block=True) plt.close("all") + def test_read_shape(gcps_fn): coords, wkt = cli_utils.read_shape(gcps_fn) - assert(isinstance(wkt, str)) - assert(isinstance(coords, list)) + assert isinstance(wkt, str) + assert isinstance(coords, list)