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

add single netCDF layer to map #285

Closed
albertlarson opened this issue Feb 2, 2021 · 10 comments
Closed

add single netCDF layer to map #285

albertlarson opened this issue Feb 2, 2021 · 10 comments
Labels
Feature Request New feature or request help wanted Extra attention is needed

Comments

@albertlarson
Copy link

I saw the notebook where you implemented the ipyleaflet's Velocity code utilizing a .nc file. Is it possible to extend the functionality of geemap / ipyleaflet to enable the ability to simply display an .nc file as a layer?

Here is a link to some .nc files as an example:
https://opendap.jpl.nasa.gov/opendap/OceanTemperature/amsre/L3/sst_1deg_1mo/contents.html

cc: @davidbrochart from xarray-leaflet

@albertlarson albertlarson added the Feature Request New feature or request label Feb 2, 2021
@giswqs
Copy link
Member

giswqs commented Feb 3, 2021

Good suggestion. I think it is possible to implement this feature, but it might a while. The upstream xarray_leaflet package currently does not work properly on Windows. https://github.com/davidbrochart/xarray_leaflet/issues/30

@ErikSeras
Copy link
Contributor

Is it possible to add a xarray as a layer to eefolium?

@giswqs
Copy link
Member

giswqs commented Feb 3, 2021

Is it possible to add a xarray as a layer to eefolium?

I don't think so.

@giswqs giswqs added the help wanted Extra attention is needed label Mar 5, 2021
@lopezvoliver
Copy link
Member

I am prototyping a function to read variables from a netCDF file and add them as an ee.Image. So far, I used the netcdf4 library to read one variable (e.g. u_wind in the wind-global.nc) and then numpy_to_ee to get the image on the map. However, if I leave the data going from lon=0 to 360, the image only displays on half of the map:

image

If I shift the data so that it goes from lon=-180 to 180, then it works:

image

Any suggestions on the desired functionality? I envision having a list of variables to read so that we can add them to the ee.Image as different bands. At the moment, I would suggest focusing on reading a file with one time slice only, and then we can build on that to read multiple time slices and create an image collection.

Do you suggest using netCDF4? xarray, gdal, or others?

Other suggestions?

@ErikSeras
Copy link
Contributor

Another option would be zarr and dask.

@albertlarson
Copy link
Author

I am prototyping a function to read variables from a netCDF file and add them as an ee.Image. So far, I used the netcdf4 library to read one variable (e.g. u_wind in the wind-global.nc) and then numpy_to_ee to get the image on the map. However, if I leave the data going from lon=0 to 360, the image only displays on half of the map:

image

If I shift the data so that it goes from lon=-180 to 180, then it works:

image

Any suggestions on the desired functionality? I envision having a list of variables to read so that we can add them to the ee.Image as different bands. At the moment, I would suggest focusing on reading a file with one time slice only, and then we can build on that to read multiple time slices and create an image collection.

Do you suggest using netCDF4? xarray, gdal, or others?

Other suggestions?

Hi Oliver ---

I like your method. Would you mind sharing a notebook and maybe sample data? Your second graphic has a nice palette and I would like to replicate.

I would expect -180 to 180 for lines of longitude, and -90 to 90 for lines of latitude. I guess you could consider opening the .nc file with xarray and then calling it from numpy. As I'm sure you're aware, the more packages you add, the greater the potential computing slowdown.

Albert

@giswqs
Copy link
Member

giswqs commented Mar 5, 2021

@lopezvoliver The prototype looks nice!! I would suggest using xarray. Keep in mind that xarray is not an official dependency of geemap yet. We need more testing to make sure that geemap can be installed smoothly across platforms before including a new dependency. For the time being, you can use try ... except ... to prompt users to install xarray if needed. Similar to what I did for the geemap.add_raster() function.

One thing I am not sure about is the size limit of a numpy array that can be converted to ee.Image on-the-fly. From geojson to ee.FeatureCollection, the size limit is ~4 MB.

Ideally, I would envision the functionality being split into two functions, e.g., Map.add_netcdf() and netcdf_to_ee(). Map.add_netcdf() would load the netcdf dataset and display it on the map using xarray_leaflet without having to convert it to ee.Image, similar to the geemap.add_raster() function. The netcdf_to_ee() would wrap the numpy_to_ee() function, allowing direct conversion from netcdf to ee.Image or ee.ImageCollection.

You don't have to implement this kind of ideal situation. Just get your prototype going and we can improve it later on. Thank you.

@giswqs
Copy link
Member

giswqs commented Mar 5, 2021

@albertlarson I believe the sample data is from https://github.com/giswqs/geemap/blob/master/examples/data/wind-global.nc

For palette and colormaps, you can take a look at #302

@lopezvoliver
Copy link
Member

@albertlarson You can check a preview of the new function here. The palette I used was "YlOrRd". Hopefully you can test it soon with your dataset.

@giswqs I agree, I think this will be useful mainly for large-scale datasets (e.g. half-degree or coarser resolution).

giswqs added a commit that referenced this issue Mar 11, 2021
@giswqs
Copy link
Member

giswqs commented Mar 11, 2021

This feature has been implemented. See notebook example https://geemap.org/notebooks/68_netcdf_to_ee. A big thank you to @lopezvoliver for making this happen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants