gee-community / geetools

A collection of tools to work with Google Earth Engine Python API
https://geetools.readthedocs.io/en/stable/
MIT License
508 stars 121 forks source link

`makeDateBand` missing? #210

Closed fitoprincipe closed 6 months ago

fitoprincipe commented 7 months ago

I cannot find the new implementation of this function. The most similar would be this, but it's not exactly the same.

12rambau commented 7 months ago

The initial idea was to port all the functionalities to https://github.com/gee-community/geetools/blob/a8b0a0ab49e84197a07fecbea26dd36d60bb3bff/geetools/Image/__init__.py#L31

For a reason I cannot explain, I stopped at timestamp (which is fine as a default but could be improved). Let me add back what is mentioned in the docstring ....

12rambau commented 6 months ago

Ok now I remember why i dropped it. The problem here is that the "format" is letting people think that they can save the date as a humanly readable way. in short as a string when in fact a band can only support numbers. So in the end you can do doy or YYYYMMDD but certainly not Y-m-d.

My take away from this discovery was that it's more interesting to keep the most complete description of the date (the millisecond timestamp) and eventually parse it wherever we really need to transform it in a readable date.

Can you provide a use case where you really need to have a code stored in a band to perform operations ?

fitoprincipe commented 6 months ago

If you store dates as milliseconds, you need an int64 band, but if you store it as YY you only need a uint8, which is lighter.

I wanted to remain flexible, so user can choose what better suits his/her needs. The issue you mention can be solved by inspecting the parsed string and verifying it has an allowed format, or just let it fail, the error will look something like

date_band = makeDateBand(image, 'YYYY-dd')
date_band.getInfo()

EEException: Number.parse: Unable to convert '2020-01' to a number

which is pretty clear to me