#010 - A Roadmap for Learning Python for Civil/Structural Engineering
Learn to blend programming skills with engineering calculations and industry specific applications.
This post is a high-level overview of the Python landscape as it relates to civil and structural engineers. This is not a technical post. Instead, I want to give you a rough idea of the various domains within the Python programming language. The hard part for many beginners is figuring out where to start and what’s involved.
This is what we do at Flocode, we shed light on the Python landscape for all civil and structural engineers. If you want to know more, drop by flocode.dev or connect with me on Linkedin. The waitlist is now open.
Why should Engineers Learn Python?
There are many reasons why Engineers should learn Python. I’ve noted a few below. There are many more that become apparent as you begin to use Python.
Python is an asset for engineers due to its simplicity and versatility. It enables the automation of repetitive tasks, such as data entry and analysis, which can significantly streamline workflow efficiency. Complex mathematical models and simulations can be executed with relative ease, which allows for custom analyses without the steep learning curve often associated with other programming languages.
Python's extensive library collection, much like apps for a smartphone, enhances and diversifies its functionality across a wide range of domains and subjects. NumPy for numerical computations and pandas for data manipulation, are tailored to handle the large data sets common in engineering tasks. This allows engineers to delve deeper into data analysis, unlocking insights that inform better decision-making.
Python’s ability to interface with other proprietary commercial software or online databases through APIs extends its utility. Engineers can create custom solutions that bridge the gaps between different software tools and disciplines.
Python is capable of building both local and web applications to provide custom tools for you, your team or your clients without needing a degree in computer science or specialized skills in full-stack software engineering.
Python is the language of choice in the realms of Data Science, Artificial Intelligence (AI), and Machine Learning (ML), fields that are profoundly transforming industries across the globe. These domains offer immense potential for predictive modelling, automation, and intelligent data analysis, informed decision-making and innovative engineering solutions.
It’s free and open-source. It requires no licence, no specific accreditation or training to start using it, other than knowing how to get started. It’s a high-leverage, low-cost tool that can dramatically increase your technical reach. And that goes for all technical knowledge-based workers, not just engineers.
Python was created in 1989 by Dutchman, Guido van Rossum.
When he began implementing Python, Guido van Rossum was also reading the published scripts from “Monty Python's Flying Circus”, a BBC comedy series from the 1970s. Van Rossum thought he needed a name that was short, unique, and slightly mysterious, so he decided to call the language Python. - From the official Python Docs.
In some ways, the evolution of the cell phone from a simple communication tool to a compact personal computer represented a seismic shift in technological reach for many people. Similarly, Python has catalyzed a paradigm shift in my own engineering perspective, vastly extending my capabilities and engineering impact.
But why wouldn’t I just use Excel?
This is hands-down the most common question I get asked. It’s a fair question that I will tackle some day in a dedicated post on the topic. But it becomes dogmatic so I tend to avoid it. The short answer is if Excel works for your purposes, then go ahead and use it.
Excel is awesome, I used it for years and it’s great but it’s like comparing a concrete bench with a soft leather recliner. They’re both seats and you can sit on each of them just fine but they’re not the same.
If you want to expand your utility, keep reading. If you want to have an internet meltdown while defending the virtues of Excel, lace up, hydrate yourself, and let me have it in the comments.
Starting the Python Journey
For engineers venturing into Python, you have a few options to get started.
If your preference is to buckle up and take the fast lane, begin by installing Python on your machine, reading the official Python documentation and familiarizing yourself with its environment. This approach is essentially drinking from a firehose so if you feel overwhelmed, come back to this post.
For a simpler more enjoyable approach, you can dip your toes and actually try Python without installing anything, you can check out the following cloud notebooks (these options all have free tiers) such as:
You can even check out this free codespace on Github 👇:
Flocode's Introductory Codespace for Engineers 🚀
Let me know if this link has broken, it’s been a little temperamental! Just head over to GitHub (you’ll need to register a free account), and you can open up this project in a codespace by clicking the dropdown on the green “Use this template” button.
Cloud notebooks remove the headaches involved in setting up and managing local environments on your machine. You can read about about coding environments and best practices here 👇.
#015 - Python Essentials | 02 - Python Environments Simplified
Exploring Python's Engineering Foundations
Now you’re ready to engage with beginner's materials that cover the essentials of variables, data types, and basic operations. These elements are the nuts and bolts of Python programming and provide the groundwork for more advanced engineering tasks. You should look into:
Mastering Syntax: The first step is mastering the basics of syntax, and setting a strong foundation for further learning. In programming terms, Python's syntax (the structure and logic of the language) is as intuitive as it gets, making it ideal for engineers new to programming. That’s not to say it’s easy. You still have to learn the basics and there are no shortcuts around this but a couple of weeks of practice will see you make huge leaps in your capabilities.
Understanding Control Flow: Next, focus on control flow structures. These are crucial as they guide the logical flow of your programs, determining how and when certain blocks of code are executed.
Exploring Functions: After grasping control flow, delve into functions. Functions are essential for executing repetitive tasks or complex, logic-dependent engineering calculations. The importance and flexibility of functions can not be overstated.
Grasp these concepts firmly, as they are the core tools for building robust engineering calculations, tools and applications. This information took me some time to process and consolidate. While you may understand the concepts pretty quickly, it’s another layer of abstraction when you begin thinking in terms of such concepts and constructing the programmatic logic to achieve your objectives.
This requires a significant shift in how you frame and think about problems. There’s a profound simplicity to this kind of fundamental procedural logic that is not immediately apparent in most of the commercial tools engineers use today.
Be patient with yourself during this period, this is where the light bulbs start to turn on.
Your Engineering Toolbox
Python's true strength for civil and structural engineers lies in its rich ecosystem of libraries and frameworks. There are over 137,000 Python libraries out there, there’s a good chance one of them can help you solve your problem.
Libraries like NumPy facilitate complex mathematical computations, while Pandas streamlines data manipulation—a frequent necessity in handling engineering datasets and managing Excel spreadsheets and other data structures. Visualization libraries such as Matplotlib and Seaborn translate quantitative findings into clear, communicable visuals, a must-have skill in data-driven engineering disciplines. Being able to visually check data for outliers or peaks/valleys is incredibly useful in so many scenarios as a structural or civil engineer. I use NumPy, Pandas and Matplolib for almost every Python project, these libraries alone can take you incredibly far.
This vast ecosystem of libraries opens doors to efficiently addressing a wide array of scientific and engineering challenges. There are libraries for all sorts of civil and structural engineering applications. A few of my other favourites…
Pynite: A structural engineering package used for the analysis and design of beams and frames.
AnaStruct: This is a simple finite element analysis package for 2D structural analysis. It's useful for analyzing statically determinate and indeterminate structures.
pySeismo: A Python library for performing 1D seismic site response analysis.
pySlope: A 2D slope stability module based on bishops method of slices.
ChannelFlowLib: Modules to use in solving hydraulic elements of an open channel.
There are many, many more out there, all free and open-source. Can I verify their accuracy in a professional context? Of course not. But you can see the code, no black boxes. If it works for you, use it.
You are welcome to my free Notion database of Python libraries for Civil and Structural Engineers. If you don’t use Notion, highly recommend it.
A Suggested Roadmap
Once you get a handle on the basics, you have the tools to do some serious computation. From here on out, it’s about figuring out how you can use Python to get the most out of it for your specific objectives.
The suggested sequential curriculum below is based on my personal preferences and experience. There’s no hard and fast rule. Just get going and dive in.
Introduction to Python
Installation and setup
Basic syntax and command line operations
Understanding of data types, variables, and operators
Control Structures and Functions
Conditional statements
Loops: for, while, break, pass, ranges
Defining and using functions
Data Handling
Lists, tuples, dictionaries, and sets
File I/O basics
Introduction to pandas for data analysis and spreadsheet manipulation
Numerical Computation and Engineering Libraries
NumPy for numerical and scientific computation
SciPy for additional functionality on top of NumPy
Data Visualization
Matplotlib or Plotly for creating static, animated, and interactive visualizations
Seaborn for statistical data visualization
This much will get you pretty far, once you feel comfortable with all of these topics, it’s time to move towards intermediate Python development concepts.
Intermediate Python Concepts
Git and Version Control
Object-Oriented Programming
Building local apps, web apps or interactive dashboards with GUI’s (Shiny, Solara, Streamlit, Gradio and others)
Connecting services, API’s and Data Streams
Error and exception handling
Debugging and testing Python code
Performance optimization techniques
More advanced Python programming principles (the language is incredibly deep)
Interfacing with Engineering Software
Inter-application communication and control using COM and OLE
Automating CAD/Revit software with Python scripts
Using Python with structural analysis software (e.g., SAP2000, ETABS, ANSYS)
Continuing Education and Development
All of these topics can and will keep you busy for years. Feeling overwhelmed? I certainly was when I started. But don’t worry because you can start doing extremely useful things within 2 to 3 weeks of starting to learn Python and from there it simply snowballs, with your progress building steadily as your skills and your understanding consolidate.
Embrace the journey, take your time and enjoy the process, even the moments when you look at the screen and put your head in your hands and think “What the **** is wrong with this? Why won’t it just work?”. I won’t sugarcoat it, you’ll get frustrated. But it is worth it.
Allow the knowledge to percolate. Technology is not going anywhere. Yet your ability to leverage it in 1 to 5 years from now could dramatically reshape your career path. Learning to code is a compound interest move. Dramatic progress is possible with some dedication to learning. It’s the best decision I have made for myself as an engineer and I only wish I did it sooner.
I faced some struggles and plenty of friction as I made my way through the necessary learning material in a manner that was actually useful for me as an engineer. That’s the reason I started Flocode. There’s a better way.
Flocode makes the entire process more manageable, coherent and streamlined in a manner that is specifically tailored to professional engineers.
If you enjoyed this post, come and see what’s up at flocode.dev. We are building big things and if you made it this far, you’ll probably like what we’re up to. The waitlist is now open.
If you have thoughts, concerns, questions or ideas you want to discuss then drop a comment! Are you using Python already, if so what for?
See you in the next post!
James 🌊