Skip to content

Instantly share code, notes, and snippets.

@emlys
emlys / wrap.py
Created April 5, 2021 22:50
Script to wrap multi-line text blocks in source code dictionary
"""
Script to wrap multi-line text blocks in dictionaries.
Made this for InVEST model ARGS_SPECs "about" properties since I'm
moving things around and it's tedious to wrap them all by hand.
This could be generalized to any multi-line text block or an entire file.
"""
import ast
import importlib
import textwrap
@emlys
emlys / generate_users_guide.py
Last active March 29, 2021 16:52
tracer code to generate user's guide content from spec
from natcap.invest import carbon
def format_spec(name, spec):
"""Format an arg spec or subsection of an arg spec into text.
Works for the entire args spec, or any nested dictionary within it (individual args or parts of args).
This way, the generated content can be combined into the existing user's guide
at whatever level makes sense for each situation.

Nested ARGS_SPEC data types examples and specification

Real model examples

leaving out all other arg properties besides "type" to save space

Coastal Blue Carbon selected args

"landcover_snapshot_csv": {
    "type": "csv",
    "structure": {
        "columns": {
@emlys
emlys / queue_bug.py
Created November 18, 2020 21:04
Minimal example for datetime64 queue pickling behavior
import numpy
import multiprocessing
array_in = numpy.empty(1, dtype='datetime64,f4')
print(array_in.dtype['f0'].metadata) # prints None
# if you use queue.Queue instead, this doesn't happen
q = multiprocessing.Queue()
q.put(array_in)
@emlys
emlys / ec2Setup.sh
Last active September 18, 2019 17:15
#!/bin/bash
# Setup for a new EC2 instance for testing Dockstore
# Install Dockstore (from https://staging.dockstore.org/quick-start)---------------------------------------------------------
# Install Java 11:
sudo apt-get update
sudo apt install -y openjdk-11-jdk
#Install the dockstore command-line program and add it to the path.