| title | description | author | keywords | math |
|---|---|---|---|---|
Day 4 |
Day 4 |
Qusai Al Shidi |
space-weather,space,python |
mathjax |
- Git is a version controlling software for your code.
- You've made changes to your local repository.
- You pushed changes to your fork on GitHub.
- by itself, pull commits from the remote repository 'origin' (GitHub)
git pull <remote> <branch>pulls changes from a similar repository on a different remote (AetherModel GitHub)
- by itself, push commits from your computer to remote repository 'origin' (GitHub)
git push <remote> <branch>pushes the branch to remote repository
- stage changes to be pushed, before this your edits are unstaged.
- commit messages should be useful and typically not more than 50 characters long.
- commit every time you have something in a working state
- track a file for changes. It will still be unstaged until you commit it.
- be careful adding folders, it will add all files in it.
- merge two branches together,
A---B---C topic
/
D---E---F---G master
- if on
master,git merge topicwill combinetopicuntomaster
- a rebase reapply commits onto a new base in your history, this might be necessary if you made commits based off a different point than the remote
A---B---C topic
/
D---E---F---G master
A'--B'--C' topic
/
D---E---F---G master
- commit history with messages
- show the changes of the last commit
git show HEAD~2will show changes since last 2 commits.HEADis the current commit
- Ask git to ignore certain files.
- This might be hidden
ls -ato list all files
spyder .gitignore
# maybe on windows:
Notepad .gitignorezip()generates tuples of its arguments sequentially (think of a zipper 🤐)
names = ['Ahmed', 'Becky', 'Cantor']
ages = [21, 30, 45]
favorite_colors = ['Pink', 'Grey', 'Blue']
print(list(zip(names, ages, favorite_colors)))
for name, age, color in zip(names, ages, favorite_colors):
print(name, age, color)from datetime import datetime
num_of_days = 10
years = [2009]*num_of_days
months = [12]*num_of_days
days = list(range(start=1, stop=11))
times = [datetime(year, month, day)
for year, month, day
in zip(years, months, days)]
for time in times:
print(time.isoformat())- It's like a
plt.contourfplot but with needing to make anp.meshgrid()
import numpy as np
import matplotlib.pyplot as plt
num_of_x = 10
num_of_y = 20
x = np.linspace(0, 1, num_of_x)
y = np.linspace(0, 1, num_of_y)
z = np.random.randn(num_of_y, num_of_x)
plt.pcolormesh(x, y, z)
plt.colorbar()- A lot of space data is in this format
- Let's get its python package
conda install netcdf4
# if that doesn't work
pip install netCDF4
# you might need to do this *only* if the above didn't work:
pip install --user netCDF4- It is similar to
h5pyor theHDF5format
- Let's download ionosphere forecast data from https://www.swpc.noaa.gov/products/wam-ipe
- We want to extract the files
conda install -c conda-forge tar
tar -xvf wfs.*.tar- We want the 2D files
ls *ipe05*.nc *means match this pattern with any string of length.ncis aNetCDFfile
import netCDF4 as nc
dataset = nc.Dataset('filename.nc')
print(dataset)
dataset['tec'][:] # How you get the numpy array of the data
dataset['tec'].units # How you get the units of data- Let's make a
plt.pcolormesh()plot of the Total Electron Content - Create a function like
def plot_tec(dataset, figsize=(12,6)):
fig, ax = plt.figure(figsize=figsize)
ax.pcolormesh()
# other things
return fig, ax- Review each others' code
- Using
argparsemake your python script take a single file name and output a.pngwith the same name. - Hint:
# You can concatenate strings in python with +
outfilename = infilename + '.png'# example
python tec.py wfs.t12z.ipe05.20220719_010000.nc
# challenge allow any number of arguments and save png figures for all- Code review when you are done
- Create a directory
frameswith your data both should be outside your git repo directory.
- Let's install
ffmpeg
conda install ffmpegcat *.png | ffmpeg -framerate 1/2 -f image2pipe -i - -c:v libx264 -pix_fmt yuv420p out.mp4- Hopefully this works 😰