Skip to content

Instantly share code, notes, and snippets.

@soiqualang
Forked from shaystrong/Readme.md
Created March 26, 2020 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soiqualang/18f05130a9398286343c0e72a8c619ce to your computer and use it in GitHub Desktop.
Save soiqualang/18f05130a9398286343c0e72a8c619ce to your computer and use it in GitHub Desktop.
SWIR DG processing
  1. Image download from ftp --> upload to AWS s3 bucket

  2. Pull to AWS EC2 machine. Save off SWIR band ratios as tif with appropriate contrast. The SWIR data is an 8-band image. You need to first grab onnly the bands you need for visualization (8-3-1 or 6-3-1 make good combos)

import rasterio
import numpy as np

raster='18NOV09185526-A2AS-058669488010_01_P001.TIF'.  #your file
outfile='swir_831.tif'

with rasterio.open(raster) as raster:
    img1 = raster.read()
    out_meta = raster.meta.copy()

ii=np.dstack((img1[7],img1[2],img1[0]))   #(bands 8-3-1)
out_meta.update({"driver": "GTiff","count":3}).   #change from 8 band count to 3 band
im = ii.transpose(1, 2, 0)
im = im.transpose(1, 2, 0)

with rasterio.open(outfile, "w", **out_meta) as dest:
    dest.write(im)
    
  1. You may have to adjust the scale. Technically you cann do something like this: gdal_translate swir_831.tif swir_831_scaled.tif -scale 0 4670 0 4670 -exponent 0.5 -co COMPRESS=DEFLATE -co PHOTOMETRIC=RGB I was still having signfiicant contrast problems once I converted to an mbtiles. So At this point, I actually pulled the image locally to QGIS and saved as a 'rendered' tif

  2. translate scaled tif to mbtiles: gdal_translate swir_831_rendered.tif -of mbtiles swir_831_rendered.mbtiles

  3. add overviews to the mbtiles: gdaladdo -r average swir_831_rendered.mbtiles 2 4 8 16 32 64 This imagery is 3.7-m/pixel native resolution. Your TMS overviews will be zoom 9-15

  4. unpack the mbtiles to create pyramid folders: mb-util swir_831_rendered.mbtiles swir_831_rendered/

  5. upload the unpacked mbtiles to the storm-ai-layers s3 bucket: aws s3 cp swir_831_rendered/ s3://storm-ai-layers/swir_831_rendered/ --recursive

  6. you can know stream your image from https://d27y2lu5k335jb.cloudfront.net/swir_831_rendered/{z}/{x}/{y}.png

  7. change the names of the files, etc to be consistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment