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

handle "classification" bands #428

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

handle "classification" bands #428

wants to merge 1 commit into from

Conversation

fitoprincipe
Copy link
Member

This is simlar to bits2bands, but in this case handling "classification" bands.

The main idea is to be able to handle a classification band using the same information as provided by GEE in the dataset's description, like the SCL band here. The only work the user needs to do is convert this:

image

to this:

{
  '2': 'dark',
  '3': 'shadow',
  '7': 'clouds_low',
  '8': 'clouds_mid',
  '9': 'clouds_high',
  '10': 'cirrus'
}

It doesn't need to contain all classes but just the needed ones.

@fitoprincipe fitoprincipe requested a review from 12rambau February 7, 2025 15:03
class_info = format_class_info(class_info)
# I don't see the class info coming from the server, so it'll client side until I get challenged
images = []
for class_value, class_name in class_info.items():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be possible to convert the dictionary of the classes into a ee object and thus change a bit the logic with 2 map ? I still have the hope that one day they will open extensibility of the javascript interface so we can port all these cool stuff to the code editor (that's why I'm forcing myself to always use ee computed object in the parameters)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually, I do this when the parameter can come from the server, for example, as it happens with the param styleProperty in the method ee.FeatureCollection.style. However, I find this confusing, because AFAIK you can use a dict as a property only when you compute it on the fly, but you cannot store a dict as a property when you save it as an GEE asset. If this is true (I tested it and seems to be true), to compute it on the fly you need to have it on the client-side, therefore I don't see the benefit of converting it to a server-side object and process it on the server.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could create a function that process/format it from STAC, but it'll still be on the client-side. We can do it on a follow-up PR.

band: band that contains class information

Example:
.. code-block:: python
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to use the jupyter-execute directive to see something here. you will need to use the documentation initialize parameter and display the image with plot I think it would be nice for the user to see what it does in the documentation.

band: name of the bit band. Defaults to first band.

Example:
.. code-block:: python
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here let's make the example real

"""Test the ``classToBands`` method."""
class_info = {"3": "shadow", "9": "clouds_high", "11": "snow"}
decoded = s2_class_image.geetools.classToBands(class_info, "SCL")
aoi = ee.Geometry.Polygon(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's make this AOI a fixture as you are rusing it in the next one

decoded = image.geetools.classToBands(class_info, "SCL")
"""
class_info = format_class_info(class_info)
# I don't see the class info coming from the server, so it'll client side until I get challenged
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eheh, here I am challenging you in the top comment of this PR ;-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same answer 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants