Skip to content

Instantly share code, notes, and snippets.

View jklymak's full-sized avatar

Jody Klymak jklymak

View GitHub Profile
@jklymak
jklymak / writeemails.py
Created May 28, 2024 16:38
Write to request references from yaml list of referees
import smtplib
import yaml
from email.message import EmailMessage
from email.utils import make_msgid
from email.mime.base import MIMEBase
from email import encoders
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
@jklymak
jklymak / LinePPlan.py
Created January 28, 2024 00:25
LinePPlan
import numpy as np
import matplotlib.pyplot as plt
import seawater
%matplotlib widget
import pooch
import xarray as xr
import pandas
"""
eg
import xarray as xr
# https://oceandata.sci.gsfc.nasa.gov/ob/getfile/AQUA_MODIS.20230606T215500.L2.SST.NRT.nc
with xr.open_dataset('/Users/jklymak/Downloads/AQUA_MODIS.20230606T215500.L2.OC.NRT.nc',group='geophysical_data') as ds, xr.open_dataset('/Users/jklymak/Downloads/AQUA_MODIS.20230606T215500.L2.OC.NRT.nc',group='navigation_data') as nav:
print(nav)
ds['lon'] = (('number_of_lines', 'pixels_per_line'), nav['longitude'].values)
ds['lat'] = (('number_of_lines', 'pixels_per_line'), nav['latitude'].values)
for j in range(0, 2030):
if np.any(~np.isfinite(ds.lat[j, :])):
print(j)
# output from the MITgcm using xmitgcm
import xarray as xr
import numpy as np
import xgcm
with xr.open_dataset(fname, decode_times=False) as ds:
grid = xgcm.Grid(ds, coords={'Z':{'center':'Z', 'outer':'Zp1'}}, periodic=False)
ds = preprocess(ds)
@jklymak
jklymak / runMonitor.sh
Created June 15, 2022 08:04
Monitor script for cedar
#!/bin/bash
#SBATCH --account=def-jklymak
#SBATCH [email protected]
#SBATCH --mail-type=ALL
#SBATCH --ntasks-per-node=1
#SBATCH --time=0-00:15
#SBATCH --mem=64G
cd ${SLURM_SUBMIT_DIR}
@jklymak
jklymak / Chaining Runs.md
Created September 24, 2021 12:07
Chaining MITgcm model runs
#!/bin/bash -l
for todo in OneHill100lowU10N10Amp305f141B059Rough
do
    day=86400
    jobid=$(sbatch -J $todo --export=start=0,stop=$((day*6 + 180)),dt=90 runModel.sh)
    #echo $jobid
    jobid1=$(sbatch  -J $todo  --dependency=afterok:${jobid##* } --export=start=$((day*6)),stop=$((day*12 + 180)),dt=90 runModel.sh)
    jobid2=$(sbatch  -J $todo --dependency=afterok:${jobid1##* } --export=start=$((day*12)),stop=$((day*18 + 180)),dt=90 runModel.sh)
    jobid3=$(sbatch  -J $todo --dependency=afterok:${jobid2##* } --export=start=$((day*18)),stop=$((day*24 + 180)),dt=90 runModel.sh)

#MITgcm checkin runs

Sometimes we want to store versions of config files for a model run. This uses runname to make a new branch, and to make a commit on the main branch. You need to set the model config up to be tracked, of course.

_log.info('doing this via git!!')
@jklymak
jklymak / getstatus_slurm.py
Created March 12, 2021 23:25
getting status from MITGCM on slurm
import sys
import os
import subprocess
os.system('sq')
out=subprocess.check_output('squeue -h -t RUNNING -u jklymak --Format="Name:50"',
shell=True, text=True)
out = out.splitlines()
# print(out)
for dd in out:

Chaining multiple MITgcm jobs

These were done for AbHillInter, on the machine koehr.

runAll.sh

#!/bin/sh -l
todo=Iso1kmlowU10Amp305f141B059Wall

one=$(qsub -N $todo -v "start=0, stop=259300, dt=50" runModelRestarts.sh)
two=$(qsub -N $todo -v "start=259200, stop=518500, dt=50"  -W depend=afterok:$one runModelRestarts.sh)
@jklymak
jklymak / distance_along_line.py
Last active March 30, 2022 13:19
Distance along a line
"""
Use https://github.com/jklymak/waypoint_distance instead!
"""
def get_xy(ds, lat0, lon0):
x = (ds.longitude - lon0) * np.cos(np.deg2rad(lat0)) * 60 * 1.852
y = (ds.latitude - lat0) * 60 * 1.852
ds['x'] = x
ds.x.attrs['units'] = f'km east of {lon0}'
ds['y'] = y