Skip to content

Commit

Permalink
Merge pull request #333 from robbievanleeuwen/add-nbqa
Browse files Browse the repository at this point in the history
Add nbQA to pre-commit (runs black, isort and pyupgrade on jupyter notebooks)
  • Loading branch information
robbievanleeuwen committed Oct 9, 2023
2 parents 75453ca + e1e2390 commit b451449
Show file tree
Hide file tree
Showing 27 changed files with 203 additions and 137 deletions.
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Expand Up @@ -68,3 +68,14 @@ repos:
rev: 0.6.1
hooks:
- id: nbstripout
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.7.0
hooks:
- id: nbqa-black
additional_dependencies: [black==23.9.1]
- id: nbqa-pyupgrade
additional_dependencies: [pyupgrade==3.14.0]
args: ["--py39-plus"]
- id: nbqa-isort
additional_dependencies: [isort==5.12.0]
args: [--profile=black]
3 changes: 3 additions & 0 deletions docs/examples/advanced/advanced_plot.ipynb
Expand Up @@ -41,6 +41,7 @@
"source": [
"from sectionproperties.pre.library import rectangular_hollow_section\n",
"\n",
"\n",
"geom = rectangular_hollow_section(d=100, b=100, t=6, r_out=15, n_r=8)"
]
},
Expand All @@ -61,6 +62,7 @@
"source": [
"from sectionproperties.analysis import Section\n",
"\n",
"\n",
"geom.create_mesh(mesh_sizes=[5])\n",
"sec = Section(geometry=geom)"
]
Expand Down Expand Up @@ -104,6 +106,7 @@
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"\n",
"# plot the geometry\n",
"ax = geom.plot_geometry(\n",
" labels=[],\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/advanced/peery.ipynb
Expand Up @@ -39,8 +39,8 @@
"metadata": {},
"outputs": [],
"source": [
"from sectionproperties.pre.library import nastran_sections\n",
"from sectionproperties.analysis import Section"
"from sectionproperties.analysis import Section\n",
"from sectionproperties.pre.library import nastran_sections"
]
},
{
Expand Down
5 changes: 4 additions & 1 deletion docs/examples/advanced/rectangle_torsion.ipynb
Expand Up @@ -33,6 +33,7 @@
"source": [
"import numpy as np\n",
"\n",
"\n",
"# list of aspect ratios to analyse (10^0 = 1 to 10^1.301 = 20)\n",
"# logspace used to concentrate data near aspect ratio = 1\n",
"aspect_ratios = np.logspace(0, 1.301, 50)\n",
Expand All @@ -56,8 +57,9 @@
"metadata": {},
"outputs": [],
"source": [
"from sectionproperties.pre.library import rectangular_section\n",
"from sectionproperties.analysis import Section\n",
"from sectionproperties.pre.library import rectangular_section\n",
"\n",
"\n",
"for ar in aspect_ratios:\n",
" # calculate rectangle dimensions\n",
Expand Down Expand Up @@ -94,6 +96,7 @@
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"\n",
"_, ax = plt.subplots()\n",
"ax.plot(aspect_ratios, torsion_constants, \"k-\")\n",
"ax.set_xlim(0, 21)\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/advanced/trapezoidal_torsion.ipynb
Expand Up @@ -33,9 +33,9 @@
"import numpy as np\n",
"from shapely import Polygon\n",
"\n",
"from sectionproperties.analysis import Section\n",
"from sectionproperties.pre import Geometry\n",
"from sectionproperties.pre.library import rectangular_section, triangular_section\n",
"from sectionproperties.analysis import Section"
"from sectionproperties.pre.library import rectangular_section, triangular_section"
]
},
{
Expand Down
6 changes: 5 additions & 1 deletion docs/examples/analysis/export_fibre_section.ipynb
Expand Up @@ -36,6 +36,7 @@
"from sectionproperties.post.fibre import to_fibre_section\n",
"from sectionproperties.pre.library import i_section\n",
"\n",
"\n",
"geom = i_section(d=203, b=133, t_f=7.8, t_w=5.8, r=8.9, n_r=8)\n",
"geom.create_mesh(mesh_sizes=10)\n",
"\n",
Expand All @@ -61,6 +62,7 @@
"source": [
"from shutil import which\n",
"\n",
"\n",
"# write the fibre section to a file\n",
"# uncomment below to write file\n",
"# with open('200UB25.4.sp', 'w') as f:\n",
Expand Down Expand Up @@ -134,6 +136,7 @@
"source": [
"from sectionproperties.analysis import Section\n",
"\n",
"\n",
"sec = Section(geom)\n",
"sec.calculate_geometric_properties()\n",
"x, y = sec.get_c()\n",
Expand Down Expand Up @@ -185,6 +188,7 @@
"source": [
"from os.path import exists\n",
"\n",
"\n",
"# write the fibre section to a file with material tag replaced\n",
"# uncomment below to write file\n",
"# with open('200UB25.4.sp', 'w') as f:\n",
Expand Down Expand Up @@ -221,8 +225,8 @@
"outputs": [],
"source": [
"if result_available:\n",
" from matplotlib import pyplot as plt\n",
" import numpy as np\n",
" from matplotlib import pyplot as plt\n",
"\n",
" data = np.loadtxt(\"R1-RF42.txt\")\n",
" twist = data[:, 0] * 0.1\n",
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/analysis/frame_analysis.ipynb
Expand Up @@ -48,8 +48,9 @@
"metadata": {},
"outputs": [],
"source": [
"from sectionproperties.pre.library import polygon_hollow_section\n",
"from sectionproperties.analysis import Section\n",
"from sectionproperties.pre.library import polygon_hollow_section\n",
"\n",
"\n",
"geom = polygon_hollow_section(d=600, t=12, n_sides=12, r_in=20, n_r=8)\n",
"geom.create_mesh(mesh_sizes=20)\n",
Expand All @@ -76,6 +77,7 @@
"source": [
"import time\n",
"\n",
"\n",
"start = time.time()\n",
"sec.calculate_geometric_properties()\n",
"sec.calculate_warping_properties()\n",
Expand Down
4 changes: 4 additions & 0 deletions docs/examples/analysis/geometric_analysis.ipynb
Expand Up @@ -43,6 +43,7 @@
"source": [
"from sectionproperties.pre.library import i_section\n",
"\n",
"\n",
"geom = i_section(d=203, b=133, t_f=7.8, t_w=5.8, r=8.9, n_r=8)"
]
},
Expand All @@ -63,6 +64,7 @@
"source": [
"from sectionproperties.analysis import Section\n",
"\n",
"\n",
"geom.create_mesh(mesh_sizes=5)\n",
"sec = Section(geometry=geom)"
]
Expand Down Expand Up @@ -175,6 +177,7 @@
"source": [
"from sectionproperties.pre.library import channel_section\n",
"\n",
"\n",
"# create 150 pfc geometry\n",
"pfc = channel_section(d=150, b=75, t_f=9.5, t_w=6, r=10, n_r=8)\n",
"pfc.plot_geometry(legend=False)"
Expand Down Expand Up @@ -265,6 +268,7 @@
"from rich.console import Console\n",
"from rich.table import Table\n",
"\n",
"\n",
"# setup table\n",
"table = Table(title=\"Section Properties Comparison\")\n",
"table.add_column(\"Property\", justify=\"left\", style=\"cyan\", no_wrap=True)\n",
Expand Down
3 changes: 3 additions & 0 deletions docs/examples/analysis/plastic_analysis.ipynb
Expand Up @@ -35,6 +35,7 @@
"source": [
"from sectionproperties.pre.library import mono_i_section\n",
"\n",
"\n",
"geom = mono_i_section(d=200, b_t=50, b_b=100, t_ft=12, t_fb=8, t_w=6, r=8, n_r=8)"
]
},
Expand All @@ -55,6 +56,7 @@
"source": [
"from sectionproperties.analysis import Section\n",
"\n",
"\n",
"geom.create_mesh(mesh_sizes=0)\n",
"sec = Section(geometry=geom)\n",
"sec.plot_mesh(materials=False)"
Expand Down Expand Up @@ -209,6 +211,7 @@
"source": [
"from sectionproperties.pre.library import angle_section\n",
"\n",
"\n",
"geom = angle_section(d=150, b=90, t=12, r_r=10, r_t=5, n_r=8)\n",
"geom.create_mesh(mesh_sizes=0)\n",
"sec = Section(geometry=geom)\n",
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/analysis/stress_analysis.ipynb
Expand Up @@ -39,8 +39,9 @@
"metadata": {},
"outputs": [],
"source": [
"from sectionproperties.pre.library import rectangular_hollow_section\n",
"from sectionproperties.analysis import Section\n",
"from sectionproperties.pre.library import rectangular_hollow_section\n",
"\n",
"\n",
"geom = rectangular_hollow_section(d=100, b=150, t=6, r_out=15, n_r=8)\n",
"geom.create_mesh(mesh_sizes=[2])\n",
Expand Down
4 changes: 4 additions & 0 deletions docs/examples/analysis/warping_analysis.ipynb
Expand Up @@ -37,6 +37,7 @@
"source": [
"from sectionproperties.pre.library import channel_section\n",
"\n",
"\n",
"geom = channel_section(d=250, b=90, t_f=15, t_w=8, r=12, n_r=8)"
]
},
Expand All @@ -57,6 +58,7 @@
"source": [
"from sectionproperties.analysis import Section\n",
"\n",
"\n",
"geom.create_mesh(mesh_sizes=7)\n",
"sec = Section(geometry=geom)\n",
"sec.plot_mesh(materials=False)"
Expand All @@ -79,6 +81,7 @@
"source": [
"import time\n",
"\n",
"\n",
"sec.calculate_geometric_properties()\n",
"\n",
"# direct solver\n",
Expand Down Expand Up @@ -165,6 +168,7 @@
"source": [
"from sectionproperties.pre.library import rectangular_section\n",
"\n",
"\n",
"# create an unconnected mesh\n",
"rect = rectangular_section(d=10, b=10)\n",
"geom = rect + rect.shift_section(x_offset=20)\n",
Expand Down
6 changes: 5 additions & 1 deletion docs/examples/geometry/advanced_geometry.ipynb
Expand Up @@ -47,8 +47,9 @@
"metadata": {},
"outputs": [],
"source": [
"from sectionproperties.pre.library import i_section\n",
"from sectionproperties.analysis import Section\n",
"from sectionproperties.pre.library import i_section\n",
"\n",
"\n",
"i_sec1 = i_section(d=250, b=150, t_f=13, t_w=10, r=12, n_r=12)\n",
"i_sec2 = i_sec1.rotate_section(angle=45)"
Expand Down Expand Up @@ -91,6 +92,7 @@
"source": [
"from sectionproperties.pre import Material\n",
"\n",
"\n",
"# just some differing properties\n",
"mat1 = Material(\n",
" name=\"Material_1\",\n",
Expand Down Expand Up @@ -335,6 +337,7 @@
"source": [
"from sectionproperties.pre.library import rectangular_section\n",
"\n",
"\n",
"s1 = rectangular_section(d=1, b=1)\n",
"s2 = rectangular_section(d=0.5, b=0.5).shift_section(x_offset=1, y_offset=0.25)\n",
"geom = s1 + s2\n",
Expand Down Expand Up @@ -557,6 +560,7 @@
"source": [
"from sectionproperties.pre import CompoundGeometry\n",
"\n",
"\n",
"# points for four squares are created\n",
"points = [\n",
" [-50.0, 50.0], # square 1\n",
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/geometry/create_mesh.ipynb
Expand Up @@ -27,13 +27,13 @@
"metadata": {},
"outputs": [],
"source": [
"from sectionproperties.analysis import Section\n",
"from sectionproperties.pre import CompoundGeometry\n",
"from sectionproperties.pre.library import (\n",
" rectangular_section,\n",
" rectangular_hollow_section,\n",
" box_girder_section,\n",
")\n",
"from sectionproperties.analysis import Section"
" rectangular_hollow_section,\n",
" rectangular_section,\n",
")"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/geometry/geometry_cad.ipynb
Expand Up @@ -27,8 +27,8 @@
"metadata": {},
"outputs": [],
"source": [
"from sectionproperties.pre import Geometry, CompoundGeometry\n",
"from sectionproperties.analysis import Section"
"from sectionproperties.analysis import Section\n",
"from sectionproperties.pre import CompoundGeometry, Geometry"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/geometry/geometry_coordinates.ipynb
Expand Up @@ -31,8 +31,8 @@
"metadata": {},
"outputs": [],
"source": [
"from sectionproperties.pre import CompoundGeometry\n",
"from sectionproperties.analysis import Section"
"from sectionproperties.analysis import Section\n",
"from sectionproperties.pre import CompoundGeometry"
]
},
{
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/geometry/geometry_manipulation.ipynb
Expand Up @@ -35,9 +35,9 @@
"outputs": [],
"source": [
"from sectionproperties.pre.library import (\n",
" rectangular_section,\n",
" channel_section,\n",
" rectangular_hollow_section,\n",
" rectangular_section,\n",
")"
]
},
Expand Down Expand Up @@ -204,6 +204,7 @@
"# combine resultant geometries into a CompoundGeometry object\n",
"from sectionproperties.pre import CompoundGeometry\n",
"\n",
"\n",
"geom = CompoundGeometry(geoms=left_geoms + right_geoms)\n",
"geom.plot_geometry()"
]
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/geometry/section_library.ipynb
Expand Up @@ -37,8 +37,8 @@
"metadata": {},
"outputs": [],
"source": [
"from sectionproperties.pre.library import circular_section\n",
"from sectionproperties.analysis import Section"
"from sectionproperties.analysis import Section\n",
"from sectionproperties.pre.library import circular_section"
]
},
{
Expand Down Expand Up @@ -144,8 +144,8 @@
"source": [
"ixx_c, iyy_c, ixy_c = sec.get_ic()\n",
"j = sec.get_j()\n",
"print(\"Ixx + Iyy + Ixy = {0:.3f}\".format(ixx_c + iyy_c + ixy_c))\n",
"print(\"J = {0:.3f}\".format(j))"
"print(f\"Ixx + Iyy + Ixy = {ixx_c + iyy_c + ixy_c:.3f}\")\n",
"print(f\"J = {j:.3f}\")"
]
},
{
Expand Down
6 changes: 5 additions & 1 deletion docs/examples/materials/assign_materials.ipynb
Expand Up @@ -94,8 +94,10 @@
"outputs": [],
"source": [
"from shapely import Polygon\n",
"from sectionproperties.pre import Geometry\n",
"\n",
"from sectionproperties.analysis import Section\n",
"from sectionproperties.pre import Geometry\n",
"\n",
"\n",
"# assign steel to a shapely polygon\n",
"poly = Polygon([(0, 0), (5, 2), (3, 7), (1, 6)])\n",
Expand Down Expand Up @@ -158,6 +160,7 @@
"source": [
"from sectionproperties.pre.library import polygon_hollow_section\n",
"\n",
"\n",
"geom = polygon_hollow_section(d=200, t=6, n_sides=8, r_in=20, n_r=12, material=steel)\n",
"geom.create_mesh(mesh_sizes=10)\n",
"Section(geometry=geom).plot_mesh()"
Expand All @@ -182,6 +185,7 @@
"source": [
"from sectionproperties.pre.library import rectangular_section\n",
"\n",
"\n",
"# create a rectangular section with the default material\n",
"geom = rectangular_section(d=16, b=100)\n",
"geom.create_mesh(mesh_sizes=10)\n",
Expand Down

0 comments on commit b451449

Please sign in to comment.