jgrss / geowombat

GeoWombat: Utilities for geospatial data
https://geowombat.readthedocs.io
MIT License
182 stars 10 forks source link

Apply #275

Closed mmann1123 closed 1 year ago

mmann1123 commented 1 year ago

How would we pass arguments to the apply function? For instance if we want to change the count to 1?

import geowombat as gw

# Function with one argument
def user_func(block, n):
    return block * n

with gw.open('input.tif') as ds:

    # Functions are given as 'apply'
    ds.attrs['apply'] = user_func

    # Function arguments (n) are given as 'apply_args'
    ds.attrs['apply_args'] = [10.0]

    ds.gw.save(
        'output.tif',
        num_workers=2,
        overwrite=True,
        compress='lzw'
    )
jgrss commented 1 year ago

Hi @mmann1123, the apply() method was written for to_raster(), so it won't be supported with save().

mmann1123 commented 1 year ago

Ok thanks!