Comments (11)
So @dionhaefner did this in https://github.com/DHI-GRAS/terracotta/blob/master/terracotta/scripts/optimize_rasters.py#L229-L269 so we could bring the solution over
from rio-cogeo.
Good job @vincentsarago! Can we use contextlib2.ExitStack?
from rio-cogeo.
Yes, flake8
is very critical of lambdas (IMO to a fault, but who am I to judge). This should work though:
- dst_ctx = lambda: memfile.open(**meta)
+ dst_ctx = functools.partial(memfile.open, **meta)
If you're not too paranoid about unclosed file descriptors in some edge cases I think it would also be perfectly fine to initialize the contexts first and enter them later:
if in_memory:
file_ctx = MemoryFile()
dst_ctx = memfile.open(**meta)
else:
file_ctx = ...
dst_ctx = ...
with file_ctx, dst_ctx as dst:
...
from rio-cogeo.
Hi @drnextgis, Thanks for opening the issue.
Does it mean that this plugin is not suit for cases when source raster is not fit in memory?
Yes sadly I don't think it could work other ways or it will need to many refactor. The main problem I can think of is that overviews need to be happened after the high resolution data (inside the tiff structure) which is kind of tricky to get.
I don't have a perfect solution for you I'm sorry.
from rio-cogeo.
Works fine from my experience (raster files > 20GB, script staying below 500MB memory usage).
from rio-cogeo.
Well I gave a try in #75 but sadly the contextlib.ExitStack()
method is a python 3 only method
I don't have python2 in my heart but dropping it might be a big deal for some users.
cc @dionhaefner
from rio-cogeo.
That's a bummer because it means some additional nesting, but shouldn't be a showstopper. You can e.g. do something like this instead:
if in_memory:
file_ctx = MemoryFile
dst_ctx = lambda: memfile.open(**meta)
# (or functools.partial if you like that better)
else:
file_ctx = ...
dst_ctx = ...
with file_ctx(), dst_ctx() as dst:
...
from rio-cogeo.
@dionhaefner I'm not sure to understand, did you check the last version I pushed. Basically I did the same you did in terracota
from rio-cogeo.
I was still at the ExitStack
issue :) But if it's solved through contextlib2
all the better. I'll have a closer look at your PR during the weekend.
from rio-cogeo.
Excellent I was going to ask you and @drnextgis if you could review it and see if it fit your needs
from rio-cogeo.
@dionhaefner BTW the solution you proposed seems kinda of smart, I'll see if we can do this instead. Right now flake8 is not happy on dst_ctx = lambda: memfile.open(**meta)
with this error do not assign a lambda expression, use a defflake8(E731)
from rio-cogeo.
Related Issues (20)
- remove call to rasterio._path module
- Creating COG out of big rasters HOT 8
- mercantile.bounds for cog HOT 2
- Installation error on ubuntu 20.04 docker image HOT 2
- Installing rio_cogeo 3.1.0 on virtualenv for a Python package HOT 1
- Displaying continuous data with multiple transparency values?
- add `ZOOM_LEVEL` creation option for web optimized COG
- installation give error
- Creating a COG in place rather than generating a new file? HOT 1
- add option to forward namespaced metadata
- add python 3.10 support
- All Console output is standard error HOT 6
- COG convesion succeeds with GDAL but not with rio-cogeo HOT 4
- Change folder of "execution" HOT 11
- NetCDF to CoG workflow
- GeoTIFF with invalidated optimizations shows up as valid HOT 1
- installation issues - coggeo command HOT 3
- limit pydantic to `1.0` HOT 3
- Shift/zoom after updating to >=4 HOT 2
- Pydantic 2.0 incompatible with morecantile HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rio-cogeo.