<div dir="ltr">Thanks Even! That makes sense. <div><br></div><div>One quibble though, using the netcdf way gives order "Z, y, x", but for Zarr "y, x, Z", is that expected? I can reorder with another step, I can't see see a relevant creation option. </div><div><br></div><div>gdal_translate Rlogo.png <a href="http://out.nc">out.nc</a> -mo NETCDF_DIM_EXTRA="{Z}" -mo NETCDF_DIM_Z_DEF="{4,4}" -mo NETCDF_DIM_Z_VALUES="{0,1,2,3}" -mo "Z#axis=Z" -co FORMAT=NC4<br>Input file size is 100, 76<br><br> "Band1": {<br> "datatype": "Byte",<br> "dimensions": [<br> "/Z",<br> "/y",<br> "/x"<br> ],<br> "dimension_size": [<br> 4,<br> 76,<br> 100<br> ],<br><br><br>gdal_translate Rlogo.png out.zarr -of ZARR<br>Input file size is 100, 76<br> "out": {<br> "datatype": "Byte",<br> "dimensions": [<br> "/Y",<br> "/X",<br> "/Band"<br> ],<br> "dimension_size": [<br> 76,<br> 100,<br> 4<br> ],<br></div><div><br></div><div><br></div><div><br></div><div>Cheers, Mike</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 15, 2024 at 12:53 AM Even Rouault <<a href="mailto:even.rouault@spatialys.com">even.rouault@spatialys.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>
<div>
<p>Michael,</p>
<p>fixed per <a href="https://github.com/OSGeo/gdal/pull/11005" target="_blank">https://github.com/OSGeo/gdal/pull/11005</a></p>
<p>Otherwise just do "gdal_translate Rlogo.png Rlogo.zarr -of Zarr"
. By default the Zarr driver translates GDAL bands as the Z
dimension, unless you specify the SINGLE_ARRAY=NO creation option,
in which case it will create a Zarr array per band (so a different
default as the netCDF driver).<br>
</p>
<p>Even<br>
</p>
<div>Le 14/10/2024 à 14:10, Michael Sumner
via gdal-dev a écrit :<br>
</div>
<blockquote type="cite">
<div dir="ltr">Possibly this is a fool's errand ...
<div><br>
</div>
<div>I want to be able to cast an RGBA file as a Zarr, so first
to cast as multidim I tried the CreateCopy route with NetCDF
and I see dimension "x" repeated, with "y" missing. (I'm using
an external file as the existing test PNG files are square in
shape).
<div><br>
</div>
<div>from osgeo import gdal<br>
<br>
## PNG source is 100x76 * 4 bands<br>
f = "/vsicurl/<a href="https://github.com/cran/png/blob/master/inst/img/Rlogo.png?raw=true" target="_blank">https://github.com/cran/png/blob/master/inst/img/Rlogo.png?raw=true</a>"<br>
src_ds = gdal.Open(f)<br>
<br>
## set NetCDF metadata to make Bands 0,1,2,3 a Z dimension<br>
size_z = 4<br>
src_ds.SetMetadataItem('NETCDF_DIM_EXTRA', '{Z}')<br>
src_ds.SetMetadataItem('NETCDF_DIM_Z_DEF',
f"{{{size_z},4}}")<br>
src_ds.SetMetadataItem('NETCDF_DIM_Z_VALUES', '{1.25,2.50}')<br>
src_ds.SetMetadataItem('Z#axis', 'Z')<br>
<br>
# Create netCDF file<br>
gdal.GetDriverByName('netCDF').CreateCopy('<a href="http://out.nc" target="_blank">out.nc</a>',
src_ds)<br>
<br>
## investigate shape as a mdim<br>
ds = gdal.OpenEx("<a href="http://out.nc" target="_blank">out.nc</a>",
gdal.OF_MULTIDIM_RASTER)<br>
rootGroup = ds.GetRootGroup()<br>
var = rootGroup.OpenMDArray("Band1")<br>
<br>
## we ended up with x,x,Z <br>
[dim.GetSize() for dim in var.GetDimensions()]<br>
#[4, 100, 100]<br>
<br>
<div><br>
</div>
<div>That looks like a bug?</div>
<div><br>
</div>
<div>And, is there a better way to go about this?
PNG->ZARR is my target, I'm fine with programmatic
creation of NetCDF, but this could be quite handy as a
two-step conversion from pseudo-3D to actual 3D via the
cli with "gdal_translate -mo ...". (This is not for real
work fwiw, just for me programming at the edges of Zarr,
with examples that are clear in visual terms). </div>
<div><br>
</div>
<div>Cheers, Mike</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<span class="gmail_signature_prefix">-- </span><br>
<div dir="ltr" class="gmail_signature">
<div dir="ltr">Michael Sumner<br>
Research Software Engineer<br>
Australian Antarctic Division<br>
Hobart, Australia<br>
e-mail: <a href="mailto:mdsumner@gmail.com" target="_blank">mdsumner@gmail.com</a></div>
</div>
</div>
</div>
</div>
<br>
<fieldset></fieldset>
<pre>_______________________________________________
gdal-dev mailing list
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a>
</pre>
</blockquote>
<pre cols="72">--
<a href="http://www.spatialys.com" target="_blank">http://www.spatialys.com</a>
My software is free, but my time generally not.
Mostly a fool, sometimes acting like a professional (or vice versa)</pre>
</div>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr">Michael Sumner<br>Research Software Engineer<br>Australian Antarctic Division<br>Hobart, Australia<br>e-mail: <a href="mailto:mdsumner@gmail.com" target="_blank">mdsumner@gmail.com</a></div></div>