Code Monkey home page Code Monkey logo

Comments (11)

vincentsarago avatar vincentsarago commented on May 24, 2024 1

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.

drnextgis avatar drnextgis commented on May 24, 2024 1

Good job @vincentsarago! Can we use contextlib2.ExitStack?

from rio-cogeo.

dionhaefner avatar dionhaefner commented on May 24, 2024 1

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.

vincentsarago avatar vincentsarago commented on May 24, 2024

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.

dionhaefner avatar dionhaefner commented on May 24, 2024

Works fine from my experience (raster files > 20GB, script staying below 500MB memory usage).

from rio-cogeo.

vincentsarago avatar vincentsarago commented on May 24, 2024

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.

dionhaefner avatar dionhaefner commented on May 24, 2024

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.

vincentsarago avatar vincentsarago commented on May 24, 2024

@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.

dionhaefner avatar dionhaefner commented on May 24, 2024

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.

vincentsarago avatar vincentsarago commented on May 24, 2024

Excellent I was going to ask you and @drnextgis if you could review it and see if it fit your needs 😄

from rio-cogeo.

vincentsarago avatar vincentsarago commented on May 24, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.