Skip to content

Instantly share code, notes, and snippets.

@brews
brews / launch_e2e_dtr_work.sh
Last active December 23, 2021 20:53
Launch Argo Workflow end-to-end runs for diurnal temperature range (DTR) for various parameter files.
#! /usr/bin/env bash
# 2021-12-21
# B. Malevich <[email protected]>
# Launch Argo Workflow end-to-end runs with various parameter files.
set -e
@brews
brews / make_dtr.py
Last active December 23, 2021 20:32
Downscale CMIP6 (dc6) sandbox scratch script to get tasmin, tasmax parameter files for each GCM and combine to create DTR parameter file.
# Get tasmin, tasmax parameter files for each GCM and combine to create DTR parameter file.
# This is all rough and likely to break. Sorry.
import logging
import pathlib
import dearprudence
import dearprudence.validation
PARAMS_DIR = pathlib.Path("/Users/bmalevich/Projects/downscaleCMIP6/workflows/parameters")
@brews
brews / launch_e2e_tasmax_work.sh
Last active February 11, 2022 01:41
Launch downscale CMIP6 (dc6) Argo Workflow end-to-end tasmax runs with various parameter files.
#! /usr/bin/env bash
# 2021-11-22
# B. Malevich <[email protected]>
# Launch Argo Workflow end-to-end runs with various parameter files.
set -e
@brews
brews / qplad_test_example.py
Last active November 17, 2021 18:47
Idea to quickly test that QPLAD adjustment factors (AF) and quantiles are matched correctly.
"""
Idea to quickly test that QPLAD adjustment factors (AF) and quantiles are matched correctly.
This uses ``dodola`` https://github.com/ClimateImpactLab/dodola/tree/f331623dfaffd3d341d27a3bc36f156646c3620f
"""
import numpy as np
import xarray as xr
from dodola.core import (
@brews
brews / wraparound_lon.py
Last active October 26, 2021 21:15
Example python function to get the 'inverse longitude' from opposite global hemisphere, from -180 to 180.
"""
Example python and numpy function to get the 'inverse longitude' from opposite global hemisphere, from -180 to 180.
"""
import numpy as np
def wraparound_lon(x):
"""Get the 'inverse longitude' from opposite global hemisphere, from -180 to 180.
I'm not sure what the proper term for this is.
@brews
brews / add_cyclic.py
Created October 26, 2021 17:30
xarray-native approach to adding a cyclic pixel (aka wrap-around pixel) to arrays in an xarray.Dataset.
import xarray as xr
def add_cyclic(ds, dim):
"""
Adds wrap-around, appending first value to end of data for named dimension.
Basically an xarray version of ``cartopy.util.add_cyclic_point()``.
"""
return ds.map(
@brews
brews / remove_duplicates.py
Created September 9, 2021 21:49
Demo python script to remove duplicate objects in a JSON file, write output
# Remove duplicate objects in a JSON file.
import json
INPATH = "offending.json"
OUTPATH = "corrected.json"
with open(INPATH, "r") as fl:
@brews
brews / remove_metadata.sh
Created August 10, 2021 05:02
Bash script to remove EXIF metadata from IMG_*.jpg files in directory. Write as 70% quality *_clean.jpg in same directory.
#! /usr/bin/env bash
# Remove EXIF metadata from IMG_*.jpg files in directory.
# Write as 70% *_clean.jpg in same directory.
for f in IMG_*.jpg
do
echo "Processing $f"
echo "Writing ${f%.*}_clean.jpg"
convert "${f}" -quality 70% -strip "${f%.*}_clean.jpg"
@brews
brews / xarray_wrap_around_pixel_demo.py
Last active January 15, 2025 08:49
Demo using cartopy.util.add_cyclic_point with an xarray Dataset to add a cyclic or wrap-around pixel to the `lon` dimension. This can be useful for plotting with `cartopy` or regridding with `xesmf`.
"""
Demo using cartopy.util.add_cyclic_point with an xarray Dataset to
add a cyclic or wrap-around pixel to the `lon` dimension. This can be useful
for plotting with `cartopy` or regridding with `xesmf`.
"""
import xarray as xr
from cartopy.util import add_cyclic_point
@brews
brews / intake-catalog.yaml
Last active May 8, 2021 06:36
demo workflow catalog
# Intake Catalog for the workflow in-progress
plugins:
source: [ module: intake_xarray ]
sources:
cmip6_raw:
description: Catalog of raw CMIP6 GCM data to be cleaned and prepared
metadata:
title: Raw CMIP6 GCM data
parameters:
source_id: