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

toPandas #34

Closed
inter8888 opened this issue Jun 25, 2021 · 4 comments
Closed

toPandas #34

inter8888 opened this issue Jun 25, 2021 · 4 comments

Comments

@inter8888
Copy link

inter8888 commented Jun 25, 2021

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.
grafik

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!

@davemlz
Copy link
Owner

davemlz commented Jun 25, 2021

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!

@inter8888
Copy link
Author

inter8888 commented Jun 25, 2021

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:
grafik

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.

@davemlz
Copy link
Owner

davemlz commented Jun 26, 2021

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! 🚀

@davemlz
Copy link
Owner

davemlz commented Jun 30, 2021

Closing this issue for now. Reopening for future discussions! :)

@davemlz davemlz closed this as completed Jun 30, 2021
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

No branches or pull requests

2 participants