gee-community/geemap

checking lat/lon in module netcdf_to_ee converter

ZofiaBaldysz opened this issue · 3 comments

Environment Information

I'm using geemap on Colab

Description

I have lat every 0.025 degree for 100 points. For example 0, 0.025, 0.050 etc. Same for lon.

What I Did

I checked the code of the netcdf_to_ee on github (geemap/geemap/common.py/netcdf_to_ee)
dim_lon = np.unique(np.ediff1d(lon_data))
dim_lat = np.unique(np.ediff1d(lat_data))
This code compares floating numbers and even for regular grid it will return on occasion the error "The netCDF file is not a regular longitude/latitude grid"
I believe it needs to be rewritten

Please provide a complete script that can reproduce the issue.

Having a netcdf file like in attachement (test_wu.nc):

nc_file = '.../test_wu.nc' #reading my nc file
ds = xr.open_dataset(nc_file) #opening using xarray
img=geemap.netcdf_to_ee(nc_file=nc_file, var_names='temperature', lon='lon', lat='lat') #conerting netcdf to ee

Error: The netCDF file is not a regular longitude/latitude grid

This error appear due to the geemap/geemap/common.py [line: 3262-3267]:
dim_lon = np.unique(np.ediff1d(lon_data))
dim_lat = np.unique(np.ediff1d(lat_data))
if (len(dim_lon) != 1) or (len(dim_lat) != 1):
print("The netCDF file is not a regular longitude/latitude grid")
return
The problem: when we use function np.unique(np.ediff1d(lon_data)), we get an array that has more than one element. Therefore there is an error about unregular grid. This is due to if state comparison applied to floating point numbers.
test_wu.zip

Sorry for the delay. This bug has been fixed in #1973