Skip to content
This repository was archived by the owner on Jul 25, 2023. It is now read-only.

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

readme.md

title description author keywords math
Day 4
Day 4
Qusai Al Shidi
space-weather,space,python
mathjax

What is this git thing? 🤔


Review

  • 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.

Let's go through the commands


git pull

  • 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)

git push

  • by itself, push commits from your computer to remote repository 'origin' (GitHub)
  • git push <remote> <branch> pushes the branch to remote repository

git commit -m 'A message'

  • 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

git add <file/folder>

  • 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.

git merge

  • merge two branches together,
           A---B---C topic                                          
          /                                                         
     D---E---F---G master                                           
  • if on master, git merge topic will combine topic unto master

rebase ???

  • 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                                           

remember --help 😊

git --help


Let's look at the changes you've made so far

git log

  • commit history with messages

git show

  • show the changes of the last commit
  • git show HEAD~2 will show changes since last 2 commits.
  • HEAD is the current commit

.gitignore

  • Ask git to ignore certain files.
  • This might be hidden ls -a to list all files
spyder .gitignore
# maybe on windows:
Notepad .gitignore

refer to your git cheat sheets 📃 for other things!


one more python tip!

  • zip() 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)

how is this useful? 🤔


a great example

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())

pcolormesh

  • It's like a plt.contourf plot but with needing to make a np.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()

NetCDF


  • 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 h5py or the HDF5 format

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
  • .nc is a NetCDF file

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 argparse make your python script take a single file name and output a .png with 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 frames with your data both should be outside your git repo directory.

  • Let's install ffmpeg
conda install ffmpeg

cat *.png | ffmpeg -framerate 1/2 -f image2pipe -i - -c:v libx264 -pix_fmt yuv420p out.mp4
  • Hopefully this works 😰