Skip to content

Commit

Permalink
style: lint code with black isort and mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
RDWimmers committed Nov 9, 2023
1 parent eafe41c commit 4d06271
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 21 deletions.
22 changes: 20 additions & 2 deletions notebooks/NBxxxxx_SBRA.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)"
]
},
{
Expand Down
11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
4 changes: 2 additions & 2 deletions src/pyvibracore/input/impact_force_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/pyvibracore/input/vibration_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down
12 changes: 6 additions & 6 deletions src/pyvibracore/results/impact_force_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
107 changes: 100 additions & 7 deletions src/pyvibracore/results/vibration_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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"},
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -297,7 +389,7 @@ def plot_reduction(
"failureValueVibrationVelocityVibrationSensitive"
],
linestyle="--",
label="Vr",
label="$Vr_{sensitive}$",
color="orange",
)
axes.axvline(
Expand All @@ -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",
)
Expand All @@ -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
2 changes: 1 addition & 1 deletion tests/test_impact_force.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 4d06271

Please sign in to comment.