toPandas
inter8888 opened this issue · 4 comments
Hello @davemlz! Thank you for your job with eemont! I was thinking if there is possible to export a time series of an area of interest to pandas. After checking the documentation I think, that is only avaiable within a Geometry.Point. by getTimeSeriesByRegion function. Am I wrong or that is not possible with eemont? I want to have a pandas dataframe like this.
I need it to do the unsupervised classification with kmeans. Do you know how can I create such a dataframe with gee?
Thank you in advance! I'd be happy to work on it!
Hi, @inter8888!
Actually, you can do it for any ee.Geometry, ee.Feature or ee.FeatureCollection! :) I have two eemont
tutorials regarding this:
Time Series By Region: https://github.com/davemlz/eemont/blob/master/tutorials/013-Time-Series-By-Region-Pandas.ipynb
Time Series By Regions: https://github.com/davemlz/eemont/blob/master/tutorials/014-Time-Series-By-Regions-Pandas.ipynb
Both show how to use the getTimeSeriesByRegion
and getTimeSeriesByRegions
methods and how to transform them into pandas dataframes (using geemap
).
I hope they can help you!
Cheers!
Thank you for your fast answer!
I see, but with getTimeSeriesByRegions(reducer = [ee.Reducer.mean()],
I calculate a mean from a e.g. ee.Geometry.Rectangle
and than have only 1D dataframe with one value for a date in each ee.FeatureCollection, because I need to readuce it, like:
I would like to have a 3D dataframe with latitude, longitude and time. Is it possible to create such a datacube? I am sorry for my unclear explanation.
Ohhhh, now I understand what you're trying to do. You need to extract all pixel values for each image in an image collection (saving their coordinates). Ok, this is not exactly possible with eemont, but, if you could manage to create a feature collection where each feature is a point representing each one of the pixels inside your region of interest (and including those coordinates as attributes of your feature collection), you could use that feature collection with the getTimeSeriesByRegions
method and then convert it to a pandas dataframe using the geemap.ee_to_pandas
function.
Another simple way to do this would be to use restee or geemap.ee_to_numpy
. Then, converting the resulting arrays into a pandas dataframe.
If you want a compltely Earth Engine solution, check the ee.Image.sampleRectangle
method. This extracts the pixels values for a region of interest and stores them in a 2D Array. If you create additional coordinates bands using the ee.Image.pixelLonLat
you could easily get a 3D Array by storing the coordinates values too.
I hope it works! 🚀
Closing this issue for now. Reopening for future discussions! :)