Skip to content

Instantly share code, notes, and snippets.

View patchdynamics's full-sized avatar

House of Salt Marsh patchdynamics

View GitHub Profile
@patchdynamics
patchdynamics / NCDO_PDSI_CT_River.vim
Last active August 27, 2015 21:01
Processing NCDC PDSI data for CT River Macrosystem
# VIM regex commands
# Get ride of anything not from 2010 - 2015
g!/\(.*\)\(201[0-5]\) /d
# Get ride of all areas not relevant to our study area
g!/^0601\|^0602\|^1901\|^1902\|^2701\|^2702\|^4301\|^4302\|^4303/d
# Split region code from year, get ride of variable code
%s/\(.*\)05\(201[0-5]\) /\1 \2/g
+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs
@patchdynamics
patchdynamics / rasterize_ct_river_hrap_above_haddam.sh
Created August 24, 2015 20:04
Rasterize CT River Watershed Haddam to HRAP Coordinate Grid
gdal_rasterize --config GDAL_CACHEMAX 4000 -burn 1 -tr 1.0 1.0 -te 562 -952 602 -853 -co COMPRESS=LZW CT_Watershed_Above_Haddam_HRAP_Projected.shp CT_Watershed_Above_Haddam_HRAP_Projected.tiff
@patchdynamics
patchdynamics / hrap_projection.prj
Last active August 29, 2015 14:27
Reproject and rasterize HRAP precipitation
+proj=stere +lat_0=90 +lat_ts=60 +lon_0=-105 +k=1 +x_0=0 +y_0=0
+a=6371200 +b=6371200 +to_meter=4762.5 +no_defs
["Degree",0.0174532925199433]],PROJECTION["Stereographic_North_Pole"],
PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],
PARAMETER["Central_Meridian",-105.0],PARAMETER["Standard_Parallel_1",
60.0],UNIT["HRAP_Grid",4762.5]]
@patchdynamics
patchdynamics / download_precip.sh
Created August 20, 2015 21:46
Download files using python, in this case precipitation gis files
#!/home/deepwinter/env/bin/python
# using virtual env
# http://wiki.dreamhost.com/Python
import datetime
import time
import wget
import datetime
import tarfile
import os.path
import urlgrabber
@patchdynamics
patchdynamics / crop_highres.sh
Last active August 29, 2015 14:27
Crop high def raster to polygon efficiently
# tried with gdalwarp, but ends up slow with a huge file
gdalwarp -q -cutline /Users/matthewxi/Documents/Projects/NASQAN/clip_columbia_extent_conus.shp -crop_to_cutline -co COMPRESS=LZW -of GTiff /Users/matthewxi/Documents/Projects/NASQAN/nasqan_raster_conus_compressed/b14246900_polygon.shp30.tiff /Users/matthewxi/Documents/Projects/NASQAN/b14246900_nlcd_clipped_3.tif
# gdal_translate seems to be the better option
# using extents to crop
gdal_translate -projwin -2191346 3275471 -1068667 2168385 -co "COMPRESS=LZW" /Users/matthewxi/Documents/Projects/NASQAN/nasqan_raster_conus_compressed/b14246900_polygon.shp30.tiff /Users/matthewxi/Documents/Projects/NASQAN/b14246900_nlcd_clipped_7.tif
@patchdynamics
patchdynamics / NARR NetCDF to GeoTIFF
Last active August 29, 2015 14:26
NARR NetCDF to GeoTIFF
require(ncdf)
require(raster)
file.nc <- 'air.sfc.2009.nc'
## Output: a GeoTIFF file
file.tiff <- paste('air/air.', sprintf('%.4d',day), '.tiff', sep ='')
r.temperature <- raster(file.nc, day)
@patchdynamics
patchdynamics / Batch Convert Shape to Raster
Last active August 29, 2015 14:26
Batch convert shape to raster user GDAL
find *.shp -exec gdal_rasterize -burn 1 -tr 200 200 {} ../nasqan_raster_lambert/{}.tif \;
# improve performance by loading more data into memory at once
find *.shp -exec gdal_rasterize --config GDAL_CACHEMAX 2400 -burn 1 -tr 30 30 -a_srs EPSG:5070 -of HFA {} ../nasqan_raster_conus/{}30.img \;
# compress tiffs using LZW to vasty improve disk performance
find *.shp -exec gdal_rasterize --config GDAL_CACHEMAX 4000 -burn 1 -tr 30 30 -a_srs EPSG:5070 -co COMPRESS=LZW {} ../nasqan_raster_conus/{}30.tiff \;
find *_polygon.shp -exec ogr2ogr -s_srs EPSG:5070 -t_srs EPSG:102009 ../nasqan_polygons_lambert/{} {} \;
@patchdynamics
patchdynamics / GeoTiff to MPEG
Last active December 5, 2016 06:56
Stuff for making a movie out of a sequence of GeoTIFFs
# need to rescale the values
gdal_translate -scale 200 350 0 1 air.59.tif air-rescaled.tif
# or batch it
find *.tif -exec gdal_translate -scale 200 350 0 1 {} {}.rescaled.tif \;
# make into png files
mogrify -format jpg *.rescaled.tif