Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

img.sum() #13

Closed
gillins opened this issue Sep 15, 2017 · 2 comments
Closed

img.sum() #13

gillins opened this issue Sep 15, 2017 · 2 comments
Labels
bug Something isn't working major

Comments

@gillins
Copy link
Member

gillins commented Sep 15, 2017

Original report by alan piszcz (Bitbucket: apiszcz, GitHub: apiszcz).


The documentation example shows inputs.img.sum(), when I try this I am getting an error.
The applier example does not show how 'inputs' is set.
I tried a list of file names, which does support the method sum.
Not sure what I'm doing wrong here.

#!python

> py lib\_learn\rios\accum.py
Images aren't on the same grid
Creating output file that is 1503P x 1241L.
Processing input file file2.tif.
0Traceback (most recent call last):
  File "lib\_learn\rios\accum.py", line 46, in <module>
    applier.apply(accum, infiles, outfiles, otherargs, controls=controls)
  File "lib\rios\applier.py", line 667, in apply
    userFunction(*params)
  File "lib\_learn\rios\accum.py", line 24, in accum
    tot = float(inputs.img.sum())
AttributeError: 'BlockAssociations' object has no attribute 'img'
#!python


def accum(info, inputs, outputs, otherargs):
    tot = float(inputs.img.sum())
    n = inputs.img.size
    otherargs.tot += tot
    otherargs.count += n


infiles = applier.FilenameAssociations()
infiles.img = ["file1.tif","file2.tif"]

outfiles = applier.FilenameAssociations()
outfiles.outimage = "outfile.tif"

controls = applier.ApplierControls()
controls.setReferenceImage(infiles.image1)
controls.progress = cuiprogress.GDALProgressBar()
controls.setOutputDriverName("GTiff")
controls.setCreationOptions(["COMPRESS=DEFLATE"])

otherargs = applier.OtherInputs()
otherargs.tot = 0.0
otherargs.count = 0
applier.apply(accum, infiles, outfiles, otherargs, controls=controls)
print('Average value = ', otherargs.tot / otherargs.count)
@gillins
Copy link
Member Author

gillins commented Sep 16, 2017

Original comment by Neil Flood (Bitbucket: neilflood, GitHub: neilflood).


Hi Alan,

you have given infiles.img a list of filenames, and this means that the resulting img field on the inputs object inside your function will itself be a list of numpy arrays, one from each file in the same order. The list datatype does not support a .sum() method.

In addition, you have used the setReferenceImage() method, giving in infiles.image1, which does not exist. You probably meant to do this:

#!python
controls.setReferenceImage(infiles.img[0])

@gillins
Copy link
Member Author

gillins commented Sep 19, 2017

Original comment by Neil Flood (Bitbucket: neilflood, GitHub: neilflood).


Closed. Not a bug.

@gillins gillins closed this as completed Sep 19, 2017
@gillins gillins added major bug Something isn't working labels Nov 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working major
Projects
None yet
Development

No branches or pull requests

1 participant