From a38259ea15e7b55b6ddb3215180dee56b05e6648 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 16:32:20 +0000 Subject: [PATCH 1/3] chore: update pre-commit hooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/adamchainz/blacken-docs: 1.16.0 → 1.18.0](https://github.com/adamchainz/blacken-docs/compare/1.16.0...1.18.0) - [github.com/astral-sh/ruff-pre-commit: v0.4.2 → v0.6.9](https://github.com/astral-sh/ruff-pre-commit/compare/v0.4.2...v0.6.9) - [github.com/pre-commit/pre-commit-hooks: v4.5.0 → v5.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.5.0...v5.0.0) - [github.com/pre-commit/mirrors-prettier: v3.1.0 → v4.0.0-alpha.8](https://github.com/pre-commit/mirrors-prettier/compare/v3.1.0...v4.0.0-alpha.8) - [github.com/pre-commit/mirrors-mypy: v1.7.1 → v1.11.2](https://github.com/pre-commit/mirrors-mypy/compare/v1.7.1...v1.11.2) - [github.com/codespell-project/codespell: v2.2.6 → v2.3.0](https://github.com/codespell-project/codespell/compare/v2.2.6...v2.3.0) - [github.com/shellcheck-py/shellcheck-py: v0.9.0.6 → v0.10.0.1](https://github.com/shellcheck-py/shellcheck-py/compare/v0.9.0.6...v0.10.0.1) - [github.com/abravalheri/validate-pyproject: v0.18 → v0.20.2](https://github.com/abravalheri/validate-pyproject/compare/v0.18...v0.20.2) - [github.com/python-jsonschema/check-jsonschema: 0.29.0 → 0.29.3](https://github.com/python-jsonschema/check-jsonschema/compare/0.29.0...0.29.3) --- .pre-commit-config.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ca57a47b..c9506087 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,20 +28,20 @@ exclude: | repos: - repo: https://github.com/adamchainz/blacken-docs - rev: "1.16.0" + rev: "1.18.0" hooks: - id: blacken-docs additional_dependencies: [black==23.7.0] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.4.2" + rev: "v0.6.9" hooks: - id: ruff args: ["--fix", "--show-fixes"] - id: ruff-format - repo: https://github.com/pre-commit/pre-commit-hooks - rev: "v4.5.0" + rev: "v5.0.0" hooks: - id: check-added-large-files exclude: ^docs/datasets/ @@ -65,14 +65,14 @@ repos: - id: rst-inline-touching-normal - repo: https://github.com/pre-commit/mirrors-prettier - rev: "v3.1.0" + rev: "v4.0.0-alpha.8" hooks: - id: prettier types_or: [yaml, markdown, html, css, scss, javascript, json] args: [--prose-wrap=always] - repo: https://github.com/pre-commit/mirrors-mypy - rev: "v1.7.1" + rev: "v1.11.2" hooks: - id: mypy files: src|tests @@ -83,7 +83,7 @@ repos: # - data-science-types - repo: https://github.com/codespell-project/codespell - rev: "v2.2.6" + rev: "v2.3.0" hooks: - id: codespell name: codespell @@ -93,7 +93,7 @@ repos: --ignore-regex=".*codespell-ignore$" - repo: https://github.com/shellcheck-py/shellcheck-py - rev: "v0.9.0.6" + rev: "v0.10.0.1" hooks: - id: shellcheck @@ -107,13 +107,13 @@ repos: exclude: .pre-commit-config.yaml - repo: https://github.com/abravalheri/validate-pyproject - rev: "v0.18" + rev: "v0.20.2" hooks: - id: validate-pyproject additional_dependencies: ["validate-pyproject-schema-store[all]"] - repo: https://github.com/python-jsonschema/check-jsonschema - rev: "0.29.0" + rev: "0.29.3" hooks: - id: check-dependabot - id: check-github-workflows From 32ae471a2a2a7b4dcd2086f64640b1a64202e118 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 16:32:57 +0000 Subject: [PATCH 2/3] style: pre-commit fixes --- src/polartoolkit/fetch.py | 2 +- src/polartoolkit/maps.py | 132 +++++++++++++++++------------------ src/polartoolkit/profiles.py | 78 ++++++++++----------- src/polartoolkit/utils.py | 30 ++++---- tests/test_fetch.py | 96 ++++++++++++------------- 5 files changed, 169 insertions(+), 169 deletions(-) diff --git a/src/polartoolkit/fetch.py b/src/polartoolkit/fetch.py index 243bfc87..7cc4df11 100644 --- a/src/polartoolkit/fetch.py +++ b/src/polartoolkit/fetch.py @@ -2576,7 +2576,7 @@ def gravity( .. footbibliography:: """ - anomaly_type = kwargs.get("anomaly_type", None) + anomaly_type = kwargs.get("anomaly_type") if version == "antgg": # found with utils.get_grid_info() diff --git a/src/polartoolkit/maps.py b/src/polartoolkit/maps.py index e954100f..3d8e8f45 100644 --- a/src/polartoolkit/maps.py +++ b/src/polartoolkit/maps.py @@ -339,13 +339,13 @@ def basemap( fig=fig, origin_shift=origin_shift, fig_height=kwargs.get("fig_height", 15), - fig_width=kwargs.get("fig_width", None), + fig_width=kwargs.get("fig_width"), hemisphere=hemisphere, yshift_amount=kwargs.get("yshift_amount", 1), xshift_amount=kwargs.get("xshift_amount", 1), ) - show_region = kwargs.get("show_region", None) + show_region = kwargs.get("show_region") if imagery_basemap is True: if hemisphere == "north": @@ -385,8 +385,8 @@ def basemap( fig, region=region, projection=proj_latlon, - x_spacing=kwargs.get("x_spacing", None), - y_spacing=kwargs.get("y_spacing", None), + x_spacing=kwargs.get("x_spacing"), + y_spacing=kwargs.get("y_spacing"), ) # plot groundingline and coastlines @@ -396,9 +396,9 @@ def basemap( hemisphere=hemisphere, region=region, projection=proj, - pen=kwargs.get("coast_pen", None), + pen=kwargs.get("coast_pen"), no_coast=kwargs.get("no_coast", False), - version=kwargs.get("coast_version", None), + version=kwargs.get("coast_version"), ) # plot faults @@ -407,12 +407,12 @@ def basemap( fig=fig, region=region, projection=proj, - label=kwargs.get("fault_label", None), - pen=kwargs.get("fault_pen", None), - style=kwargs.get("fault_style", None), - fault_activity=kwargs.get("fault_activity", None), - fault_motion=kwargs.get("fault_motion", None), - fault_exposure=kwargs.get("fault_exposure", None), + label=kwargs.get("fault_label"), + pen=kwargs.get("fault_pen"), + style=kwargs.get("fault_style"), + fault_activity=kwargs.get("fault_activity"), + fault_motion=kwargs.get("fault_motion"), + fault_exposure=kwargs.get("fault_exposure"), ) # add box showing region @@ -420,7 +420,7 @@ def basemap( add_box( fig, show_region, - pen=kwargs.get("region_pen", None), + pen=kwargs.get("region_pen"), ) # add datapoints @@ -438,7 +438,7 @@ def basemap( style=kwargs.get("points_style", "c.2c"), fill=kwargs.get("points_fill", "black"), pen=kwargs.get("points_pen", "1p,black"), - cmap=kwargs.get("points_cmap", None), + cmap=kwargs.get("points_cmap"), ) # display colorbar if kwargs.get("colorbar", False) is True: @@ -454,7 +454,7 @@ def basemap( } add_colorbar( fig, - cmap=kwargs.get("points_cmap", None), + cmap=kwargs.get("points_cmap"), fig_width=fig_width, region=region, **cbar_kwargs, @@ -1019,13 +1019,13 @@ def plot_grd( fig=fig, origin_shift=origin_shift, fig_height=kwargs.get("fig_height", 15), - fig_width=kwargs.get("fig_width", None), + fig_width=kwargs.get("fig_width"), hemisphere=hemisphere, yshift_amount=kwargs.get("yshift_amount", 1), xshift_amount=kwargs.get("xshift_amount", 1), ) - show_region = kwargs.get("show_region", None) + show_region = kwargs.get("show_region") if imagery_basemap is True: if hemisphere == "north": @@ -1058,8 +1058,8 @@ def plot_grd( projection=proj, region=region, nan_transparent=True, - frame=kwargs.get("frame", None), - shading=kwargs.get("shading", None), + frame=kwargs.get("frame"), + shading=kwargs.get("shading"), transparency=kwargs.get("transparency", 0), verbose="q", ) @@ -1079,7 +1079,7 @@ def plot_grd( style=kwargs.get("points_style", "c.2c"), fill=kwargs.get("points_fill", "black"), pen=kwargs.get("points_pen", "1p,black"), - cmap=kwargs.get("points_cmap", None), + cmap=kwargs.get("points_cmap"), ) # add box showing region @@ -1087,7 +1087,7 @@ def plot_grd( add_box( fig, show_region, - pen=kwargs.get("region_pen", None), + pen=kwargs.get("region_pen"), ) # plot groundingline and coastlines @@ -1097,9 +1097,9 @@ def plot_grd( hemisphere=hemisphere, region=region, projection=proj, - pen=kwargs.get("coast_pen", None), + pen=kwargs.get("coast_pen"), no_coast=kwargs.get("no_coast", False), - version=kwargs.get("coast_version", None), + version=kwargs.get("coast_version"), ) # plot faults @@ -1108,12 +1108,12 @@ def plot_grd( fig=fig, region=region, projection=proj, - label=kwargs.get("fault_label", None), - pen=kwargs.get("fault_pen", None), - style=kwargs.get("fault_style", None), - fault_activity=kwargs.get("fault_activity", None), - fault_motion=kwargs.get("fault_motion", None), - fault_exposure=kwargs.get("fault_exposure", None), + label=kwargs.get("fault_label"), + pen=kwargs.get("fault_pen"), + style=kwargs.get("fault_style"), + fault_activity=kwargs.get("fault_activity"), + fault_motion=kwargs.get("fault_motion"), + fault_exposure=kwargs.get("fault_exposure"), ) # add lat long grid lines @@ -1127,8 +1127,8 @@ def plot_grd( fig, region=region, projection=proj_latlon, - x_spacing=kwargs.get("x_spacing", None), - y_spacing=kwargs.get("y_spacing", None), + x_spacing=kwargs.get("x_spacing"), + y_spacing=kwargs.get("y_spacing"), ) # add inset map to show figure location @@ -1258,7 +1258,7 @@ def add_colorbar( orientation = kwargs.get("cbar_orientation", "h") # text location - text_location = kwargs.get("cbar_text_location", None) + text_location = kwargs.get("cbar_text_location") # add colorbar with pygmt.config( @@ -1272,7 +1272,7 @@ def add_colorbar( ), frame=cbar_frame, scale=kwargs.get("cbar_scale", 1), - log=kwargs.get("cbar_log", None), + log=kwargs.get("cbar_log"), ) # add histogram to colorbar @@ -1280,7 +1280,7 @@ def add_colorbar( # `hist_ymax` to an appropriate value if hist is True: # get grid to use - grid = kwargs.get("grid", None) + grid = kwargs.get("grid") hist_cmap = kwargs.get("hist_cmap", True) @@ -1289,7 +1289,7 @@ def add_colorbar( raise ValueError(msg) # clip grid to plot region - region = kwargs.get("region", None) + region = kwargs.get("region") # if no region supplied, get region of current PyGMT figure if region is None: with pygmt.clib.Session() as lib: @@ -1304,7 +1304,7 @@ def add_colorbar( # incorrectly, hacky solution is to check if clipped figure is smaller than # a few data points, if so, use grids full region if len(grid_clipped[list(grid_clipped.sizes.keys())[0]].values) < 5: # noqa: RUF015 - reg = kwargs.get("region", None) + reg = kwargs.get("region") if reg is None: msg = ( "Issue with detecting figure region for adding colorbar " @@ -1352,10 +1352,10 @@ def add_colorbar( ) zmin, zmax = utils.get_min_max( grid, - shapefile=kwargs.get("shp_mask", None), - region=kwargs.get("cmap_region", None), + shapefile=kwargs.get("shp_mask"), + region=kwargs.get("cmap_region"), robust=kwargs.get("robust", False), - hemisphere=kwargs.get("hemisphere", None), + hemisphere=kwargs.get("hemisphere"), ) else: zmin, zmax = cpt_lims @@ -1367,7 +1367,7 @@ def add_colorbar( # subset data between cbar min and max data = df2[df2.between(zmin, zmax)] - bin_width = kwargs.get("hist_bin_width", None) + bin_width = kwargs.get("hist_bin_width") bin_num = kwargs.get("hist_bin_num", 100) if bin_width is not None: @@ -1425,9 +1425,9 @@ def add_colorbar( region=hist_reg, frame=kwargs.get("hist_frame", False), cmap=hist_cmap, - fill=kwargs.get("hist_fill", None), + fill=kwargs.get("hist_fill"), pen=kwargs.get("hist_pen", "default"), - barwidth=kwargs.get("hist_barwidth", None), + barwidth=kwargs.get("hist_barwidth"), center=kwargs.get("hist_center", False), distribution=kwargs.get("hist_distribution", False), cumulative=kwargs.get("hist_cumulative", False), @@ -1856,7 +1856,7 @@ def add_scalebar( """ font_color = kwargs.get("font_color", "black") - scale_length = kwargs.get("scale_length", None) + scale_length = kwargs.get("scale_length") length_perc = kwargs.get("length_perc", 0.25) position = kwargs.get("position", "n.5/.05") @@ -2015,7 +2015,7 @@ def interactive_map( layout = ipywidgets.Layout( width=kwargs.get("width", "auto"), - height=kwargs.get("height", None), + height=kwargs.get("height"), ) # if points are supplied, center map on them and plot them @@ -2170,7 +2170,7 @@ def subplots( # set subplot projection and size from input region and figure dimensions # by default use figure height to set projection - if kwargs.get("fig_width", None) is None: + if kwargs.get("fig_width") is None: _proj, _proj_latlon, fig_width, fig_height = utils.set_proj( region, fig_height=kwargs.pop("fig_height", 15), @@ -2180,7 +2180,7 @@ def subplots( else: _proj, _proj_latlon, fig_width, fig_height = utils.set_proj( region, - fig_width=kwargs.get("fig_width", None), + fig_width=kwargs.get("fig_width"), hemisphere=hemisphere, ) @@ -2192,41 +2192,41 @@ def subplots( ncols=subplot_dimensions[1], subsize=(fig_width, fig_height), frame=kwargs.get("frame", "f"), - clearance=kwargs.get("clearance", None), # edges of figure - title=kwargs.get("fig_title", None), + clearance=kwargs.get("clearance"), # edges of figure + title=kwargs.get("fig_title"), margins=kwargs.get("margins", "0.5c"), # between suplots autolabel=kwargs.get("autolabel"), ): for i, j in enumerate(grids): with fig.set_panel(panel=i): # if list of cmaps provided, use them - if kwargs.get("cmaps", None) is not None: - cmap = kwargs.get("cmaps", None)[i] + if kwargs.get("cmaps") is not None: + cmap = kwargs.get("cmaps")[i] # if not, use viridis else: cmap = "viridis" # if list of titles provided, use them - if kwargs.get("subplot_titles", None) is not None: - sub_title = kwargs.get("subplot_titles", None)[i] + if kwargs.get("subplot_titles") is not None: + sub_title = kwargs.get("subplot_titles")[i] else: sub_title = None # if list of colorbar labels provided, use them - if kwargs.get("cbar_labels", None) is not None: - cbar_label = kwargs.get("cbar_labels", None)[i] + if kwargs.get("cbar_labels") is not None: + cbar_label = kwargs.get("cbar_labels")[i] else: cbar_label = " " # if list of colorbar units provided, use them - if kwargs.get("cbar_units", None) is not None: - cbar_unit = kwargs.get("cbar_units", None)[i] + if kwargs.get("cbar_units") is not None: + cbar_unit = kwargs.get("cbar_units")[i] else: cbar_unit = " " # if list of cmaps limits provided, use them - if kwargs.get("cpt_limits", None) is not None: - cpt_lims = kwargs.get("cpt_limits", None)[i] + if kwargs.get("cpt_limits") is not None: + cpt_lims = kwargs.get("cpt_limits")[i] else: cpt_lims = None @@ -2294,17 +2294,17 @@ def plot_3d( Returns a figure object, which can be used by other PyGMT plotting functions. """ fig_height = kwargs.get("fig_height", 15) - fig_width = kwargs.get("fig_width", None) + fig_width = kwargs.get("fig_width") - cbar_labels = kwargs.get("cbar_labels", None) + cbar_labels = kwargs.get("cbar_labels") # colormap kwargs modis = kwargs.get("modis", False) grd2cpt = kwargs.get("grd2cpt", False) - cmap_region = kwargs.get("cmap_region", None) + cmap_region = kwargs.get("cmap_region") robust = kwargs.get("robust", False) reverse_cpt = kwargs.get("reverse_cpt", False) - cpt_lims_list = kwargs.get("cpt_lims", None) + cpt_lims_list = kwargs.get("cpt_lims") if not isinstance(grids, list): grids = [grids] @@ -2435,7 +2435,7 @@ def plot_3d( ) # set transparency values - transparencies = kwargs.get("transparencies", None) + transparencies = kwargs.get("transparencies") transparency = 0 if transparencies is None else transparencies[i] # plot as perspective view @@ -2455,8 +2455,8 @@ def plot_3d( # display colorbar if colorbar is True: - cbar_xshift = kwargs.get("cbar_xshift", None) - cbar_yshift = kwargs.get("cbar_yshift", None) + cbar_xshift = kwargs.get("cbar_xshift") + cbar_yshift = kwargs.get("cbar_yshift") xshift = 0 if cbar_xshift is None else cbar_xshift[i] # yshift = fig_height / 2 if cbar_yshift is None else cbar_yshift[i] @@ -2476,7 +2476,7 @@ def plot_3d( # shift up for next grid if i < len(grids) - 1: - zshifts = kwargs.get("zshifts", None) + zshifts = kwargs.get("zshifts") zshift = 0 if zshifts is None else zshifts[i] if zshifts is not None: diff --git a/src/polartoolkit/profiles.py b/src/polartoolkit/profiles.py index f96d7424..24b239bd 100644 --- a/src/polartoolkit/profiles.py +++ b/src/polartoolkit/profiles.py @@ -557,7 +557,7 @@ def plot_profile( inset = kwargs.get("inset", True) subplot_orientation = kwargs.get("subplot_orientation", "horizontal") gridlines = kwargs.get("gridlines", True) - map_points = kwargs.get("map_points", None) + map_points = kwargs.get("map_points") coast = kwargs.get("coast", True) # create dataframe of points @@ -573,8 +573,8 @@ def plot_profile( layers_dict = default_layers( layers_version, # type: ignore[arg-type] # region=vd.get_region((points.x, points.y)), - reference=kwargs.get("default_layers_reference", None), - spacing=kwargs.get("default_layers_spacing", None), + reference=kwargs.get("default_layers_reference"), + spacing=kwargs.get("default_layers_spacing"), hemisphere=hemisphere, ) @@ -609,15 +609,15 @@ def plot_profile( raise ValueError(msg) df_layers = shorten( df_layers, - max_dist=kwargs.get("max_dist", None), - min_dist=kwargs.get("min_dist", None), + max_dist=kwargs.get("max_dist"), + min_dist=kwargs.get("min_dist"), ) if data_dict is not None: df_data = shorten( df_data, - max_dist=kwargs.get("max_dist", None), - min_dist=kwargs.get("min_dist", None), + max_dist=kwargs.get("max_dist"), + min_dist=kwargs.get("min_dist"), ) fig = pygmt.Figure() @@ -657,7 +657,7 @@ def plot_profile( else: ax1_min_max.append(utils.get_min_max(df_data[k])) - frames = kwargs.get("data_frame", None) + frames = kwargs.get("data_frame") if isinstance(frames, (str, type(None))): # noqa: SIM114 frames = [frames] @@ -705,7 +705,7 @@ def plot_profile( ] # plot data - if kwargs.get("data_line_cmap", None) is None: + if kwargs.get("data_line_cmap") is None: # plot data as lines data_pen = kwargs.get("data_pen") if isinstance(data_pen, list): @@ -717,20 +717,20 @@ def plot_profile( if isinstance(thick, (float, int)): thick = [thick] * len(data_dict.items()) - color = kwargs.get("data_pen_color", None) + color = kwargs.get("data_pen_color") if isinstance(color, list): color = color[i] if color is None: color = v["color"] - style = kwargs.get("data_pen_style", None) + style = kwargs.get("data_pen_style") if isinstance(style, list): style = style[i] if style is None: style = "" pen = f"{thick[i]}p,{color},{style}" - data_line_style = kwargs.get("data_line_style", None) + data_line_style = kwargs.get("data_line_style") if isinstance(data_line_style, list): data_line_style = data_line_style[i] @@ -783,7 +783,7 @@ def plot_profile( S=kwargs.get("data_legend_scale", 1), ) - if kwargs.get("data_line_cmap", None) is not None: + if kwargs.get("data_line_cmap") is not None: fig.colorbar( cmap=True, frame=f"a+l{kwargs.get('data_line_cmap_label', ' ')}", @@ -835,20 +835,20 @@ def plot_profile( if isinstance(thick, (float, int)): thick = [thick] * len(layers_dict.items()) - color = kwargs.get("layers_pen_color", None) + color = kwargs.get("layers_pen_color") if isinstance(color, list): color = color[i] if color is None: color = "black" - style = kwargs.get("layers_pen_style", None) + style = kwargs.get("layers_pen_style") if isinstance(style, list): style = style[i] if style is None: style = "" pen = f"{thick[i]}p,{color},{style}" - layers_line_style = kwargs.get("layers_line_style", None) + layers_line_style = kwargs.get("layers_line_style") if isinstance(layers_line_style, list): layers_line_style = layers_line_style[i] # plot lines between df_layers @@ -868,7 +868,7 @@ def plot_profile( ) # dont fill layers, just draw lines else: - if kwargs.get("layers_line_cmap", None) is None: + if kwargs.get("layers_line_cmap") is None: # get pen properties layers_pen = kwargs.get("layers_pen") if isinstance(layers_pen, list): @@ -880,13 +880,13 @@ def plot_profile( if isinstance(thick, (float, int)): thick = [thick] * len(layers_dict.items()) - color = kwargs.get("layers_pen_color", None) + color = kwargs.get("layers_pen_color") if isinstance(color, list): color = color[i] if color is None: color = v["color"] - style = kwargs.get("layers_pen_style", None) + style = kwargs.get("layers_pen_style") if isinstance(style, list): style = style[i] if style is None: @@ -919,7 +919,7 @@ def plot_profile( zvalue=v["color"], ) - if kwargs.get("layers_line_cmap", None) is not None: + if kwargs.get("layers_line_cmap") is not None: fig.colorbar( cmap=True, frame=f"a+l{kwargs.get('layers_line_cmap_label', ' ')}", @@ -1023,7 +1023,7 @@ def plot_profile( # plot imagery, or supplied grid as background # can't use maps.plot_grd because it reset projection - background = kwargs.get("map_background", None) + background = kwargs.get("map_background") if background is None: if hemisphere == "south": background = fetch.imagery() @@ -1067,7 +1067,7 @@ def plot_profile( # plot groundingline and coastlines if coast is True: - coast_version = kwargs.get("coast_version", None) + coast_version = kwargs.get("coast_version") if coast_version is None: if hemisphere == "north": coast_version = "BAS" @@ -1087,7 +1087,7 @@ def plot_profile( projection=map_proj, pen=kwargs.get("coast_pen", "1.2p,black"), no_coast=kwargs.get("no_coast", False), - version=kwargs.get("coast_version", None), + version=kwargs.get("coast_version"), ) # add lat long grid lines @@ -1096,8 +1096,8 @@ def plot_profile( fig, map_reg, map_proj_ll, - x_spacing=kwargs.get("x_spacing", None), - y_spacing=kwargs.get("y_spacing", None), + x_spacing=kwargs.get("x_spacing"), + y_spacing=kwargs.get("y_spacing"), ) # plot profile location, and endpoints on map @@ -1145,7 +1145,7 @@ def plot_profile( region=map_reg, inset_pos=kwargs.get("inset_pos", "TL"), inset_width=kwargs.get("inset_width", 0.25), - inset_reg=kwargs.get("inset_reg", None), + inset_reg=kwargs.get("inset_reg"), ) if kwargs.get("save") is True: @@ -1226,7 +1226,7 @@ def plot_data( inset = kwargs.get("inset", True) subplot_orientation = kwargs.get("subplot_orientation", "horizontal") gridlines = kwargs.get("gridlines", True) - map_points = kwargs.get("map_points", None) + map_points = kwargs.get("map_points") coast = kwargs.get("coast", True) # create dataframe of points @@ -1254,8 +1254,8 @@ def plot_data( raise ValueError(msg) df_data = shorten( df_data, - max_dist=kwargs.get("max_dist", None), - min_dist=kwargs.get("min_dist", None), + max_dist=kwargs.get("max_dist"), + min_dist=kwargs.get("min_dist"), ) fig = pygmt.Figure() @@ -1277,7 +1277,7 @@ def plot_data( else: ax1_min_max.append(utils.get_min_max(df_data[k])) - frames = kwargs.get("data_frame", None) + frames = kwargs.get("data_frame") if isinstance(frames, (str, type(None))): # noqa: SIM114 frames = [frames] @@ -1325,7 +1325,7 @@ def plot_data( ] # plot data - if kwargs.get("data_line_cmap", None) is None: + if kwargs.get("data_line_cmap") is None: # plot data as lines data_pen = kwargs.get("data_pen") if isinstance(data_pen, list): @@ -1337,20 +1337,20 @@ def plot_data( if isinstance(thick, (float, int)): thick = [thick] * len(data_dict.items()) - color = kwargs.get("data_pen_color", None) + color = kwargs.get("data_pen_color") if isinstance(color, list): color = color[i] if color is None: color = v["color"] - style = kwargs.get("data_pen_style", None) + style = kwargs.get("data_pen_style") if isinstance(style, list): style = style[i] if style is None: style = "" pen = f"{thick[i]}p,{color},{style}" - data_line_style = kwargs.get("data_line_style", None) + data_line_style = kwargs.get("data_line_style") if isinstance(data_line_style, list): data_line_style = data_line_style[i] @@ -1394,7 +1394,7 @@ def plot_data( box=kwargs.get("data_legend_box", False), S=kwargs.get("data_legend_scale", 1), ) - if kwargs.get("data_line_cmap", None) is not None: + if kwargs.get("data_line_cmap") is not None: fig.colorbar( cmap=True, frame=f"a+l{kwargs.get('data_line_cmap_label', ' ')}", @@ -1463,7 +1463,7 @@ def plot_data( # plot imagery, or supplied grid as background # can't use maps.plot_grd because it reset projection - background = kwargs.get("map_background", None) + background = kwargs.get("map_background") if background is None: if hemisphere == "south": background = fetch.imagery() @@ -1500,7 +1500,7 @@ def plot_data( projection=map_proj, pen=kwargs.get("coast_pen", "1.2p,black"), no_coast=kwargs.get("no_coast", False), - version=kwargs.get("coast_version", None), + version=kwargs.get("coast_version"), ) # add lat long grid lines @@ -1509,8 +1509,8 @@ def plot_data( fig, map_reg, map_proj_ll, - x_spacing=kwargs.get("x_spacing", None), - y_spacing=kwargs.get("y_spacing", None), + x_spacing=kwargs.get("x_spacing"), + y_spacing=kwargs.get("y_spacing"), ) # plot profile location, and endpoints on map diff --git a/src/polartoolkit/utils.py b/src/polartoolkit/utils.py index d95a38be..6cc8246b 100644 --- a/src/polartoolkit/utils.py +++ b/src/polartoolkit/utils.py @@ -1111,8 +1111,8 @@ def grd_compare( tuple[xarray.DataArray, xarray.DataArray, xarray.DataArray] three xarray.DataArrays: (diff, resampled grid1, resampled grid2) """ - shp_mask = kwargs.get("shp_mask", None) - region: tuple[float, float, float, float] = kwargs.get("region", None) + shp_mask = kwargs.get("shp_mask") + region: tuple[float, float, float, float] = kwargs.get("region") verbose = kwargs.get("verbose", "e") if isinstance(da1, str): da1 = xr.load_dataarray(da1) @@ -1173,10 +1173,10 @@ def grd_compare( else: region = da1_reg # use registration from first grid, or from kwarg - if kwargs.get("registration", None) is None: + if kwargs.get("registration") is None: registration = get_grid_info(da1)[4] else: - registration = kwargs.get("registration", None) + registration = kwargs.get("registration") # resample grids grid1 = fetch.resample_grid( da1, @@ -1204,13 +1204,13 @@ def grd_compare( grid1, shp_mask, robust=robust, - hemisphere=kwargs.get("hemisphere", None), + hemisphere=kwargs.get("hemisphere"), ) grid2_cpt_lims = get_min_max( grid2, shp_mask, robust=robust, - hemisphere=kwargs.get("hemisphere", None), + hemisphere=kwargs.get("hemisphere"), ) diff_maxabs = kwargs.get("diff_maxabs", True) @@ -1219,7 +1219,7 @@ def grd_compare( dif, shp_mask, robust=robust, - hemisphere=kwargs.get("hemisphere", None), + hemisphere=kwargs.get("hemisphere"), ) else: diff_maxabs = vd.maxabs( @@ -1227,7 +1227,7 @@ def grd_compare( dif, shp_mask, robust=robust, - hemisphere=kwargs.get("hemisphere", None), + hemisphere=kwargs.get("hemisphere"), ) ) diff_lims = kwargs.get("diff_lims", (-diff_maxabs, diff_maxabs)) @@ -1404,10 +1404,10 @@ def grd_compare( a.set_xlabel("") a.set_ylabel("") a.set_aspect("equal") - if kwargs.get("points", None) is not None: + if kwargs.get("points") is not None: a.plot(kwargs.get("points").x, kwargs.get("points").y, "k+") # type: ignore[union-attr] - if kwargs.get("show_region", None) is not None: - show_region = kwargs.get("show_region", None) + if kwargs.get("show_region") is not None: + show_region = kwargs.get("show_region") a.add_patch( mpl.patches.Rectangle( xy=(show_region[0], show_region[2]), @@ -1491,8 +1491,8 @@ def raps( msg = "Missing optional dependency 'seaborn' required for plotting." raise ImportError(msg) - region = kwargs.get("region", None) - spacing = kwargs.get("spacing", None) + region = kwargs.get("region") + spacing = kwargs.get("spacing") if plot_type == "pygmt": spec = pygmt.Figure() @@ -1607,8 +1607,8 @@ def coherency( msg = "Missing optional dependency 'seaborn' required for plotting." raise ImportError(msg) - region = kwargs.get("region", None) - spacing = kwargs.get("spacing", None) + region = kwargs.get("region") + spacing = kwargs.get("spacing") plt.figure() diff --git a/tests/test_fetch.py b/tests/test_fetch.py index 8d391727..22e576cf 100644 --- a/tests/test_fetch.py +++ b/tests/test_fetch.py @@ -52,8 +52,8 @@ def test_(): ) -@pytest.mark.fetch() -@pytest.mark.earthdata() +@pytest.mark.fetch +@pytest.mark.earthdata @skip_earthdata @deprecation.fail_if_not_removed def test_measures_boundaries(): @@ -205,7 +205,7 @@ def test_measures_boundaries(): ] -@pytest.mark.fetch() +@pytest.mark.fetch @pytest.mark.parametrize(("test_input", "expected"), resample_test) @pytest.mark.filterwarnings("ignore::RuntimeWarning") def test_resample_grid(test_input, expected): @@ -231,9 +231,9 @@ def test_resample_grid(test_input, expected): # %% ice_vel -@pytest.mark.fetch() -@pytest.mark.slow() -@pytest.mark.earthdata() +@pytest.mark.fetch +@pytest.mark.slow +@pytest.mark.earthdata @skip_earthdata @pytest.mark.filterwarnings("ignore::RuntimeWarning") def test_ice_vel_lowres(): @@ -251,9 +251,9 @@ def test_ice_vel_lowres(): ) -@pytest.mark.fetch() -@pytest.mark.slow() -@pytest.mark.earthdata() +@pytest.mark.fetch +@pytest.mark.slow +@pytest.mark.earthdata @skip_earthdata @pytest.mark.filterwarnings("ignore::RuntimeWarning") def test_ice_vel_highres(): @@ -293,9 +293,9 @@ def test_ice_vel_highres(): # %% modis -@pytest.mark.fetch() -@pytest.mark.slow() -@pytest.mark.earthdata() +@pytest.mark.fetch +@pytest.mark.slow +@pytest.mark.earthdata @skip_earthdata @pytest.mark.filterwarnings("ignore::RuntimeWarning") def test_modis(): @@ -338,16 +338,16 @@ def test_modis(): # utils.get_grid_info(grid) -@pytest.mark.fetch() -@pytest.mark.earthdata() +@pytest.mark.fetch +@pytest.mark.earthdata @skip_earthdata @deprecation.fail_if_not_removed def test_modis_moa(): fetch.modis_moa() -@pytest.mark.fetch() -@pytest.mark.earthdata() +@pytest.mark.fetch +@pytest.mark.earthdata @skip_earthdata @deprecation.fail_if_not_removed def test_modis_mog(): @@ -357,9 +357,9 @@ def test_modis_mog(): # %% imagery -@pytest.mark.fetch() -@pytest.mark.slow() -@pytest.mark.issue() +@pytest.mark.fetch +@pytest.mark.slow +@pytest.mark.issue @pytest.mark.filterwarnings("ignore::RuntimeWarning") def test_imagery(): grid = fetch.imagery() @@ -418,7 +418,7 @@ def test_imagery(): ] -@pytest.mark.fetch() +@pytest.mark.fetch @pytest.mark.filterwarnings("ignore::RuntimeWarning") @pytest.mark.parametrize(("test_input", "expected"), sediment_test) def test_sediment_thickness(test_input, expected): @@ -444,7 +444,7 @@ def test_sediment_thickness(test_input, expected): ] -@pytest.mark.fetch() +@pytest.mark.fetch @pytest.mark.parametrize(("test_input", "expected"), geomap_test) def test_geomap(test_input, expected): # collect a few points @@ -459,7 +459,7 @@ def test_geomap(test_input, expected): # %% IBCSO coverage data -@pytest.mark.fetch() +@pytest.mark.fetch def test_ibcso_coverage(): # collect a few points points, polygons = fetch.ibcso_coverage( @@ -554,8 +554,8 @@ def test_ibcso_coverage(): ] -@pytest.mark.fetch() -@pytest.mark.issue() +@pytest.mark.fetch +@pytest.mark.issue @pytest.mark.filterwarnings("ignore::RuntimeWarning") @pytest.mark.parametrize(("test_input", "expected"), ibcso_test) def test_ibcso(test_input, expected): @@ -688,8 +688,8 @@ def test_ibcso(test_input, expected): ] -@pytest.mark.fetch() -@pytest.mark.earthdata() +@pytest.mark.fetch +@pytest.mark.earthdata @skip_earthdata @pytest.mark.filterwarnings("ignore::RuntimeWarning") @pytest.mark.parametrize(("test_input", "expected", "hemisphere"), bedmachine_test) @@ -704,8 +704,8 @@ def test_bedmachine(test_input, expected, hemisphere): ) -@pytest.mark.fetch() -@pytest.mark.earthdata() +@pytest.mark.fetch +@pytest.mark.earthdata @skip_earthdata @pytest.mark.filterwarnings("ignore::RuntimeWarning") def test_bedmachine_reference_south(): @@ -745,8 +745,8 @@ def test_bedmachine_reference_south(): assert BM_eigen_6c4 == pytest.approx(eigen_6c4, rel=0.1) -@pytest.mark.fetch() -@pytest.mark.earthdata() +@pytest.mark.fetch +@pytest.mark.earthdata @skip_earthdata @pytest.mark.filterwarnings("ignore::RuntimeWarning") def test_bedmachine_reference_north(): @@ -837,7 +837,7 @@ def test_bedmachine_reference_north(): ] -@pytest.mark.fetch() +@pytest.mark.fetch @pytest.mark.filterwarnings("ignore::RuntimeWarning") @pytest.mark.parametrize(("test_input", "expected"), bedmap2_test) def test_bedmap2(test_input, expected): @@ -851,7 +851,7 @@ def test_bedmap2(test_input, expected): ) -@pytest.mark.fetch() +@pytest.mark.fetch @pytest.mark.filterwarnings("ignore::RuntimeWarning") def test_bedmap2_reference(): # fetch variations of grids and reference models @@ -910,7 +910,7 @@ def test_bedmap2_reference(): ] -@pytest.mark.fetch() +@pytest.mark.fetch @pytest.mark.parametrize(("test_input", "expected"), bedmap2_fill_nans_test) def test_bedmap2_fill_nans(test_input, expected): grid = fetch.bedmap2(**test_input) @@ -926,7 +926,7 @@ def test_bedmap2_fill_nans(test_input, expected): # %% Bedmap points -@pytest.mark.fetch() +@pytest.mark.fetch def test_bedmap_points(): df = fetch.bedmap_points(version="bedmap1") expected = [ @@ -1010,7 +1010,7 @@ def test_bedmap_points(): ] -@pytest.mark.fetch() +@pytest.mark.fetch @pytest.mark.filterwarnings("ignore::RuntimeWarning") @pytest.mark.parametrize(("test_input", "expected"), gravity_test) def test_gravity(test_input, expected): @@ -1059,7 +1059,7 @@ def test_gravity(test_input, expected): ] -@pytest.mark.fetch() +@pytest.mark.fetch @pytest.mark.filterwarnings("ignore::RuntimeWarning") @pytest.mark.parametrize(("test_input", "expected"), magnetics_test) def test_magnetics(test_input, expected): @@ -1126,8 +1126,8 @@ def test_magnetics(test_input, expected): ] -@pytest.mark.fetch() -@pytest.mark.issue() +@pytest.mark.fetch +@pytest.mark.issue @pytest.mark.filterwarnings("ignore::RuntimeWarning") @pytest.mark.parametrize(("test_input", "expected", "hemisphere"), mass_change_test) def test_mass_change(test_input, expected, hemisphere): @@ -1158,8 +1158,8 @@ def test_mass_change(test_input, expected, hemisphere): @pytest.mark.parametrize(("test_input", "expected"), basal_melt_test) -@pytest.mark.fetch() -@pytest.mark.issue() +@pytest.mark.fetch +@pytest.mark.issue @pytest.mark.filterwarnings("ignore::RuntimeWarning") def test_basal_melt(test_input, expected): grid = fetch.basal_melt(variable=test_input) @@ -1218,7 +1218,7 @@ def test_basal_melt(test_input, expected): ] -@pytest.mark.fetch() +@pytest.mark.fetch @pytest.mark.filterwarnings("ignore::RuntimeWarning") @pytest.mark.parametrize(("test_input", "expected"), ghf_test) def test_ghf(test_input, expected): @@ -1232,7 +1232,7 @@ def test_ghf(test_input, expected): ) -@pytest.mark.fetch() +@pytest.mark.fetch def test_ghf_points(): df = fetch.ghf(version="burton-johnson-2020", points=True) expected = [ @@ -1278,7 +1278,7 @@ def test_ghf_points(): ] -@pytest.mark.fetch() +@pytest.mark.fetch @pytest.mark.filterwarnings("ignore::RuntimeWarning") @pytest.mark.parametrize(("test_input", "expected"), gia_test) def test_gia(test_input, expected): @@ -1321,7 +1321,7 @@ def test_gia(test_input, expected): ] -@pytest.mark.fetch() +@pytest.mark.fetch @pytest.mark.filterwarnings("ignore::RuntimeWarning") @pytest.mark.parametrize(("test_input", "expected"), crust_test) def test_crustal_thickness(test_input, expected): @@ -1364,7 +1364,7 @@ def test_crustal_thickness(test_input, expected): ] -@pytest.mark.fetch() +@pytest.mark.fetch @pytest.mark.filterwarnings("ignore::RuntimeWarning") @pytest.mark.parametrize(("test_input", "expected"), moho_test) def test_moho(test_input, expected): @@ -1407,7 +1407,7 @@ def test_moho(test_input, expected): ] -@pytest.mark.fetch() +@pytest.mark.fetch @pytest.mark.filterwarnings("ignore::RuntimeWarning") @pytest.mark.parametrize(("test_input", "expected"), geoid_test) def test_geoid(test_input, expected): @@ -1451,7 +1451,7 @@ def test_geoid(test_input, expected): ] -@pytest.mark.fetch() +@pytest.mark.fetch @pytest.mark.filterwarnings("ignore::RuntimeWarning") @pytest.mark.parametrize(("test_input", "expected"), etopo_test) def test_etopo(test_input, expected): @@ -1495,7 +1495,7 @@ def test_etopo(test_input, expected): ] -@pytest.mark.fetch() +@pytest.mark.fetch @pytest.mark.filterwarnings("ignore::RuntimeWarning") @pytest.mark.parametrize(("test_input", "expected"), rema_test) def test_rema(test_input, expected): From 11f4539514d70957743cfb84049cdc0a46aa2cd3 Mon Sep 17 00:00:00 2001 From: mdtanker Date: Mon, 18 Nov 2024 14:16:27 -0500 Subject: [PATCH 3/3] chore: remove ruff commands and use pre-commit --- Makefile | 8 +------- docs/contributing.md | 10 +++------- pyproject.toml | 1 - src/polartoolkit/maps.py | 42 +++++++++++++-------------------------- src/polartoolkit/utils.py | 6 +++--- 5 files changed, 21 insertions(+), 46 deletions(-) diff --git a/Makefile b/Makefile index ecd5b69d..74f98f43 100644 --- a/Makefile +++ b/Makefile @@ -43,19 +43,13 @@ test_fetch: #### #### -format: - ruff format $(STYLE_CHECK_FILES) - check: - ruff check --fix $(STYLE_CHECK_FILES) - -lint: pre-commit run --all-files pylint: pylint $(PROJECT) -style: format check lint pylint +style: check pylint mypy: mypy src/$(PROJECT) diff --git a/docs/contributing.md b/docs/contributing.md index d778c1e9..4e2edbf8 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -151,15 +151,11 @@ This environment now contains your local, editable version of PolarToolkit, mean ### Code style and linting -We use [Ruff](https://docs.astral.sh/ruff/) to format the code so we don't have to -think about it. This allows you to not think about proper indentation, line length, or aligning your code while to development. Before committing, or periodically while you code, run the following to automatically format your code: -``` -make format -``` -Some formatting changes can't be applied automatically. Running the following to see these. +We use [pre-commit](https://pre-commit.com/) to check code style. This can be used locally, by installing pre-commit, or can be used as a pre-commit hook, where it is automatically run by git for each commit to the repository. This pre-commit hook wont add or commit any changes, but will just inform your of what should be changed. Pre-commit is setup within the `.pre-commit-config.yaml` file. There are lots of hooks (processes) which run for each pre-commit call, including [Ruff](https://docs.astral.sh/ruff/) to format and lint the code. This allows you to not think about proper indentation, line length, or aligning your code during development. Before committing, or periodically while you code, run the following to automatically format your code: ``` make check ``` + Go through the output of this and try to change the code based on the errors. Search the error codes on the [Ruff documentation](https://docs.astral.sh/ruff/), which should give suggestions. Re-run the check to see if you've fixed it. Somethings can't be resolved (unsplittable urls longer than the line length). For these, add `# noqa: []` at the end of the line and the check will ignore it. Inside the square brackets add the specific error code you want to ignore. We also use [Pylint](https://pylint.readthedocs.io/en/latest/), which performs static-linting on the code. This checks the code and catches many common bugs and errors, without running any of the code. This check is slightly slower the the `Ruff` check. Run it with the following: @@ -168,7 +164,7 @@ make pylint ``` Similar to using `Ruff`, go through the output of this, search the error codes on the [Pylint documentation](https://pylint.readthedocs.io/en/latest/) for help, and try and fix all the errors and warnings. If there are false-positives, or your confident you don't agree with the warning, add ` # pylint: disable=` at the end of the lines, with the warning code following the `=`. -To run all three of the code checks, use: +To run both pre-commit and pylint together use: ``` make style ``` diff --git a/pyproject.toml b/pyproject.toml index 150dee02..7ae6d8b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -86,7 +86,6 @@ docs = [ ] dev = [ "polartoolkit[interactive,viz,test,docs]", - "ruff", "nox", "pre-commit", "pylint>=3.2", diff --git a/src/polartoolkit/maps.py b/src/polartoolkit/maps.py index 3d8e8f45..f85d98e0 100644 --- a/src/polartoolkit/maps.py +++ b/src/polartoolkit/maps.py @@ -420,7 +420,7 @@ def basemap( add_box( fig, show_region, - pen=kwargs.get("region_pen"), + pen=kwargs.get("region_pen"), # type: ignore[arg-type] ) # add datapoints @@ -1087,7 +1087,7 @@ def plot_grd( add_box( fig, show_region, - pen=kwargs.get("region_pen"), + pen=kwargs.get("region_pen"), # type: ignore[arg-type] ) # plot groundingline and coastlines @@ -1293,7 +1293,7 @@ def add_colorbar( # if no region supplied, get region of current PyGMT figure if region is None: with pygmt.clib.Session() as lib: - region = list(lib.extract_region()) + region = tuple(lib.extract_region()) assert len(region) == 4 # clip grid to plot region @@ -2200,35 +2200,24 @@ def subplots( for i, j in enumerate(grids): with fig.set_panel(panel=i): # if list of cmaps provided, use them - if kwargs.get("cmaps") is not None: - cmap = kwargs.get("cmaps")[i] - # if not, use viridis - else: - cmap = "viridis" + cmaps = kwargs.get("cmaps") + cmap = cmaps[i] if cmaps is not None else "viridis" # if list of titles provided, use them - if kwargs.get("subplot_titles") is not None: - sub_title = kwargs.get("subplot_titles")[i] - else: - sub_title = None + subplot_titles = kwargs.get("subplot_titles") + sub_title = subplot_titles[i] if subplot_titles is not None else None # if list of colorbar labels provided, use them - if kwargs.get("cbar_labels") is not None: - cbar_label = kwargs.get("cbar_labels")[i] - else: - cbar_label = " " + cbar_labels = kwargs.get("cbar_labels") + cbar_label = cbar_labels[i] if cbar_labels is not None else " " # if list of colorbar units provided, use them - if kwargs.get("cbar_units") is not None: - cbar_unit = kwargs.get("cbar_units")[i] - else: - cbar_unit = " " + cbar_units = kwargs.get("cbar_units") + cbar_unit = cbar_units[i] if cbar_units is not None else " " # if list of cmaps limits provided, use them - if kwargs.get("cpt_limits") is not None: - cpt_lims = kwargs.get("cpt_limits")[i] - else: - cpt_lims = None + cpt_limits = kwargs.get("cpt_limits") + cpt_lims = cpt_limits[i] if cpt_limits is not None else None # plot the grids plot_grd( @@ -2313,7 +2302,6 @@ def plot_3d( num_grids = len(grids) # if not provided as a list, make it a list the length of num_grids - if not isinstance(cbar_labels, list): cbar_labels = [cbar_labels] * num_grids if not isinstance(modis, list): @@ -2338,9 +2326,7 @@ def plot_3d( & (all(isinstance(x, float) for x in cpt_lims_list)) ): cpt_lims_list = [cpt_lims_list] * num_grids - if cmap_region is None: - cmap_region = [None] * num_grids - elif ( + if ( isinstance(cmap_region, list) & (len(cmap_region) == 4) & (all(isinstance(x, float) for x in cmap_region)) diff --git a/src/polartoolkit/utils.py b/src/polartoolkit/utils.py index 6cc8246b..72639c29 100644 --- a/src/polartoolkit/utils.py +++ b/src/polartoolkit/utils.py @@ -1112,7 +1112,7 @@ def grd_compare( three xarray.DataArrays: (diff, resampled grid1, resampled grid2) """ shp_mask = kwargs.get("shp_mask") - region: tuple[float, float, float, float] = kwargs.get("region") + region = kwargs.get("region") verbose = kwargs.get("verbose", "e") if isinstance(da1, str): da1 = xr.load_dataarray(da1) @@ -1406,8 +1406,8 @@ def grd_compare( a.set_aspect("equal") if kwargs.get("points") is not None: a.plot(kwargs.get("points").x, kwargs.get("points").y, "k+") # type: ignore[union-attr] - if kwargs.get("show_region") is not None: - show_region = kwargs.get("show_region") + show_region = kwargs.get("show_region") + if show_region is not None: a.add_patch( mpl.patches.Rectangle( xy=(show_region[0], show_region[2]),