From 4d062716356e706afdfa6444d3829a8f472c01bb Mon Sep 17 00:00:00 2001 From: Robin Wimmers Date: Thu, 9 Nov 2023 09:16:26 +0100 Subject: [PATCH] style: lint code with black isort and mypy --- notebooks/NBxxxxx_SBRA.ipynb | 22 +++- pyproject.toml | 11 +- .../input/impact_force_properties.py | 4 +- src/pyvibracore/input/vibration_properties.py | 4 +- .../results/impact_force_result.py | 12 +- src/pyvibracore/results/vibration_result.py | 107 ++++++++++++++++-- tests/test_impact_force.py | 2 +- 7 files changed, 141 insertions(+), 21 deletions(-) diff --git a/notebooks/NBxxxxx_SBRA.ipynb b/notebooks/NBxxxxx_SBRA.ipynb index c4df333..4ec25b2 100644 --- a/notebooks/NBxxxxx_SBRA.ipynb +++ b/notebooks/NBxxxxx_SBRA.ipynb @@ -417,7 +417,7 @@ "outputs": [], "source": [ "if len(upload.value) == 1:\n", - " logging.info(\"Use uploaded geojson file\")\n", + " logging.info(f\"Use uploaded geojson file. File name: {upload.value[0].name}\")\n", " content = upload.value[0].content.tobytes()\n", " with fiona.BytesCollection(content) as f:\n", " crs = f.crs\n", @@ -428,7 +428,25 @@ "fig = map_payload(buildings, location)\n", "\n", "# add basemap\n", - "ctx.add_basemap(fig.axes[0], crs=\"EPSG:28992\", source=ctx.providers.Esri.WorldTopoMap)" + "ctx.add_basemap(fig.axes[0], crs=\"EPSG:28992\", source=ctx.providers.Esri.WorldTopoMap)\n", + "\n", + "buildings[\n", + " [\n", + " \"name\",\n", + " \"monumental\",\n", + " \"category\",\n", + " \"structuralCondition\",\n", + " \"vibrationSensitive\",\n", + " # \"foundationElement\",\n", + " # \"material\",\n", + " # \"thickness\",\n", + " # \"buildingDepth\",\n", + " # \"buildingDepthVibrationSensitive\",\n", + " \"bouwjaar\",\n", + " \"gebruiksdoel\",\n", + " \"status\",\n", + " ]\n", + "].head(10)" ] }, { diff --git a/pyproject.toml b/pyproject.toml index 253c672..2fd48af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,7 +84,16 @@ strict_equality = true install_types = true [[tool.mypy.overrides]] -module = ["matplotlib.*", "requests.*", "pytest.*"] +module = [ + "matplotlib.*", + "requests.*", + "pytest.*", + "geopandas.*", + "shapely.*", + "pygef.*", + "mpl_toolkits.*", + "nuclei.*" +] ignore_missing_imports = true [[tool.mypy.overrides]] diff --git a/src/pyvibracore/input/impact_force_properties.py b/src/pyvibracore/input/impact_force_properties.py index 823c10d..1d51251 100644 --- a/src/pyvibracore/input/impact_force_properties.py +++ b/src/pyvibracore/input/impact_force_properties.py @@ -73,8 +73,8 @@ def from_sheet_pile_name( ) return cls( - areaShaftSpecific=props.get("area_shaft_specific"), - areaTipSpecific=props.get("area_tip_specific"), + areaShaftSpecific=props.get("area_shaft_specific"), # type: ignore + areaTipSpecific=props.get("area_tip_specific"), # type: ignore amountOfSheetPiles=amount_of_sheet_piles, slotResistanceSpecific=slot_resistance_specific, sheetPileName=name, diff --git a/src/pyvibracore/input/vibration_properties.py b/src/pyvibracore/input/vibration_properties.py index 9a9179a..1114604 100644 --- a/src/pyvibracore/input/vibration_properties.py +++ b/src/pyvibracore/input/vibration_properties.py @@ -156,7 +156,7 @@ def create_prepal_payload( frequency_vibration_sensitive: float = 40.0, measurement_type: Literal["indicative", "limited", "extensive"] = "extensive", hysteretic_damping_barkan: float = -0.05, -): +) -> dict: """ Create payload for VibraCore call `cur166/validation/multi` @@ -295,7 +295,7 @@ def create_cur166_payload( ] = "Amsterdam", measurement_type: Literal["indicative", "limited", "extensive"] = "extensive", methode_safety_factor: Literal["CUR", "exact"] = "exact", -): +) -> dict: """ Create payload for VibraCore call `cur166/validation/multi` diff --git a/src/pyvibracore/results/impact_force_result.py b/src/pyvibracore/results/impact_force_result.py index 57a86d4..61673d8 100644 --- a/src/pyvibracore/results/impact_force_result.py +++ b/src/pyvibracore/results/impact_force_result.py @@ -160,13 +160,13 @@ class ImpactForceTable: betaFrictionalResistance: Sequence[float] | None betaPointResistance: Sequence[float] | None - correctedConeResistance: Sequence[float] - depthOffset: Sequence[float] - frictionalResistance: Sequence[float] - pointResistance: Sequence[float] + correctedConeResistance: Sequence[float] | None + depthOffset: Sequence[float] | None + frictionalResistance: Sequence[float] | None + pointResistance: Sequence[float] | None sheetResistance: Sequence[float] | None - slotResistance: Sequence[float] - totalResistance: Sequence[float] + slotResistance: Sequence[float] | None + totalResistance: Sequence[float] | None def __post_init__(self) -> None: raw_lengths = [] diff --git a/src/pyvibracore/results/vibration_result.py b/src/pyvibracore/results/vibration_result.py index 589ffa0..48dd1fa 100644 --- a/src/pyvibracore/results/vibration_result.py +++ b/src/pyvibracore/results/vibration_result.py @@ -13,6 +13,7 @@ def _north_arrow(axes: plt.Axes) -> None: + """Add north arrow to axes""" x, y, arrow_length = 0.05, 0.98, 0.1 axes.annotate( "N", @@ -27,6 +28,7 @@ def _north_arrow(axes: plt.Axes) -> None: def _scalebar(axes: plt.Axes) -> None: + """Add size bar to axes""" scalebar = AnchoredSizeBar( axes.transData, 20, @@ -43,6 +45,15 @@ def _scalebar(axes: plt.Axes) -> None: @dataclass(frozen=True) class VibrationResults: + """ + Dataclass that holds the information from `/cur166/validation/multi` or `/prepal/validation/multi` + + Attributes + ----------- + gdf: gpd.GeoDataFrame + + """ + gdf: gpd.GeoDataFrame @classmethod @@ -68,7 +79,37 @@ def map( figsize: Tuple[float, float] = (10.0, 12.0), settings: dict | None = None, **kwargs: Any, - ): + ) -> plt.Figure: + """ + Create map plot of the results + + Parameters + ---------- + source_location: + location of the vibration source + title: + Legend title + figsize: + Size of the activate figure, as the `plt.figure()` argument. + settings: + Plot settings used in plot: default settings are: + + { + "source_location": {"label": "Trillingsbron", "color": "black"}, + "insufficient_cat1": { + "label": "Voldoet Niet - Cat.1", + "color": "orange", + }, + "insufficient_cat2": {"label": "Voldoet Niet - Cat.2", "color": "red"}, + "sufficient": {"label": "Voldoet", "color": "green"}, + } + **kwargs: + All additional keyword arguments are passed to the `pyplot.subplots()` call. + + Returns + ------- + Figure + """ if settings is None: settings = { "source_location": {"label": "Trillingsbron", "color": "black"}, @@ -159,7 +200,39 @@ def map_payload( figsize: Tuple[float, float] = (10.0, 12.0), settings: dict | None = None, **kwargs: Any, -): +) -> plt.Figure: + """ + Create map of the input building settings. + + Parameters + ---------- + gdf: + GeoDataFrame of the input buildings + source_location: + location of the vibration source + title: + Legend title + figsize: + Size of the activate figure, as the `plt.figure()` argument. + settings: + Plot settings used in plot: default settings are: + + { + "source_location": {"label": "Trillingsbron", "color": "black"}, + "insufficient_cat1": { + "label": "Voldoet Niet - Cat.1", + "color": "orange", + }, + "insufficient_cat2": {"label": "Voldoet Niet - Cat.2", "color": "red"}, + "sufficient": {"label": "Voldoet", "color": "green"}, + } + **kwargs: + All additional keyword arguments are passed to the `pyplot.subplots()` call. + + Returns + ------- + Figure + """ if settings is None: settings = { "source_location": {"label": "Trillingsbron", "color": "black"}, @@ -252,7 +325,26 @@ def plot_reduction( sensitive: bool = False, figsize: Tuple[float, float] = (8, 8), **kwargs: Any, -): +) -> plt.Figure: + """ + PLot single vibration prediction reduction plot + + Parameters + ---------- + response_dict: + response of the single prepal or cur166 endpoint. + sensitive: + Default is False + Flag that indicates if vibration sensitive results are included + figsize: + Size of the activate figure, as the `plt.figure()` argument. + **kwargs: + All additional keyword arguments are passed to the `pyplot.subplots()` call. + + Returns + ------- + + """ kwargs_subplot = { "figsize": figsize, "tight_layout": True, @@ -297,7 +389,7 @@ def plot_reduction( "failureValueVibrationVelocityVibrationSensitive" ], linestyle="--", - label="Vr", + label="$Vr_{sensitive}$", color="orange", ) axes.axvline( @@ -311,13 +403,13 @@ def plot_reduction( # excitation axes.axhline( y=response_dict["calculation"]["failureValueExcitationVelocity"], - linestyle="--", - label="Vr", + linestyle="-.", + label="$Vr_{velocity}$", color="orange", ) axes.axvline( x=response_dict["calculation"]["distanceRequiredExcitationVelocity"], - linestyle="--", + linestyle="-.", label="Distance required", color="black", ) @@ -333,5 +425,6 @@ def plot_reduction( axes.set_ylabel("Vibration velocity [mm/s]") axes.set_xlim(0, 50) axes.set_ylim(0, 30) + axes.legend("best") return fig diff --git a/tests/test_impact_force.py b/tests/test_impact_force.py index 4673b96..77d8449 100644 --- a/tests/test_impact_force.py +++ b/tests/test_impact_force.py @@ -18,7 +18,7 @@ def test_vibration_source(): def test_create_multi_cpt_impact_force_payload(cpt, mock_classify_response): - payload = create_multi_cpt_impact_force_payload( + create_multi_cpt_impact_force_payload( [cpt], {"S-TUN-016-PG": mock_classify_response}, VibrationSource.from_sheet_pile_name("AZ12-770"),