Skip to content

Instantly share code, notes, and snippets.

View guidorice's full-sized avatar

Alex G Rice guidorice

View GitHub Profile
@guidorice
guidorice / graphql-upload-example.sh
Created February 5, 2023 11:03
graphql-upload-example
# curl -v http://dev.mlhub.earth:8080/gql \
curl -v http://dev.mlhub.earth:3000/api/gql \
-F operations='{ "query": "mutation ($file: Upload!) { upload_dataset_ingest_file( input: { dataset_id: \"guidorice_dataset1\", ingest_filetype: pdf }, blob: $file) { error size message } } ", "variables": { "file": null } }' \
-F map='{ "0": ["variables.file"] }' \
-F 0=@test.pdf
@guidorice
guidorice / gdalinfo_with_cog_ex.txt
Last active January 6, 2023 19:29
COG GDAL vsis3 driver example
$ gdalinfo /vsis3/sentinel-cogs/sentinel-s2-l2a-cogs/46/C/DB/2022/10/S2B_46CDB_20221003_0_L2A/B02.tif
Driver: GTiff/GeoTIFF
Files: /vsis3/sentinel-cogs/sentinel-s2-l2a-cogs/46/C/DB/2022/10/S2B_46CDB_20221003_0_L2A/B02.tif
Size is 10980, 10980
Coordinate System is:
PROJCRS["WGS 84 / UTM zone 46S",
...
@guidorice
guidorice / prepare_chips.py
Last active December 15, 2022 18:19
model_ecaas_agrifieldnet_silver / prepare dirs named by chip id.
"""
Preprocess chips and fields dirs for model_ecaas_agrifieldnet_silver.
"""
from pathlib import Path
import shutil
dataset_src = Path.home() / 'data/ref_agrifieldnet_competition_v1'
fields_src = dataset_src / 'ref_agrifieldnet_competition_v1_labels_test'
images_src = dataset_src / 'ref_agrifieldnet_competition_v1_source'
@guidorice
guidorice / installs.sh
Created December 1, 2022 23:42
install R on ubuntu
apt-get install -y --no-install-recommends gdebi-core
export R_VERSION=4.2.2
curl -O https://cdn.rstudio.com/r/ubuntu-1804/pkgs/r-${R_VERSION}_1_amd64.deb
gdebi --non-interactive r-${R_VERSION}_1_amd64.deb
export PATH=${PATH}:/opt/R/${R_VERSION}/bin
R -e "install.packages(c('devtools', 'plyr', 'tidyverse', 'raster', 'celestial', 'caret', 'fastICA', 'SOAR', 'RStoolbox', 'jsonlite', 'data.table', 'spdep'), repos='http://cran.us.r-project.org')"
R -e "devtools::install_github('OpenDroneMap/FIELDimageR')"
rm r-${R_VERSION}_1_amd64.deb
@guidorice
guidorice / validate_jsonschema.py
Last active November 29, 2022 22:09
umm-s, umm-c: python simple jsonschema usage
"""
umm-s can be validated in the default usage of jsonschema:
"""
import json
from pathlib import Path
from jsonschema import validate
schema_src = Path.home() / 'repos/nasa/unified-metadata-model/service/v1.5.0/umm-s-json-schema.json'
@guidorice
guidorice / convert_to_gpkg.sh
Created October 14, 2021 17:23
convert directory of geojson to geopackage database
#!/usr/bin/env bash
#
# adds directory of geojson to geopackage database
#
set -e
for file in task_aois/*.geojson; do
echo adding $file;
ogr2ogr -f GPKG task_aois.gpkg -append $file;
@guidorice
guidorice / lc_colormap.py
Created July 16, 2020 21:06
use rasterio to apply colormap on tif
"""
freely copied from @vincentsarago
"""
import rasterio
# http://due.esrin.esa.int/files/GLOBCOVER2009_Validation_Report_2.2.pdf
cmap = {
0: (0, 0, 0, 0), # Nodata
11: (192, 240, 239, 255), # Post-flooding or irrigated croplands
14: (255, 255, 112, 255), # Rainfed croplands
@guidorice
guidorice / loadtest.py
Created July 16, 2020 15:46
loadtest.py for titiler cogs
"""
from @vincentsarago
"""
import random
import sys
import numpy
import requests
import mercantile
from concurrent import futures
import click