Skip to content

Instantly share code, notes, and snippets.

View jhamman's full-sized avatar
🔨
Building Earthmover!

Joe Hamman jhamman

🔨
Building Earthmover!
View GitHub Profile
@jhamman
jhamman / apply_along_axis.ipynb
Created October 17, 2019 21:52
apply_along_axis (not working)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jhamman
jhamman / map_blocks_dataset_schema.ipynb
Last active February 24, 2020 23:43
Xarray map_blocks examples
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jhamman
jhamman / conway.py
Last active February 27, 2020 21:36
streaming-zarr-blog
store = zarr.RedisStore(port=args.port)
root = zarr.group(store=store, overwrite=True)
t = 0
while True:
arr = root.zeros(f"{t}", shape=grid.shape, chunks=(25, 25)) # create a new array for this timestep
arr[…] = grid # write data to zarr array
t += 1 # increment the time counter
time.sleep(update_interval)
grid = update(grid, N) # evolve the model one time step
In [1]: import intake
In [2]: catalog = intake.open_stac_catalog(
...: 'https://storage.googleapis.com/pdd-stac/disasters/catalog.json',
...: name='planet-disaster-data')
...:
In [3]: list(catalog)
Out[3]:
['20170831_172754_101c',
'2017831_195552_SS02',
'20170831_195425_SS02',
In [4]: tif = cat['Houston-East-20170831-103f-100d-0f4f-RGB']['thumbnail']
In [5]: tiff_da = tif.to_dask()
Out[5]:
<xarray.DataArray (y: 552, x: 549, channel: 3)>
dask.array<xarray-<this-array>, shape=(552, 549, 3), dtype=uint8, chunksize=(552, 549, 3), chunktype=numpy.ndarray>
Coordinates:
* y (y) int64 0 1 2 3 4 5 6 7 8 ... 543 544 545 546 547 548 549 550 551
* x (x) int64 0 1 2 3 4 5 6 7 8 ... 540 541 542 543 544 545 546 547 548
* channel (channel) int64 0 1 2
In [6]: tiff_da.plot.imshow(rgb='channel')
In [7]: import satsearch
In [8]: results = satsearch.Search.search(
...: collection='landsat-8-l1',
...: bbox=[43.16, -11.32, 43.54, -11.96],
...: sort=['<datetime'], #earliest scene first
...: property=["landsat:tier=T1"])
...:
In [9]: catalog = intake.open_stac_item_collection(results.items())
In [10]: catalog
<satstac.itemcollection.ItemCollection at 0x7f96efe16828>
$ pip install intake-stac
# or
$ conda install -c conda-forge intake-stac
@jhamman
jhamman / dask_k8s.yaml
Created March 30, 2020 18:38
dask_k8s.yaml
# file: dask_config.yaml
kubernetes:
worker-template:
spec:
containers:
- args:
- dask-worker
- --nthreads
- '2'
- --memory-limit
@jhamman
jhamman / dask_k8s.py
Created March 30, 2020 18:39
dask_k8s.py
containers = [
{
"args": [
"dask-worker", "--nthreads", "1",
"--memory-limit", "14GB",
],
"resources": {
"limits": {"cpu": 1, "memory": "14G"},
"requests": {"cpu": 1, "memory": "14G"},
},
@jhamman
jhamman / dask_gateway_1.py
Last active March 30, 2020 18:46
dask_gateway_1.py
options.worker_cores = 1
options.worker_memory = 8
cluster = gateway.new_cluster(cluster_options=options)