Skip to content

Instantly share code, notes, and snippets.

View ryanjdillon's full-sized avatar
👨‍🚀

Ryan J. Dillon ryanjdillon

👨‍🚀
View GitHub Profile
@ryanjdillon
ryanjdillon / get_weather.sh
Created July 7, 2023 11:07
Get grib files for areas around Norway
#!/bin/bash
usage () {
cat <<HELP_USAGE
$0 <area> <outputs-path>
outputs-path: directory weather grib and radar gif should be saved
area: weather area to collect for, try "n-northsea" or "west_norway". For
more options see https://api.met.no/weatherapi/gribfiles/1.1/available
@ryanjdillon
ryanjdillon / pyproject.toml
Last active January 2, 2023 10:49
Pytest Plugin with pyproject.toml and setuptools
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"
[project]
name = "pytest-myplugin"
description = "My pytest plugin"
readme = "README.rst"
requires-python = ">=3.5"
license = {text = "MIT"}
@ryanjdillon
ryanjdillon / s3-rsync.sh
Last active July 2, 2022 12:23
Sync data to S3 with `aws s3 sync`, an AWS `rsync` emulator
# Install the aws cli
source your-venv/bin/activate
pip install awscli
# Setup your credentials
aws configure
# Check out what is going to get transfered first
aws s3 sync ./path/to/data s3://bucket-name --exclude "*" --include "*.nc" --dryrun
@ryanjdillon
ryanjdillon / push_pull.zsh
Created December 13, 2019 08:51
Push (skyv) Pull (trekk) to global directory stack file, but keep only one
# Functions that push and pull to a singleton working directory...a bare-bones pushd/popd.
# For namespace clartiy, Norwegian words were use: skyv (push) and trekk (pull).
# Adapted from here https://stackoverflow.com/a/9916812
directory_stack=$HOME/.directory_singleton
function skyv() {
# Save only one skyv path, overwriting the last
echo $(pwd) > $directory_stack
}
@ryanjdillon
ryanjdillon / load_test_azureml.py
Last active November 4, 2019 07:51
Load test AzureML Workspace handling of MLflow logging calls -- results in rate limit errors
"""
Load test MLFlow logging to AzureML Workspace (as a tracking backend)
Warning: Azure charges apply!
The following environment variables must be set:
* SUBSCRIPTION_ID - The Azure Subscription ID the Workspace is created under
* RESOURCE_GROUP - The Azure ResourceGroup ID the Workspace is created under
* WORKSPACE_NAME - The name of the AzureML Worskpace to log to
"""
@ryanjdillon
ryanjdillon / perc_bc_from_lipid.py
Created September 8, 2017 12:37
Percent body compositions from percent lipids
def perc_bc_from_lipid(perc_lipid, perc_water=None):
'''Calculate body composition component percentages based on % lipid
Calculation of percent protein and percent ash are based on those presented
in Reilly and Fedak (1990).
Args
----
perc_lipid: ndarray
1D array of percent lipid values from which to calculate body composition
@ryanjdillon
ryanjdillon / kartverket_wms.py
Created August 23, 2017 19:30
Working on getting retrieving Kartverket map data
'''
A Package for retrieving Kartverket image data for specified areas.
Exampl URLs
-----------
GetCapabilities:
http://opencache.statkart.no/gatekeeper/gk/gk.open?Version=1.0.0&service=wms&request=getcapabilities
NOAA (not active/testable):
http://porter.pmel.noaa.gov:8922/wms/wms_servlet?VERSION=1.1.1&REQUEST=GetMap&LAYERS=coads_climatology_cdf:airt&STYLES=ferret_default&WIDTH=640&HEIGHT=320&FORMAT=image/png&SRS=EPSG:4326&BBOX=-180.0,-90.0,180.0,90.0&EXCEPTION=application/vnd.ogc.se_xml&DIM_COADS_CLIMATOLOGY_CDF_TIME=15-Jan
@ryanjdillon
ryanjdillon / calc_mod_density.py
Last active July 3, 2017 11:52
Example routine for calculating modified body density of seals
def calc_mod_density(mass_kg, dens_kgm3, n_blocks, block_type):
'''Calculate the modified density with attached blocks
Args
----
mass_kg: float
mass of the seal (kg)
dens_kgm3: float
mass of the seal (kg/m^3)
block_type: str
@ryanjdillon
ryanjdillon / lip2dens.py
Last active June 22, 2017 17:42
Seal lipid to body density calculation
def lip2dens(p_lipid, lipid_dens=0.9007, prot_dens=1.34, water_dens=0.994, a_dens=2.3):
'''Derive tissue density from lipids
Translated to python from R code written by Martin Biuw
'''
p_comps = perc_bc_from_lipid(p_lipid)
p_comps['density'] = (lipid_dens * (0.01 * p_comps['perc_lipid'])) + \
@ryanjdillon
ryanjdillon / algae_light_response.py
Created March 13, 2017 14:51
Algae light response - Calculate the level of oxygen at a give light level
import seaborn
def light_response(light, EC50, hillslop=2.5):
'''Typical response function for EC50 tests'''
import numpy
# http://www.sigmaplot.co.uk/splot/products/sigmaplot/productuses/prod-uses43.php
# Response to concentration
dose_min = light.min()
dose_max = light.max()