Skip to content

Instantly share code, notes, and snippets.

@nikmolnar
nikmolnar / databasin_client_example.py
Created December 2, 2015 01:22
Example of importing a NetCDF dataset with the Data Basin client library.
from databasin.client import Client
c = Client()
c.login('user', 'pass')
# Package must have complete metadata and style necessary for one-step import
dataset = c.import_netcdf_dataset('/path/to/netcdf_with_metadata_and_style.zip')
# One-step imports are private by default
dataset.make_public()
#!C:\Users\nik\Documents\environments\databasin_web\Scripts\python2.7.exe
# EASY-INSTALL-ENTRY-SCRIPT: 'celery==3.1.17','console_scripts','celery'
__requires__ = 'celery==3.1.19'
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.exit(
load_entry_point('celery==3.1.19', 'console_scripts', 'celery')()
)
@nikmolnar
nikmolnar / netcdf_for_databasin.py
Last active October 20, 2015 20:53
This script takes a directory of NetCDF datasets and a single JSON style file and creates one ZIP archive per dataset, ready to upload to Data Basin.
"""
This script takes a directory of NetCDF datasets and a single JSON style file and creates one ZIP archive
per dataset, ready to upload to Data Basin.
"""
import json
import os
import sys
from zipfile import ZipFile, ZIP_DEFLATED
@nikmolnar
nikmolnar / databasin_webhook.php
Last active November 9, 2015 03:26
Example PHP code for handling a webhook callback from Data Basin
<?php
$SECRET_KEY = "<secret key here>";
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
function is_valid($secret, $value, $salt, $signature) {
$verify = base64url_encode(hash_hmac("sha1", $value, sha1($salt . $secret, true), true));
return $signature === $verify;
@nikmolnar
nikmolnar / render_geotiff.py
Last active March 17, 2016 15:56
Simple example of rendering a GeoTIFF using the mapnik RasterSymbolizer
import mapnik
m = mapnik.Map(600, 600)
m.srs = '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'
rs = mapnik.RasterSymbolizer()
# COLORIZER_DISCRETE is a binned/classified rendere. Other options are COLORIZER_LINEAR (stretched) and
# COLORIZER_EXACT (unique)
rs.colorizer = mapnik.RasterColorizer(mapnik.COLORIZER_DISCRETE, mapnik.Color(0, 0, 0, 0))
@nikmolnar
nikmolnar / convert_grid.py
Created June 3, 2015 17:43
This script converts from a simple binary elevation format to ArcASCII.
"""
This script converts from a simple binary elevation format to ArcASCII. The format of the binary file is:
Offset Type Description
-----------------------------
0 uint Grid width
4 uint Grid height
8 float* Elevation values as floats in row-major order from lower-left to upper-right.
"""
from openpyxl import Workbook
import os
COLUMNS = [
'Name', 'Data Lead', 'Description', 'Date Obtained', 'Time Period of Content Date', 'Publication Date',
'URL', 'Contact', 'Processing Notes', 'Keywords', 'Relative Path', 'Absolute Path'
]
def parse_readme(f):