From 824091535aafcacc4477fe3d967b2807162c005c Mon Sep 17 00:00:00 2001 From: Amanda Tan <amandach@uw.edu> Date: Mon, 7 Feb 2022 13:53:57 -0800 Subject: [PATCH] Added Landsat module for AWS --- aws-landsat/install_packages.sh | 16 +++++++++ aws-landsat/process_sat.py | 59 ++++++++++++++++++++++++++++++++ landsat/.combine.py.swp | Bin 0 -> 12288 bytes 3 files changed, 75 insertions(+) create mode 100755 aws-landsat/install_packages.sh create mode 100755 aws-landsat/process_sat.py create mode 100644 landsat/.combine.py.swp diff --git a/aws-landsat/install_packages.sh b/aws-landsat/install_packages.sh new file mode 100755 index 0000000..43629a7 --- /dev/null +++ b/aws-landsat/install_packages.sh @@ -0,0 +1,16 @@ +#!/bin/bash -i + +wget -q 'https://repo.anaconda.com/miniconda/Miniconda3-py39_4.10.3-Linux-x86_64.sh' +chmod ug+x ./Miniconda3-py39_4.10.3-Linux-x86_64.sh +bash ./Miniconda3-py39_4.10.3-Linux-x86_64.sh -b + +echo 'export PATH="/home/ubuntu/miniconda3/bin:$PATH"' >> ~/.bashrc + +source ~/.bashrc + + +conda create -q -y --name myenv + +conda activate myenv + +conda install -y -c conda-forge rasterio diff --git a/aws-landsat/process_sat.py b/aws-landsat/process_sat.py new file mode 100755 index 0000000..81cb0db --- /dev/null +++ b/aws-landsat/process_sat.py @@ -0,0 +1,59 @@ +#!/usr/bin/python3 +import os +import rasterio + +print('Landsat on AWS:') +filepath = 'http://landsat-pds.s3.amazonaws.com/c1/L8/042/034/LC08_L1TP_042034_20170616_20170629_01_T1/LC08_L1TP_042034_20170616_20170629_01_T1_B4.TIF' +with rasterio.open(filepath) as src: + print(src.profile) + +with rasterio.open(filepath) as src: + oviews = src.overviews(1) # list of overviews from biggest to smallest + oview = oviews[-1] # let's look at the smallest thumbnail + print('Decimation factor= {}'.format(oview)) + # NOTE this is using a 'decimated read' (http://rasterio.readthedocs.io/en/latest/topics/resampling.html) + thumbnail = src.read(1, out_shape=(1, int(src.height // oview), int(src.width // oview))) + +print('array type: ',type(thumbnail)) +print(thumbnail) + +date = '2017-06-16' +url = 'http://landsat-pds.s3.amazonaws.com/c1/L8/042/034/LC08_L1TP_042034_20170616_20170629_01_T1/' +redband = 'LC08_L1TP_042034_20170616_20170629_01_T1_B{}.TIF'.format(4) +nirband = 'LC08_L1TP_042034_20170616_20170629_01_T1_B{}.TIF'.format(5) + +with rasterio.open(url+redband) as src: + profile = src.profile + oviews = src.overviews(1) # list of overviews from biggest to smallest + oview = oviews[1] # Use second-highest resolution overview + print('Decimation factor= {}'.format(oview)) + red = src.read(1, out_shape=(1, int(src.height // oview), int(src.width // oview))) + print(red) + +def calc_ndvi(nir,red): + '''Calculate NDVI from integer arrays''' + nir = nir.astype('f4') + red = red.astype('f4') + ndvi = (nir - red) / (nir + red) + return ndvi + +np.seterr(invalid='ignore') +ndvi = calc_ndvi(nir,red) +print(ndvi) + +localname = 'LC08_L1TP_042034_20170616_20170629_01_T1_NDVI_OVIEW.tif' + +with rasterio.open(url+nirband) as src: + profile = src.profile.copy() + + aff = src.transform + newaff = rasterio.Affine(aff.a * oview, aff.b, aff.c, + aff.d, aff.e * oview, aff.f) + profile.update({ + 'dtype': 'float32', + 'height': ndvi.shape[0], + 'width': ndvi.shape[1], + 'transform': newaff}) + + with rasterio.open(localname, 'w', **profile) as dst: + dst.write_band(1, ndvi) diff --git a/landsat/.combine.py.swp b/landsat/.combine.py.swp new file mode 100644 index 0000000000000000000000000000000000000000..2e0666f0fedf59302ed4c3ff51402a2c7aba8637 GIT binary patch literal 12288 zcmeI&u}<4S7zgkVmQGOA?&wGrDFg8VSy-r43P^||5R|fkE{UsJ!oHL5EXV>AJ2R~G z5!z0LC#Wj%2%XEo8}zf{YgB?mI=1?s^4Ix%clP<`EK#mG^KNxr%m;JCWrC>kotigp zZ}jYvNX05?E2omYZ$Qb1*!ue7=72GI*YWQQ$|c>(;xKVm?rv<Y$*twh4f*=btL^Rj z@{x+oL1^Ux-`pxETRLt=Nf?;UBbP@v1Rzi*kh%Bu`LUhG-0Vy~<V9slJb$)RHX7$4 z009U<00Izz00bZaf&WmznGrhS=Nc`Z?MYFO+^dTwDhNOT0uX=z1Rwwb2tWV=5P$## z{y_oNCOUme^p%tU|L=eQ-*WpW=LhG8bIrNp<m0}L6Mf;NoR^#hPJ=Vaxf>(;%=yIm z$hqL0b5I}v0SG_<0uX=z1Rwwb2tc4zKomu1y(4Eb7aaPw&{_9H8o6-4$s49?(R8Y; z3)4sk+Js51l5gOaRm-3K#cDfv>*o$N^})ftlm6(h*5M}&wSYg@zPeHoRZ+A3B3%G~ z>HhWjo`E+VYS6=~y_Kb{a9WhEFn>j*w<+!Dd#glIY;;;wP9#}uIzm~Im~M{~{%hdd W+VZB~DVf<+@^*S@I_`r`8uSZlg8ZBS literal 0 HcmV?d00001