From fd384052df6f408bd5446a2dc96161bc4a242cfa Mon Sep 17 00:00:00 2001 From: Timothy Middelkoop Date: Thu, 9 Dec 2021 15:23:04 +0000 Subject: [PATCH] Simple combine script with rasterio --- .gitignore | 1 + landsat/ReadMe.md | 7 +++++++ landsat/combine.py | 17 +++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 landsat/combine.py diff --git a/.gitignore b/.gitignore index 496cb34..a520a14 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ config* token* local* data/ +output/ diff --git a/landsat/ReadMe.md b/landsat/ReadMe.md index 9a51147..025de7e 100644 --- a/landsat/ReadMe.md +++ b/landsat/ReadMe.md @@ -36,3 +36,10 @@ cd CLASS-Examples/landsat/ bash get-index.sh cat data/index.csv | python3 search.py | bash download.sh ``` + +## Analysis +``` +sudo apt-get install python3-rasterio +install -dv output/ +python3 combine.py +``` diff --git a/landsat/combine.py b/landsat/combine.py new file mode 100644 index 0000000..8bb4079 --- /dev/null +++ b/landsat/combine.py @@ -0,0 +1,17 @@ +#!/usr/bin/python3 +import os +import rasterio + +# Open the first directory, could walk entire tree +for dirname, dirs, files in os.walk('data'): + source = dirs[0] + break + +with rasterio.open("data/%s/%s_B2.TIF" % (source, source)) as band2: + meta = band2.meta + +meta.update(count = 3, driver='PNG') +with rasterio.open('output/result.png', 'w+', **meta) as output: + for i in range(1, 4): + print(i) + output.write_band(i,rasterio.open("data/%s/%s_B%d.TIF" % (source, source, i+3)).read(1)) # Red