-
Notifications
You must be signed in to change notification settings - Fork 83
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
Converting NetCDF dataset with 2D coordinates to GeoTiff #47
Comments
What are the dimensions of |
this is the print out:
|
Here's the documentation for |
Currently For example:
@goriliukasbuxton, I see:
Can you define what |
|
Can you try: http://xarray.pydata.org/en/stable/generated/xarray.Dataset.rename_dims.html#xarray.Dataset.rename_dims data = data.rename_dims({"ground_pixel": "longitude", "scanline": "latitude"})
data.rio.to_raster("test1.tif") |
|
Whoops. wrong variable. How about this one: xds = xds.rename_dims({"ground_pixel": "longitude", "scanline": "latitude"})
data = xds.nitrogendioxide_tropospheric_column
data.rio.to_raster("test1.tif") |
no go:
|
Probably naming conflicts. I wonder if you need to drop the ground_pixel and scanline coordinates first. Are you able to share the file? |
Your data has unevenly spaced 2D lat/lon values. That means that either:
If (1) is your problem, you will need to re-project your data from 2D latlon back to the projected coordinates in 1D, add the 1D x&y coordinates to your dataset. Then it should work. If (2) is your problem, then you will need to decide on the resolution of your grid, the bounds of your area of interest, and resample your data to the new regularly spaced grid. Then it will work. |
For (1), this may be helpful: https://github.com/snowman2/gazar/blob/7e0317466afa96ccdd5dd214b924b9c93d8a7788/gazar/grid.py#L683-L717 |
data from the same source, just would like to save it to files. |
Hi everyone, especially @djhoese, @snowman2 and @goriliukasbuxton I am having similar problems. I use verde, from fatiando, for gridding and interpolating geospatial data. Here is my example code. Example data can be downloaded here.
The error is always
To check whether my data is over an evenly-spaced grid, I did the following checking and got these results:
My grid seems evenly spaced but for the very last decimals places. Any ideas on how to solve that, please? |
@leomiquelutti what version of |
Also, it would be interesting to see the difference in interpolation between |
Hi @snowman2,
Do you believe that the minor differences in the last decimals are responsible for that? |
Yes, please update to the latest and try it again. |
I don't believe so in this scenario. |
import geopandas
import pandas
from geocube.api.core import make_geocube
from geocube.rasterize import rasterize_points_griddata
depth_of_interest = -273.4
spacing = 5e3
filename = 'AusLAMP_MT_Gawler.xyzr'
data = pandas.read_csv(filename, delimiter=',')
data = data[data["depth_m"] == depth_of_interest]
gdf = geopandas.GeoDataFrame(
data,
geometry=geopandas.points_from_xy(data.longitude, data.latitude),
crs="EPSG:4326"
)
gdf_utm = gdf.to_crs("EPSG:32753")
geo_grid = make_geocube(
vector_data=gdf_utm,
measurements=['log10_resistivity_ohm_m'],
resolution=(-spacing, spacing),
rasterize_function=rasterize_points_griddata,
)
geo_grid.log10_resistivity_ohm_m.rio.to_raster('MT_25_verde.tif') |
|
@snowman2 thanks for the support.
Any more ideas? |
The issue you are running into is that the This works: grid.resistivity.rio.set_spatial_dims("easting", "northing", inplace=True) \
.rio.write_crs("EPSG:32753", inplace=True) \
.rio.to_raster("MT_25_verde.tif") Side note, you should probably do this to initialize >>> import pyproj
>>> projection = pyproj.Proj("EPSG:32753")
>>> projection.srs
'+proj=utm +zone=53 +south +datum=WGS84 +units=m +no_defs' |
Also, grid = grid.rename({'easting': 'x','northing': 'y'}) |
This worked! The image appeared in the right location in ArcGIS! Thanks a lot, @snowman2! I am still a beginner in Python, and would gladly appreciate some directions on the syntax you used (the slashes). A link would be very helpful, but don't bother if this requires lots of effort. I would like to understand this, to be clear.
|
Glad to hear that it worked. Here is one reference: https://stackoverflow.com/a/53180/11622836 |
@snowman2 Can you have a look at at this data: https://drive.google.com/file/d/1RoLPC6UaozsncO__qmst4sHrywN0_iyH/view?usp=sharing I want to convert a single time band to geotiff in epsg:4326 projection. Please tell me how to convert it to tiff. I am having the same error about set_spatial_dims(). I tried setting x=lon and y=lat but not succeeding. |
I believe I succeeded in converting it by changing the way I was opening the dataset: Please confirm if I did the right thing.
TRMM file is here: https://drive.google.com/file/d/1g_Nf-KKNP1psIj3q9HdQHH6396yUBDsm/view?usp=sharing |
This worked for me: xds = xarray.open_dataset("1998_01_01.nc")
xds.precipitation.squeeze().transpose(
'nlat', 'nlon'
).rio.set_spatial_dims(x_dim="nlon", y_dim="nlat").rio.to_raster("1998_01_01.tif") |
@snowman2 This worked. Thanks. |
Closing for #209 |
import rioxarray
import xarray as xr
#Sentinel-5P data
xds = xr.open_dataset(r'S5P_NRTI_L2__NO2____20190513T181819_20190513T182319_08191_01_010301_20190513T185033.nc', group="/PRODUCT")
data = xds.nitrogendioxide_tropospheric_column
data.rio.to_raster("test1.tif")
gives error: "x dimension not found. 'set_spatial_dims()' can address this." rioxarray.exceptions.DimensionError: x dimension not found. 'set_spatial_dims()' can address this.
The text was updated successfully, but these errors were encountered: