Skip to content

Instantly share code, notes, and snippets.

View grovduck's full-sized avatar

Matt Gregory grovduck

  • Oregon State University
  • Corvallis, OR
View GitHub Profile
"""AoC 8, 2021"""
# Standard library imports
import pathlib
import sys
from itertools import permutations
def parse(puzzle_input):
"""Parse input"""

Overview

This is an attempt to create a simple script for downloading new GNN data for the NWFP visualization group through Google Earth Engine. This code will only work for members of the nwfp-vis or nwfp25-users groups as we don't intend to make the GNN neighbor rasters available outside these groups.

Note that our standard GNN download tool will actually NOT use GEE given the complexities of managing exports from GEE to Google Drive and the possible demands put on specific user accounts when multiple downloads are requested. But this is a way that folks from NWFP-25 working groups can access the data in a somewhat easy API (although this may be a bit too little, too late ...)

Note that this "API" will likely change in the future, although I will try to minimize these changes. Please let me know if you come across any configurations that are not working and provide the configuration object that you used when you triggered the bug. I have not tested many of the different combinations.

A

class FeatureSpace(object):
def __init__(self, max_k):
self.max_k = max_k
self.knn_classifier = KNeighborsClassifier(max_k)
def train(self):
raise NotImplementedError
def transform(self, raw_scores):
raise NotImplementedError
@grovduck
grovduck / dynamic-earthquakes.html
Last active November 15, 2017 21:14
[Mapbox GL JS animated earthquakes] Code for generating animated earthquakes using GeoJSON data and Mapbox GL JS. Need a simple webserver to run, e.g. 'python -m SimpleHTTPServer 8000' #mapbox #web_mapping
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title></title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.37.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.37.0/mapbox-gl.css' rel='stylesheet' />
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700' rel='stylesheet'>
<style>
@grovduck
grovduck / get_ravioli_windows.py
Last active November 15, 2017 21:32
[Expand rasterio windows] Get rasterio windows that expand the shape of raster blocks #rasterio
import sys
import click
import rasterio
def expand(window, size=1):
r, c = window
return ((r[0] - size, r[1] + size), (c[0] - size, c[1] + size))
@grovduck
grovduck / get_rasterio_window_chunks.py
Last active November 15, 2017 21:32
[Rasterio chunks based on RAM] Script to return window address based on user-defined allowable RAM usage. This allows the user to do fewer reads on rasterio data. #rasterio #numpy
"""
This script returns window addresses based on user-defined maximum RAM
usage. It is similar to rasterio.block_windows but allows the user to
potentially do fewer reads on rasterio data.
"""
import rasterio
import numpy as np
@grovduck
grovduck / extract_masked_window.py
Last active November 15, 2017 21:32
[Masked window from numpy array] #numpy #algorithms
import numpy.ma as ma
def extract_masked_window(arr, mask, offset=(0, 0)):
"""
Extract the (possibly) masked window from a numpy array
Parameters
----------
arr : array-like
@grovduck
grovduck / generate_random_points.py
Last active November 15, 2017 21:32
[Bounded random points] Generate random points using a rasterio dataset as boundary #rasterio #numpy #algorithms
def generate_random_points(r, num_points):
"""
Generate random points with replacement using a raster as a bound. Points
will be the centers of pixels in the raster
Parameters
----------
r: rasterio.RasterReader
The raster to use as the bounding area
num_points: int
@grovduck
grovduck / gee-filter.js
Last active November 15, 2017 21:30
[Google Earth Engine snippets] #google_earth_engine
// Examples of using filters with collections
// See https://groups.google.com/forum/#!topic/google-earth-engine-developers/J50mCM-LEMk
// for context
// Set up two constant images with 'a', 'b' and 'c' properties
var im1 = ee.Image.constant(0).set({
a: [1,2,3], b: 4, c: 4
});
var im2 = ee.Image.constant(0).set({
a: [4,5,6], b: 4, c: 5
@grovduck
grovduck / _base.pxd
Last active November 15, 2017 21:31
[RAT support for rasterio (WIP)] Add raster attribute support to rasterio. The property raster_attributes is added to the DatasetReader object and the RAT is returned as an array of dictionaries, where each dictionary has a row's worth of field names/field values. One array is returned for each band in the dataset #rasterio #rat
# Add in _raster_attributes object
cdef class DatasetReader:
cdef public object _crs_wkt
cdef public object _transform
cdef public object _block_shapes
cdef public object _raster_attributes