I'm super excited for this new semester. This video covers class logistics. Here is the link to the discord server: https://discord.gg/5e86BmQ7 Here is the link to the course files on github: https://github.com/sp8rks/MSE2001python Here is the link to the YouTube playlist for the course: https://www.youtube.com/playlist?list=PLL0SWcFqypCmkHClksnGlab3wglEVMqNN
Python is a fantastic coding language to learn if you are an engineering student! It's free, widely used, has lots of support, and offers many packages and libraries that will help you do the things you want like scientific computing, data analysis, visualization and more. A drawback to python is that it's an interpreted language as opposed to a compiled language so it will run slower than things like C++ or javascript. We should start by downloading python via the Anaconda3 distribution. This will give us things like Spyder, Jupyter notebooks, and more. In Spyder we can see where we code, our console (the output of the code) and our variable explorer window where we can see the values of our variables in real-time.
I'm a big fan of Spyder as my python IDE. However, some folks like to use Jupyter notebooks or the powerful and free Google Colab. This video shows how to use these alternatives and talks about pros and cons of each like free GPUs vs a built-in variable explorer
Semantics and syntax are essentially the grammar rules that a programming language uses to make sure that information is communicated without misinterpretation. In coding, this is things like spelling, spacing, semicolons, brackets etc. This video covers a few of the key differences in python and introduces a few other programming basics.
There are different data types including numeric, string, sequential, mapping, boolean, set, and binary. For these different types we have different variables including integer, float, complex, string, list, tuple, set, dictionary, boolean, byte, bytearray, and memoryview. Variables can be named with flexibility. Preference is given for short, descriptive names and this video explains when we use camelCase, CapCase, and snake case along with general rules for naming variables, functions, modules, and constants.
Strings are ways that we can store text in variables in python. We cover how to use strings, how to access characters within strings, slicing, useful functions like len() and str() as well as useful methods like .upper(), .replace(), split() and more.
Boolean variables can be either True or False. These variables are very important in programming because we often have tasks or decisions to make which depend on whether different logical conditions are met. We need a way to define a True or False outcome. In this video we describe these variables and we also mention a brief word about the namesake of Boolean variables, George Boole. Copyright image attribution: https://en.wikipedia.org/wiki/George_Boole#/media/File:George_Boole_color.jpg, unkown author http://schools.keldysh.ru/sch444/museum/1_17-19.htm
Lists are a really useful and versatile variable type. We can store more than a single value in a list. Lists can store more than one type of variable at a time. The order is changeable and we can add or remove items with ease. There are many useful methods to help us work with lists like .append(), .remove(), .pop(), .sort() and many more. When interacting with lists we need to learn how to slice. This means we need to learn python indexing which starts at 0 and can also work in reverse from the back. The slice start index is included in the slide but the stop index is not included. Copyright image attribution: https://en.wikipedia.org/wiki/The_Lord_of_the_Rings:_The_Fellowship_of_the_Ring#/media/File:Fellowship.JPG
Tuples and Sets are a lot like Lists which we learned about in our last video. They both store multiple data. However, there are some big differences. Sets cannot have any duplicate values and a set is also unordered (no index). Tuples are like lists that cannot be changed (immutable). These both offer some advantages. We can take advantage of the fact that sets don't allow duplicates to remove duplicates from a list with ease by simply converting a list to a set. Sets also allow us to identify in Venn diagram fashion, the elements in common between sets or the differences, etc using union(), intersection(), difference(), and symmetric_difference() methods. We do an example where we pull the keywords from the internet movie database for Fellowship of the Ring, Harry Potter (Sorcerer's stone), and Star Wars (A New Hope) and see what they have in common etc. Try it yourself with the .csv file available on my github. https://github.com/sp8rks/MSE2001python/blob/main/module_examples/data_for_exercises/fantasy_sets.csv Tuples make assignments simultaneously so we can use these to easily swap variable values. We can also take advantage of packing and unpacking with tuples.
Dictionaries are probably the most popular data storage variable type. They are not ordered and rely instead on a key & value system. You can store a value to a specific key using a dictionary. You can even make a dictionary of dictionaries as we do in this video example.
Operators in python can be Arithmetic, Assignment, Comparison, Logical, Identity, Membership, and Bitwise. In this video we go over the syntax for some of these operations.
We need to make decision based off of logical conditions when coding. If, elif, and else statements along with comparison and other logical operators allow us to make these decisions. In this video we show some examples of complex and nested if statements.
Python functions are super helpful so we don't have to let the same line of code over and over. Instead, we can write the code block once and call it over and over. Functions are flexible and they can accept different numbers of parameters and even varying numbers and types of parameters or parameters with key values or default values. This video gives an example of how we can use these to convert Fahrenheit to Celsius and a custom one using a Lambda function which is essentially a one-line version of a function.
For loops in python are extremely powerful. Rather than index from start to stop with some incremented, it can do much more! It is able to iterate through any iterable object including lists, sets, tuples, dictionaries, and strings. We can also do list comprehension and dictionary comprehension to create sub-lists form a larger list given a logical condition. While loops are also possible in python if you don't know how long the loop will need to continue.
NumPy is arguably the most important library for python. It's built for scientific computing. It allows us to store data in arrays and perform operations and manipulations of those arrays at incredible speeds. Numpy also has many math functions like the trig functions, log, exp, etc. This video explores some of the options NumPy offers and shows a few examples along the way.
Most scientists and engineers are very familiar with Microsoft Excel for managing tabular datasets like comma separated values (.csv). However, excel is very limited in what it can do and does not do well with large datasets either. Instead, engineers should learn to work with the Pandas library in python. Pandas is a powerful tool for managing, sorting, grouping, describing, and all around working with data. Here's a tutorial performed on a dataset of UFO sightings!
Part 2 of 3. Having discussed the hallmarks of a good vs a bad scientific publication (see part 1 https://youtu.be/rUV8VFbUi_U), we are now ready to explain how to use python to make plots. This video covers the basics of different python plots such as x,y plots, semilog plots, bar plots, pie charts, scatter plots, histograms, and more. Basic functions and keywords are described to show how to generate data, control markers, marker color, line style, legends, labels, and more. 00:00 import libraries 00:45 basic x,y plot 3:21 marker, line etc 7:20 plot legend 9:13 semilog plot 9:43 math LaTeX equations 10:56 font size 11:33 bar and pie charts 18:06 scatter plots 21:50 histograms 23:55 error bar plots
This is part 3 in a 3-part series on making beautiful scientific figures in python. In this video, I will cover some advanced scientific plots in python. Check out part 1 and part 2 if you haven't yet. Part 1: https://youtu.be/rUV8VFbUi_U Part 2: https://youtu.be/Y8JWfGjj2okAll the files and scripts for these plots are available on the github https://github.com/sp8rks/MSE2001python/tree/main/module_examples 00:00 Generic advanced plot First, we cover the generic python script for making a nice figure.link: https://github.com/sp8rks/MSE2001python/blob/main/module_examples/figures_generic_single_plot_example.py 6:45 stacked plots with fill between Next, we cover stacked plots with fill_between data setslink: https://github.com/sp8rks/MSE2001python/blob/main/module_examples/figures_cobalt_fill_between_example.py 11:51 multipanel plots Next, we cover multipanel plots link: https://github.com/sp8rks/MSE2001python/blob/main/module_examples/figures_multipanel_plot_example.py 23:29 heatmaps Next, we cover heatmaps using the seaborn library with 2D plots of the end memberslink: https://github.com/sp8rks/MSE2001python/blob/main/module_examples/figures_heatmap_example.py 37:24 multiple axes plots Next, we cover figures with multiple axes link: https://github.com/sp8rks/MSE2001python/blob/main/module_examples/figures_multiple_axes.py 44:32 Rietveld refinement diffraction plots Next, we cover Rietveld refinement diffraction plotslink: https://github.com/sp8rks/MSE2001python/blob/main/module_examples/figures_XRD_Rietveld.py 51:24 3D plots Finally, we cover 3D plots with contour, surface, and scatter plotslink: https://github.com/sp8rks/MSE2001python/blob/main/module_examples/figures_3d.py
Classes are a super helpful data type in python. We can create objects that share similar information types. This video shows an example of classes where we create members of Bravais lattice and store relevant information like crystal system or centering as fields within the class. We can then create various instances of the class for different elements and store their information in a compact, useful way. We can also define custom methods and use a helpful initialization function as well as write help documentation for the class so we remember what the class was later ;) 00:00 what are classes? 3:30 help and initialization 9:08 custom methods 11:38 example of classes to classify Bravias lattices
It's critical to keep track of units in scientific computing. Fortunately, python has a few options for tracking and converting units. Here we show you a unit conversion library and the power pint library. We also introduce scipy constants and the molmass library to calculate elemental molar mass. This video has lots of examples of unit conversion for materials science. 00:00 why care about units? 1:30 unit_converter 3:30 pints library 7:20 combining units 9:15 scipy constants 12:15 molmass library 17:20 custom units 18:55 electrical conductivity




















