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
using cog_translate
on netCDF4 with improper georeferencing
#74
Comments
@ryanjdillon can you try |
Excellent. I'll report back as soon as I've tried that out. Thanks!
Den fre. 5. apr. 2019, 16:18 skrev Vincent Sarago <notifications@github.com
…:
@ryanjdillon <https://github.com/ryanjdillon> can you try transform
instead of src_transform ?
https://github.com/cogeotiff/rio-cogeo/blob/webOpt/rio_cogeo/cogeo.py#L141
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#74 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA39Gv8T72PKy_nfaR93XtF17TUwujv0ks5vd1slgaJpZM4ce6K0>
.
|
@ryanjdillon did it fix the problem ? |
I was just about to report back. That didn't seem to fix things unfortunately. It looks like vrt_params = dict(
src_transform=nc_affine, src_crs=crs,
transform=nc_affine, crs=crs,
)
cogeo.cog_translate(
src_path=band_fp,
dst_path=dst_fp,
dst_kwargs=config.GDAL_TRANSLATE_PROFILE,
vrt_params=vrt_params,
indexes=[i,],
overview_resampling='nearest',
config=config.GDAL_CONFIG
) Which yields the same error. If I pass
And that seems to be related to the output file not existing. It sounded as though this could have been due to the slightly outdated Debian packages I'm using, so I compiled everything from source, which didn't do anything for me. gdalinfo --version
nc-config --all
|
I've tried to use However, gdalwarp -s_srs EPSG:4326 -t_srs EPSG:4326 -of GTIFF 'NETCDF:"c_gls_NDVI_201808110000_GLOBE_PROBAV_V2.2.1.nc":NDVI' ./test.tiff Whereas my NetCDF file lacking georeferencing throws the same error with |
@ryanjdillon so if I understand correctly this might be a Rasterio Error and not specific with rio-cogeo. Can you check if you are at least able to read the dataset with a simple rasterio code ? |
It seems like it is a bit of a combo. I got it to work when I opened the subdataset with a It was also necessary to pass I also tried using I could submit a PR if you want to look over / incorporate these changes. |
🤔 thanks @ryanjdillon,
Can you checkout what https://svn.osgeo.org/gdal/trunk/gdal/swig/python/samples/validate_cloud_optimized_geotiff.py gives you ?
Allowing I'm no expert with netCDF so I'm may be missing some knowledge here |
I'll take a look at that as soon as possible. Once I have a clear handle on things I can contribute an example to the docs or something. |
I managed to get things to work by first converting the NetCDF to GeoTIFF using GDAL, and then doing the COG conversion with I first created a VRT file with The resulting COG produced by |
@ryanjdillon Long time no see 😄
def translate(
src_path,
cog_path,
cogeo_profile="deflate",
cogeo_options={"blockxsize": 128, "blockysize": 128, "predictor": 2, "zlevel": 7},
):
"""Convert a netcdf to COG."""
config = dict(GDAL_NUM_THREADS="ALL_CPUS", GDAL_TIFF_OVR_BLOCKSIZE="128")
with rasterio.Env(**config):
with rasterio.open(src_path) as src_dst:
with WarpedVRT(
src_dst,
crs="epsg:4326",
warp_mem_limit=0.1, # Reduce chunk size, see: https://github.com/OSGeo/gdal/issues/1989
num_threads=8
) as vrt:
profile = cog_profiles.get(cogeo_profile)
profile.update(cogeo_options)
cog_translate(
vrt,
cog_path,
profile,
config=config,
in_memory=True,
quiet=True,
)
def translate(
src_path,
cog_path,
cogeo_profile="deflate",
cogeo_options={"blockxsize": 128, "blockysize": 128, "predictor": 2, "zlevel": 7},
):
"""Convert a netcdf to COG."""
config = dict(GDAL_NUM_THREADS="ALL_CPUS", GDAL_TIFF_OVR_BLOCKSIZE="128")
with rasterio.Env(**config):
with rasterio.open(src_path) as src_dst:
dst_transform, dst_width, dst_height = calculate_default_transform(
src_dst.crs, "epsg:4326", src_dst.width, src_dst.height, *src_dst.bounds
)
meta = dict(
driver="GTiff",
dtype=src_dst.dtypes[0],
count=src_dst.count,
height=dst_height,
width=dst_width,
crs="epsg:4326",
transform=dst_transform,
nodata=-999,
tiled=True,
compress="deflate",
blockxsize=256,
blockysize=256,
)
with MemoryFile() as memfile:
with memfile.open(**meta) as mem:
reproject(
rasterio.band(src_dst, 1),
rasterio.band(mem, 1),
resampling=rasterio.enums.Resampling.nearest,
warp_mem_limit=1, # Reduce chunk size, see: https://github.com/OSGeo/gdal/issues/1989
num_threads=8,
)
mem.update_tags(**src_dst.tags(1))
profile = cog_profiles.get(cogeo_profile)
profile.update(cogeo_options)
cog_translate(
mem,
cog_path,
profile,
config=config,
in_memory=True,
quiet=True,
) since we can use MemoryFile or VRT, we can now fix the data upfront and pass it to |
Excellent. Thanks for the ping. |
I am trying to use
cog_translate
to convert some netCDF4 datasets to COG, and it appears these files do not have proper georeferencing.I have modified
cogeo.py
to acceptvrt_params
, so that I can manually pass thesrc_crs
andsrc_transform
via theWarpedVRTReaderBase
mixin ofWarpedVRT
, as you can see here:https://github.com/ryanjdillon/rio-cogeo/blob/cog_translate_vrt_params/rio_cogeo/cogeo.py#L87-L99
Then I'm passing the following
vrt_params
:This get's me past the CRS is None error, but it doesn't seem to acknowledge the Affine transform I pass to
src_transform
, resulting in the following error:Any suggestions on how I might get this to work?
The text was updated successfully, but these errors were encountered: