awesome-spectral-indices / spyndex

Awesome Spectral Indices in Python.
https://spyndex.readthedocs.io/
MIT License
191 stars 22 forks source link

issue in calculating some of the vegetation indices #4

Closed Raziehgithub closed 3 years ago

Raziehgithub commented 3 years ago

Hi, I have used this library to calculate some vegetation indices, but the "EVI", "GBNDVI", "GLI", "GRNDVI", "MSAVI", "MTVI2", and "VARI" could not calculate and I got this error: MergeError: conflicting values for variable 'band' on objects to be combined. You can skip this check by specifying compat='override'.

davemlz commented 3 years ago

Hi, @Raziehgithub!

I wasn't able to reproduce the error you got. Could you please share the code here?

Raziehgithub commented 3 years ago

import pandas as pd from affine import Affine import spyndex import xarray as xr import rasterio as ro import os import glob

tif_files = glob.glob('clipped*.tif') da = xr.open_rasterio(tif_files[1]) idx_1 = spyndex.computeIndex( index = ["ARVI", "BNDVI", "CIG", "CIRE", "CVI", "DVI", "GARI", "GNDVI", "MCARI", "MNLI", "MSR", "NDYI", "NLI","OSAVI", "RDVI", "SAVI", "TGI", "NDVI", "NDREI", "EVI", "GBNDVI", "GLI", "GRNDVI", "MSAVI", "MTVI2", "VARI"], params = { "B": da.sel(band = 1), "G": da.sel(band = 2), "R": da.sel(band = 3), "RE1": da.sel(band = 4), "N": da.sel(band = 5), "L": 0.5, "g": 2.5, "C1": 6, "C2": 7.5 } ) idx_1

error

julianblue commented 3 years ago

@davemlz I believe this has to do with some returned indices not having the same coordinates. Problematic coordinates seem to be "gsd", "common_name", "band" and some others. As of my understanding XR.concat should avoid this issue with the compat= "no_conflicts" statement, which is default. Might adding a coordinate check help to ensure all calculated indices contain the same coordinates ?

davemlz commented 3 years ago

Yes. You're totally right, @julianblue! I'm on it and I hope to have it done later :) For now and until then, [@Raziehgithub, @julianblue], if you want, a workaround for this problem is to set returnOrigin=False. With this the indices are not concatenated and are returned as a list :)

davemlz commented 3 years ago

The problem was solved! If you download the dev version it should work now :) pip install git+https://github.com/davemlz/spyndex.

Thank you for pointing this out!

davemlz commented 3 years ago

[@Raziehgithub, @julianblue], I have released v0.0.2 with the fix. Now you can download the new version with pip install -U spyndex :)

Raziehgithub commented 3 years ago

Thank you for your response and sharing your useful github!

On Thu, Oct 7, 2021 at 2:13 PM David Montero Loaiza < @.***> wrote:

@.*** https://github.com/Raziehgithub, @julianblue https://github.com/julianblue], I have released v0.0.2 with the fix. Now you can download the new version with pip install -U spyndex :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/davemlz/spyndex/issues/4#issuecomment-938080569, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVMNI6XOA5JIMQXTHSAPZZDUFXWPBANCNFSM5FNGGEHQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.