Skip to content

Instantly share code, notes, and snippets.

chmod a+x ~
apt update
apt install build-essential autoconf automake libtool postgresql-server-dev-all libxml2-dev libgeos-dev libproj-dev libxml2-utils xsltproc bison postgresql-10
service postgresql start
su postgres -c 'createuser root'
su postgres -c 'psql -d postgres -c "alter user root superuser;"'
git clone git@github.com:postgis/postgis.git
cd postgis
./autogen.sh
./configure --without-raster
@jnhansen
jnhansen / xr_auto_merge.py
Created August 3, 2018 18:59
Auto-merge xarray datasets along multiple dimensions
import glob
import xarray as xr
import itertools
import numpy as np
def auto_merge(datasets):
"""
Automatically merge a split xarray Dataset. This is designed to behave like
`xarray.open_mfdataset`, except it supports concatenation along multiple
@rsignell-usgs
rsignell-usgs / fvcom_forecast_ugrid_ncml.xml
Created June 9, 2018 11:41
NcML to make FVCOM UGRID-1.0 compliant
<dataset name="NECOFS GOM3 Forecast" ID="gom3_nocache"
urlPath="FVCOM/NECOFS/Forecasts/NECOFS_GOM3_FORECAST.nc" dataType="Grid">
<serviceName>allServices</serviceName>
<access serviceName="wms" urlPath="" />
<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2"
location="/http/www/CODFISH/Data/FVCOM/NECOFS/Forecasts/NECOFS_GOM3_FORECAST.nc">
name="cdm_data_type" value="any"/>
<attribute name="Conventions" value="CF-1.0, UGRID-1.0"/>
<attribute name="title" value="NECOFS GOM3 (FVCOM) - Northeast US - Latest Forecast"/>
<attribute name="summary" value="Latest forecast from the FVCOM Northeast Coastal Ocean Forecast System using an newer, higher-resolution GOM3 mesh (GOM2 was the preceding mesh)"/>
@codeinthehole
codeinthehole / client.py
Last active July 27, 2023 07:40
Sample Python client for working with the Octopus Energy REST API
# Requires the requests library (install with 'pip install requests')
import requests
class APIClient(object):
BASE_URL = "https://api.octopus.energy/v1"
class DataUnavailable(Exception):
"""
Catch-all exception indicating we can't get data back from the API
@pyRobShrk
pyRobShrk / invdisttree.py
Created February 10, 2018 18:31
Inverse Distance & K-D Tree Interpolation
""" invdisttree.py: inverse-distance-weighted interpolation using KDTree
fast, solid, local
https://stackoverflow.com/a/3119544
"""
from __future__ import division
import numpy as np
from scipy.spatial import cKDTree as KDTree
# http://docs.scipy.org/doc/scipy/reference/spatial.html
__date__ = "2010-11-09 Nov" # weights, doc
import xarray as xr
import numpy as np
import operator
airtemps = xr.tutorial.load_dataset('air_temperature')
airtemps = airtemps.sel(time=slice('2013-01-01', '2013-12-31'))
airtemps['air'] = airtemps.air - 273.15
air_day = airtemps.resample('1D', 'time', how='mean')
meets_condition = (air_day.air > 22) & (air_day.air < 30)
@mhweber
mhweber / explode.py
Created July 25, 2016 17:45 — forked from debboutr/explode.py
Explode MultiPolygon geometry into individual Polygon geometries in a shapefile using GeoPandas and Shapely
import geopands as gpd
from shapely.geometry.polygon import Polygon
from shapely.geometry.multipolygon import MultiPolygon
def explode(indata):
indf = gpd.GeoDataFrame.from_file(indata)
outdf = gpd.GeoDataFrame(columns=indf.columns)
for idx, row in indf.iterrows():
if type(row.geometry) == Polygon:
outdf = outdf.append(row,ignore_index=True)
@lfigueira
lfigueira / bng_to_latlon.py
Last active March 24, 2021 11:14
Python script to convert British National grid coordinates (OSGB36 Eastings, Northings) to WGS84 latitude and longitude. The code from this script was copied/adapted from Hannah Fry's blog; the original code and post can be found here: http://www.hannahfry.co.uk/blog/2012/02/01/converting-british-national-grid-to-latitude-and-longitude-ii, toghe…
#
# Converts eastings and northings (British national grid coordinates) to Lat/Long
#
# Original code author: Hannah Fry; see code/comments here:
# http://www.hannahfry.co.uk/blog/2012/02/01/converting-british-national-grid-to-latitude-and-longitude-ii
#
from math import sqrt, pi, sin, cos, tan, atan2 as arctan2
import csv
from datetime import datetime, timedelta
def datetime2matlabdn(dt):
ord = dt.toordinal()
mdn = dt + timedelta(days = 366)
frac = (dt-datetime(dt.year,dt.month,dt.day,0,0,0)).seconds / (24.0 * 60.0 * 60.0)
return mdn.toordinal() + frac
@sixtenbe
sixtenbe / analytic_wfm.py
Last active May 27, 2024 01:24 — forked from endolith/peakdet.m
Peak detection in Python
#!/usr/bin/python2
# Copyright (C) 2016 Sixten Bergman
# License WTFPL
#
# This program is free software. It comes without any warranty, to the extent
# permitted by applicable law.
# You can redistribute it and/or modify it under the terms of the Do What The
# Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See