Skip to content

Instantly share code, notes, and snippets.

View joreilly86's full-sized avatar

James O'Reilly joreilly86

View GitHub Profile
@joreilly86
joreilly86 / anchor_check.py
Last active April 25, 2025 19:59
#068 - Structuring Engineering Calculations in Python | 01 - The Basics
# ---- FULL CONSOLIDATED SCRIPT FROM FLOCODE NEWSLETTER #068 - Structuring Engineering Calculations in Python | 01 - The Basics
# https://flocode.substack.com/
import math # Provides math constants (pi) and functions (sqrt)
# ---- FUNDAMENTAL INPUT PARAMETERS & ASSUMPTIONS ----
# Basic geometry, material properties, loads, factors per ACI 318-19
# Anchor Properties
da = 0.75 # Anchor diameter (in)
@joreilly86
joreilly86 / 061-pytorch_beam_example.py
Last active March 7, 2025 23:29
ML for Structural Beam Design: PyTorch example comparing linear and non-linear neural networks to traditional bending moment calculations for steel beam depth. Demonstrates augmenting engineering formulas with data-driven learning. (Flocode Newsletter #062)
"""
Flocode Newsletter #062 - Machine Learning for Engineers: When and How Should We Use it?
This script demonstrates a simple application of machine learning (ML) to a
structural engineering problem: predicting the required depth of a steel beam
based on its span and applied uniformly distributed load (UDL). It compares
three ML models (linear, non-linear, and deep non-linear neural networks)
with a traditional calculation based on the bending moment formula.
The key concept is that the ML models are trained on data *derived* from the
@joreilly86
joreilly86 / #052 - Python Dictionaries.py
Created November 1, 2024 19:17
This code supports Flocode Newsletter #052 - Python Dictionaries for Engineers
# This code supports #052 - Python Dictionaries for Engineers
# It demonstrates the use of dictionaries, Pandas, and Polars for engineering data handling
import pandas as pd
import polars as pl
from datetime import datetime, timedelta
import random
# Dictionary storing material attributes
steel = {
@joreilly86
joreilly86 / create_notebook_project.py
Created October 23, 2024 23:47
A simple Python project setup template using Cookiecutter to automate directory structure creation and environment management. This template includes folders for data and source code, a Jupyter notebook, and integrates with uv for easy virtual environment setup and package management. Streamline your workflow and standardize your project setup w…
import json
import os
import shutil
import subprocess
import sys
from cookiecutter.main import cookiecutter
# Template Directory Structure
template = {
@joreilly86
joreilly86 / bayesian_methods.py
Created August 11, 2024 05:44
#043 - Bayesian Methods
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from scipy.stats import norm
# Set the background color to black
plt.style.use('dark_background')
# Step 1: Define the prior distribution for the remaining fatigue life (in years)
prior_mean = 20 # Prior mean fatigue life in years
@joreilly86
joreilly86 / #027 - Data Structures for Engineers: Pandas 101.py
Last active April 12, 2024 15:10
#027 - Data Structures for Engineers: Pandas 101
# -----------------------------------------------------------------------------
# #027 - Data Structures for Civil/Structural Engineers: Pandas 101
# -----------------------------------------------------------------------------
'''
Hi everybody from the flocode newsletter πŸ‘‹
This is all the code from article #027 - Data Structures for Civil/Structural Engineers:
Pandas 101
@joreilly86
joreilly86 / #027 - Thinking Programmatically.py
Last active March 26, 2024 23:47
Sample code from Substack Post
# ==========================================================
# Prepare Pseudocode for Calculating Concrete Volume
# ==========================================================
FUNCTION calculate_concrete_volume(length, width, depth)
# Calculate the area of the floor slab
area = length * width
# Calculate the volume of concrete required
@joreilly86
joreilly86 / 023_numpy_example.py
Created February 23, 2024 16:37
Numpy example from Flocode Newsletter #023 - The Best Python Libraries for Civil/Structural Engineering
import numpy as np
# Constants
M = 140 # Moment at the cross-section (kN.m)
I = 102_000_000 # Moment of inertia in mm^4
y = np.array([-150, -100, -50, 0, 50, 100, 150]) # Distance from the neutral axis in mm
# Bending stress calculation
sigma = ((M * 1e6) * y) / I # Convert M from kN.m to N.mm
@joreilly86
joreilly86 / simply_supported_beam_function.py
Created February 8, 2024 19:37
Function for simply supported beam
import numpy as np
import matplotlib.pyplot as plt
def plot_beam_diagrams(length, w):
"""
Plot the shear force and bending moment diagrams for a simply supported beam.
Parameters:
- length: Length of the beam (m)
- w: Magnitude of the uniformly distributed load (kN/m)
@joreilly86
joreilly86 / simply_supported_beam.py
Created February 5, 2024 05:22
#23 - A Simply Supported Beam in Python, a simple code snippet for calculating and plotting the shear force and bending moment diagrams for a beam under a uniformly distributed load.
import numpy as np
import matplotlib.pyplot as plt
# Beam parameters
length = 10 # Length of the beam (m)
w = 10 # Uniformly distributed load in kN/m
# Functions
def shear_force(x):
return w * (length / 2 - x) # kN