davemlz / eemont

A python package that extends Google Earth Engine.
https://eemont.readthedocs.io/
MIT License
417 stars 69 forks source link

Tasseled Cap Transformations #46

Closed aazuspan closed 3 years ago

aazuspan commented 3 years ago

Is this a Feature Request for eemont or for eeExtra? Not sure! It would require matching image STAC IDs to a list of ee.Image coefficients and calculating a weighted mean, so it could be done using just earthengine-api and your STAC tools from eemont.

Is your feature request related to a problem? Please describe. If you're not familiar with tasseled cap transformations, different orthogonal axes (usually brightness, greenness, and wetness) are calculated as the weighted mean of spectral bands, and the weighting coefficients depend on the axis and the sensor. There are published coefficients available for Landsat OLI TOA, Landsat TM/ETM/OLI surface reflectance, Sentinel-2 MSI TOA, and MODIS.

Calculating tasseled cap manually in GEE is kind of a pain because it requires tracking down the correct coefficients, putting them into a multi-band constant image, and applying them to the matching bands in your input image. Having a method to quickly calculate tasseled cap in eemont would be awesome!

Describe the solution you'd like ee.Image.tasseledCap() and ee.ImageCollection.tasseledCap() methods that would apply published band-wise coefficients to Landsat, MODIS, or Sentinel-2 imagery to calculate brightness, greenness, and wetness bands. Those bands could be returned as a new image or added to the original image.

Describe alternatives you've considered I've thought about whether these could be implemented with your awesome-spectral-indices system, and I don't think that's possible because the formula varies depending on the dataset. But maybe there's a solution I haven't thought of?

Do you want to work on it? Sure!

Additional context :)

davemlz commented 3 years ago

Haha love the additional context!

This is a great idea, @aazuspan! :D And yes, I also think that using the STAC IDs is better for this!

Also, this is a perfect fit for eeExtra! Let me explain: eeExtra is a python package that @csaybar and I have created. This is a "ghost" package (or a "ninja" package, like we like to call it) since it is not required for users to download it as a standalone package, BUT, it is a dependency for eemont and for rgee (and rgeeExtra), which means that all methods in eeExtra are available for Python through eemont and for R through rgeeExtra in a standardized way. In other words, eeExtra is a standardized GEE methods provider for eemont and rgeeExtra.

I have added to eeExtra most of eemont methods (including the eemont STAC tools), so if you accept to add this feature there, you can use them! :)

How is the process of adding a new feature in eeExtra? well, it is pretty simple, in the package folder you can create a new subpackage (a new folder), maybe called Transformations, and in there it is just required to create the required files (e.g., __init__.py, core.py, utils.py and all the files that you need). The method, in this case tasseledCap(), is not extended to GEE in eeExtra, but rather just created as a simple function that receives an ee.Image or an ee.ImageCollection. After the method and tests are created, you can submit the PR and we will merge it and release a new version of eeExtra. After the release, I can add the method to eemont, or you, if you want to! :) And here, in eemont, the method is now extended to GEE for ee.Image and ee.ImageCollection by just importing and using ee_extra.Transformations.core.tasseledCap().

Let us know if you like the idea, @aazuspan! :)

PD: If you want to add the panSharpening and matchHistogram methods for eeExtra (that would be awesome since them would be available also for R!), you can also do it! The PlusCodes methods would be awesome to add them too, but unfortunately, since the dependency is not on conda, we would have problems with R.

aazuspan commented 3 years ago

Thanks for explaining @davemlz! I was wondering why things were implemented in eeExtra, and standardization between eemont and rgeeExtra makes perfect sense. Great design!

I'll go ahead and open an issue over there for tasseled cap. Feel free to close this :)

I'll migrate panSharpen and matchHistogram over there too when I get a chance, but they might take me longer to get to.