Skip to content

Instantly share code, notes, and snippets.

View banesullivan's full-sized avatar
🛠️
I may be slow to respond.

Bane Sullivan banesullivan

🛠️
I may be slow to respond.
View GitHub Profile
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Proxy Intercept Fetch Example</title>
</head>
<body>
<h1>Proxy Intercept Fetch Example</h1>
<button id="make-fetch">Make Fetch Call</button>
@banesullivan
banesullivan / data_clean.nc
Last active September 27, 2024 02:33
Is deep copy working for xarray DataSet?
@banesullivan
banesullivan / rio-roi.py
Last active June 14, 2023 03:33
How to extract a region of interest (ROI) from a raster with rasterio. This will maintain the original projection of the source data. Data are converted to Cloud Optimezed GeoTIFF (COG) format via rio_cogeo
import rasterio
from rasterio.mask import mask
import rio_cogeo
from shapely.geometry import box
def region(src, output_path, geom, geom_crs):
region_geom = rasterio.warp.transform_geom(geom_crs, src.crs, geom)
# Read the raster data within the region
@banesullivan
banesullivan / callablevalue.py
Created June 7, 2022 19:46
CallableValue: transition a method to a `property` and preserve backward compatibility
import warnings
def CallableValue(value):
typ = type(value)
if typ is bool:
# For bools, we must subclass int
# https://stackoverflow.com/questions/2172189/why-i-cant-extend-bool-in-python
_typ = int
@banesullivan
banesullivan / dem.xml
Created May 9, 2022 17:01
orthorectify a geospatial raster
<GDAL_WMS>
<service name="TMS">
<ServerUrl>https://s3.amazonaws.com/elevation-tiles-prod/geotiff/${z}/${x}/${y}.tif</ServerUrl>
</service>
<DataWindow>
<UpperLeftX>-20037508.34</UpperLeftX>
<UpperLeftY>20037508.34</UpperLeftY>
<LowerRightX>20037508.34</LowerRightX>
<LowerRightY>-20037508.34</LowerRightY>
<TileLevel>14</TileLevel>
@banesullivan
banesullivan / 3D Tiles Bounds.ipynb
Created February 17, 2022 06:44
Extract EPSG:4326 bounding boxes from 3D Tiles dataset and plot with ipyleaflet
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@banesullivan
banesullivan / cesium-viewer-no-token.html
Last active February 23, 2025 16:50
Create a Cesium Viewer without Cesium Ion Token and still have a decent selection base maps. For some reason, I could not find a clear explanation of how to do this in the Cesium docs or Discourse.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!-- Include the CesiumJS JavaScript and CSS files -->
<script src="https://cesium.com/downloads/cesiumjs/releases/1.87.1/Build/Cesium/Cesium.js"></script>
<link href="https://cesium.com/downloads/cesiumjs/releases/1.87.1/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
</head>
@banesullivan
banesullivan / unyt-demo.py
Created October 27, 2019 01:20
[Using unyt] Use unyt to keep track of physical units when doinng math. In the snippet, I define data in units of centimeters, then peerform math with units of meters and then I can get my final result in the correct units with like no thought!
import unyt as u
import numpy as np
# The following data were collected at a snow station
station = np.array([1,2,3,4,5])
# Collected data
depth = np.array([92,94,105,93,96]) * u.cm
water_eq = np.array([29,30,33,29,32]) * u.cm
temp = np.array([-6, -5, -6, -6, -6]) * u.celcius
@banesullivan
banesullivan / group-by.py
Last active September 13, 2019 06:04
[Pandas Group By] Example of how I like to use the Pandas group by method. It is particularly helpful when dealing with CSV files of well logs for many different wells where a name/id is available. #pandas
import pandas as pd
# Load pandas data frame
df = pd.read_csv('z-group-by-data.csv')
# Split every well into its own dataframe
# Assumes we have many wells in the same table
# and we want to have a table for each of those
# wells individually.
well_dfs = dict(tuple(df.groupby('well_id')))
@banesullivan
banesullivan / distances.py
Last active September 13, 2019 05:45
[Compute Distances] Compute the element-wise distances between two arrays of points in 3D space. This rather simple but a snippet I find myself using all the time. #numpy
import numpy as np
# The function for computing distances
compute = lambda a, b: np.sqrt(np.sum((b - a)**2, axis=1))