mapbox / rio-pansharpen Goto Github PK
View Code? Open in Web Editor NEWpansharpening landsat scenes
License: MIT License
pansharpening landsat scenes
License: MIT License
For some workflows, we should drop the alpha band. An --out-alpha
CLI option and a corresponding out_alpha
function argument should handle it.
I am trying to get this to run, but every try I do ends up with this error. Stack trace follows:
Traceback (most recent call last): File "/home/ubuntu/anaconda2/envs/rasterio-env/bin/rio", line 11, in <module> sys.exit(main_group()) File "/home/ubuntu/anaconda2/envs/rasterio-env/lib/python2.7/site-packages/click/core.py", line 716, in __call__ return self.main(*args, **kwargs) File "/home/ubuntu/anaconda2/envs/rasterio-env/lib/python2.7/site-packages/click/core.py", line 696, in main rv = self.invoke(ctx) File "/home/ubuntu/anaconda2/envs/rasterio-env/lib/python2.7/site-packages/click/core.py", line 1060, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/ubuntu/anaconda2/envs/rasterio-env/lib/python2.7/site-packages/click/core.py", line 889, in invoke return ctx.invoke(self.callback, **ctx.params) File "/home/ubuntu/anaconda2/envs/rasterio-env/lib/python2.7/site-packages/click/core.py", line 534, in invoke return callback(*args, **kwargs) File "/home/ubuntu/anaconda2/envs/rasterio-env/lib/python2.7/site-packages/rio_pansharpen/scripts/cli.py", line 46, in pansharpen jobs, half_window, customwindow File "/home/ubuntu/anaconda2/envs/rasterio-env/lib/python2.7/site-packages/rio_pansharpen/worker.py", line 167, in calculate_landsat_pansharpen rm.run(jobs) File "/home/ubuntu/anaconda2/envs/rasterio-env/lib/python2.7/site-packages/riomucho/__init__.py", line 108, in run for data, window in self.pool.imap_unordered(reader_worker, self.windows): File "/home/ubuntu/anaconda2/envs/rasterio-env/lib/python2.7/site-packages/riomucho/single_process_pool.py", line 9, in imap_unordered yield reader_worker(i) File "/home/ubuntu/anaconda2/envs/rasterio-env/lib/python2.7/site-packages/riomucho/__init__.py", line 33, in manualRead raise e AttributeError: bilinear
I am running this in a conda-env. This is the output of conda env export
(untruncated since the cause may be some conflict):
`Using Anaconda Cloud api site https://api.anaconda.org
name: rasterio-env
dependencies:
The cli command and python module are named pansharpen
. Maybe the repo should be too?
Is there any reason to keep this repo private? I propose we make it a proper rio pansharpen
tool and spend a few hours cleaning it up for a release.
We should define the parameters, return values, and a short description.
We should complete the readme with coverage status, examples for using the cli and api, instructions for installing the module etc.
We should build a pure function (data-in, data-out, no IO) that we can unit test easily. This might take some refactoring to accomplish.
I'm thinking of a function with a signature like:
def pansharpen(vis, vis_transform, pan, pan_transform, method="Brovey"):
"""Pansharpen a lower-resolution visual band
Parameters
=========
vis: ndarray, 3D with shape == (3, vh, vw)
Visual band array with RGB bands
vis_transform: Affine
affine transform defining the georeferencing of the vis array
pan: ndarray, 2D with shape == (ph, pw)
Panchromatic band array
pan_transform: Affine
affine transform defining the georeferencing of the pan array
method: string
Algorithm for pansharpening; default Brovey
Returns:
======
pansharp: ndarray, 3D with shape == (3, ph, pw)
pansharpened visual band
affine transform is identical to `pan_transform`
"""
given the rio
naming of the repo, we should move the setup.py entry point to register this as a rasterio plugin instead of a standalone script.
Trying to run this, I am getting the following error, probably because Window
objects in rasterio
no longer are tuples.
Rasterio version 1.1.2
MuchoChildError:
Child process's traceback:
Traceback (most recent call last):
File "/home/jovyan/.conda/envs/py3/lib/python3.6/site-packages/riomucho/__init__.py", line 63, in wrapper
return func(*args, **kwds)
File "/home/jovyan/.conda/envs/py3/lib/python3.6/site-packages/riomucho/__init__.py", line 119, in __call__
return self.user_func(srcs, window, ij, global_args), window
File "/home/jovyan/.conda/envs/py3/lib/python3.6/site-packages/rio_pansharpen/worker.py", line 77, in _pansharpen_worker
rgb_window = _pad_window(rgb_base_window, padding)
File "/home/jovyan/.conda/envs/py3/lib/python3.6/site-packages/rio_pansharpen/utils.py", line 116, in _pad_window
(wnd[0][0] - pad, wnd[0][1] + pad),
TypeError: 'Window' object does not support indexing
Hi there,
Do you think I could use this package to pansharpening Landsat8 TIR images (Band 10), or it just work on the visible bands?
Thanks in advance,
LSR
Right now, our manually doubled affine numbers give us a slight multispectral/panchromatic offset. This isn’t a big deal today, but it’s something we should know how to handle.
We’ve used other methods in the past, but they’re prone to seams in unpredictable cases depending on pixel alignment. Per voice w/ @dnomadb, @virginiayung, @perrygeo, the most bulletproof way would look something like:
As a bonus, buffered windows would also solve the color-seam problem that would appear if we applied this code to commercial imagery.
Pip install failed with
IOError: [Errno 2] No such file or directory: 'README.md'
pip install rio-pansharpen
$pip install rio-pansharpen
Collecting rio-pansharpen
Downloading rio-pansharpen-0.1.0.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/mp/nl3vzcd93979ktmr6rxtt48r0000gn/T/pip-build-fxrufF/rio-pansharpen/setup.py", line 6, in <module>
with codecs_open('README.md', encoding='utf-8') as f:
File "/Users/VirginiaMapbox/venv/lib/python2.7/codecs.py", line 896, in open
file = __builtin__.open(filename, mode, buffering)
IOError: [Errno 2] No such file or directory: 'README.md'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/mp/nl3vzcd93979ktmr6rxtt48r0000gn/T/pip-build-fxrufF/rio-pansharpen/
0.1.1
:I should have used README.rst in the setup.py instead of the markdown file. For release[0.1.1]
, I removed setup.cfg
which tells PyPI where my README file is:
[metadata]
description-file = README.md
I was able to run pip install rio-pansharpen
successfully after this change. For the next release, I will include README.rst as well as try to add the README files to MANIFEST.in
.
We're currently mixing the type of the method
argument to pansharpen.
It defaults to a string but the code expects a function
We should either pass around a string (e.g. "Brovey"
) instead of a function to be safe from any distributed/multiprocessing gotchas
would allow us to keep color detail throughout the process for use with rio color, etc
We need to do more direct unit tests and make sure we're hitting all the code.
Add tests for changes made in #9
Not sure if this is a problem with rio-pansharpen itself or rio-mucho.
I tried running the pansharpening over cropped Landsat images, but a particular window size keeps giving me this error, no matter if I try running from Python or directly via rio pansharpen
.
After some tests, I managed to create the following repeatable sequence of actions to reproduce the problem:
landsat download -b 8,4,3,2 LC80390282016240LGN00
gdal_translate
to this exact window:gdal_translate -srcwin 3812 2460 366 740 /home/ubuntu/landsat/downloads/LC82220762016210LGN00/LC82220762016210LGN00_B8.TIF gdal_b8.tif
gdal_translate -srcwin 1906 1230 183 371 /home/ubuntu/landsat/downloads/LC82220762016210LGN00/LC82220762016210LGN00_B4.TIF gdal_b4.tif
gdal_translate -srcwin 1906 1230 183 371 /home/ubuntu/landsat/downloads/LC82220762016210LGN00/LC82220762016210LGN00_B3.TIF gdal_b3.tif
gdal_translate -srcwin 1906 1230 183 371 /home/ubuntu/landsat/downloads/LC82220762016210LGN00/LC82220762016210LGN00_B2.TIF gdal_b2.tif
rio pansharpen gdal_b{8,4,3,2}.tif pan.tif
The full output is as follows:
/home/ubuntu/anaconda2/envs/benchmark/lib/python2.7/site-packages/rio_pansharpen/scripts/cli.py:46: FutureWarning: The value of this property will change in version 1.0. Please see https://github.com/mapbox/rasterio/issues/86 for details.
jobs, half_window, customwindow
/home/ubuntu/anaconda2/envs/benchmark/lib/python2.7/site-packages/rio_pansharpen/worker.py:134: FutureWarning: GDAL-style transforms are deprecated and will not be supported in Rasterio 1.0.
transform=guard_transform(pan_src.transform),
/home/ubuntu/anaconda2/envs/benchmark/lib/python2.7/site-packages/rio_pansharpen/worker.py:160: FutureWarning: GDAL-style transforms are deprecated and will not be supported in Rasterio 1.0.
"r_aff": guard_transform(r_meta['transform']),
Traceback (most recent call last):
File "/home/ubuntu/anaconda2/envs/benchmark/lib/python2.7/site-packages/rio_pansharpen/worker.py", line 167, in calculate_landsat_pansharpen
rm.run(jobs)
File "/home/ubuntu/anaconda2/envs/benchmark/lib/python2.7/site-packages/riomucho/__init__.py", line 108, in run
with rio.open(self.outpath, 'w', **self.options) as dst:
File "/home/ubuntu/anaconda2/envs/benchmark/lib/python2.7/site-packages/rasterio/__init__.py", line 193, in open
s.start()
File "rasterio/_io.pyx", line 1401, in rasterio._io.RasterUpdater.start (rasterio/_io.c:19697)
ValueError: blockxsize exceeds raster width.
Traceback (most recent call last):
File "/home/ubuntu/anaconda2/envs/benchmark/bin/rio", line 11, in <module>
sys.exit(main_group())
File "/home/ubuntu/anaconda2/envs/benchmark/lib/python2.7/site-packages/click/core.py", line 716, in __call__
return self.main(*args, **kwargs)
File "/home/ubuntu/anaconda2/envs/benchmark/lib/python2.7/site-packages/click/core.py", line 696, in main
rv = self.invoke(ctx)
File "/home/ubuntu/anaconda2/envs/benchmark/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/ubuntu/anaconda2/envs/benchmark/lib/python2.7/site-packages/click/core.py", line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/ubuntu/anaconda2/envs/benchmark/lib/python2.7/site-packages/click/core.py", line 534, in invoke
return callback(*args, **kwargs)
File "/home/ubuntu/anaconda2/envs/benchmark/lib/python2.7/site-packages/rio_pansharpen/scripts/cli.py", line 46, in pansharpen
jobs, half_window, customwindow
File "/home/ubuntu/anaconda2/envs/benchmark/lib/python2.7/site-packages/rio_pansharpen/worker.py", line 167, in calculate_landsat_pansharpen
rm.run(jobs)
File "/home/ubuntu/anaconda2/envs/benchmark/lib/python2.7/site-packages/riomucho/__init__.py", line 108, in run
with rio.open(self.outpath, 'w', **self.options) as dst:
File "/home/ubuntu/anaconda2/envs/benchmark/lib/python2.7/site-packages/rasterio/__init__.py", line 193, in open
s.start()
File "rasterio/_io.pyx", line 1401, in rasterio._io.RasterUpdater.start (rasterio/_io.c:19697)
ValueError: blockxsize exceeds raster width.
Last July, we integrated pansharpening into the l8sr pipeline and blogged about it. We'd like to clean up this current repo, modularize pansharpening and have it ready as a plugin for the new l8sr-live
stack which handles all preprocessing work necessary for Landsat (https://github.com/mapbox/satellite/issues/1204#issue-167649314). Here's the checklist of things we need to complete before releasing pansharpening into the wild:
Item | Dev | Test | PR ready for 👀 | Merge PR |
---|---|---|---|---|
New window approach | ✅ #2 | ✅ #1 (comment) | ✅ #2 | ✅ |
Add option to output 16bit tifs | ✅ #3 | ✅ #11 | ✅ #9 | ✅ |
Refactor python API | ✅ #13 | ✅ #5 | ✅ #13 | ✅ |
Better test coverage | ✅ #13 | ✅ #5 | ✅ #13 | ✅ |
Update Readme | ✅ #14 | ✅ | ✅ | |
Add docstrings | ✅ #14 | ✅ | ✅ |
Currently the src_nodata is hardcoded to zero which is problematic for pansharpening products derived from level 1 L8 Bands.
For example, using LaSRC, the surface reflectance and toa products are output as int16 (-32768 to 32768) with a nodata value of -9999. When we pansharpen these, the nodata mask is incorrect since it assumes zero.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.