Project

General

Profile

Unable to transform ASC fill to netcdf

Added by Mark jwaideh 11 months ago

Struggling to understand why my ASC file will not transform to NETCDF. The code is part of a larger code file (attached) within a loop to transform lots of ASC files to NETCDF.

Even when I try to simplify the code to:

cdo -f nc -input,grid.txt < conv_rangeland1500AD.asc out.nc

it still states " Too few input elements (9331199 of 9331200)!"

I would very much appreciate any support - very much a novice to this!

grid.txt (329 Bytes) grid.txt grid file
step2_hyde_convert.sh (2.7 KB) step2_hyde_convert.sh script to convert multiple ASC files to NetCDF from particular folder directories
conv_rangeland1500AD.asc (52.2 MB) conv_rangeland1500AD.asc example input .ASC

Replies (9)

RE: Unable to transform ASC fill to netcdf - Added by Estanislao Gavilan 11 months ago

Hi Mark,

I think the order is not corret. Try this

cdo -f nc -input,grid.txt out.nc < conv_rangeland1500AD.asc

Kind regards,

Estanislao

RE: Unable to transform ASC fill to netcdf - Added by Mark jwaideh 11 months ago

Thank you Estanisiao,

Still comes up with the following error. The first error is removed when run in the full script but the second error (related to too few inputs) remains>>

cdo -f nc -input,grid.txt out.nc < conv_rangeland1500AD.asc
cdo input: Enter all 9331200 elements of timestep 1!

cdo input (Abort): Too few input elements (9331199 of 9331200)!

RE: Unable to transform ASC fill to netcdf - Added by Estanislao Gavilan 11 months ago

Hi,

I cannot test the script enterily, but I can tell that this line works fine.

cdo --history -m -9999 -f nc4c -z zip -setmissval,1E+20 -invertlatdata -setunit,km^2 -input,grid.txt out.nc < conv_rangeland1500AD.asc

If you cannot run the same line, it could be an issue of your cdo version. Which cdo are you using?

Kind regards,

Estanislao

PS: I attach you the output

out.nc (1.66 MB) out.nc

RE: Unable to transform ASC fill to netcdf - Added by Mark jwaideh 11 months ago

Thank You Estanislao,

This code didn't work for me, so must be something wrong with my setup.

I am using CDO - 1.9.8 on Ubuntu 22.04.2 on a Windows platform via visual studio code. I had tried using the latest CDO version but caused the same issue. Could you let me know what the correct setup would be on Windows to run this code.

Thank you for your support.

Best,

Mark J

RE: Unable to transform ASC fill to netcdf - Added by Estanislao Gavilan 11 months ago

Hi Mark,

Windows is alwys difficult. I have not tried via vidual studio. If you are working with windows, I recommend to set a virtual machine with linux via WSL 2 or virtual box. You can then install cdo via conda, apt install or source. Let me know if you still having problems.

Kind regards,

Estanislao

RE: Unable to transform ASC fill to netcdf - Added by Karin Meier-Fleischer 11 months ago

Hi Mark,

short and easy answer is that the ASCII data file is wrong, it contains header lines.

Your conv_rangeland1500AD.asc:

ncols 4320
nrows 2160
xllcorner -180
yllcorner -90
cellsize 0.0833333
NODATA_value -9999
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 ...

The data file has to have no header lines. Delete the first 6 lines and it works.

RE: Unable to transform ASC fill to netcdf - Added by Estanislao Gavilan 11 months ago

Hi Karin,

how comes I did not get any error using those files?

Kind regards

Estanislao

RE: Unable to transform ASC fill to netcdf - Added by Karin Meier-Fleischer 11 months ago

Thanks Estanislao, of course it is the ASCII data file that contains the header lines. I corrected the above answer from me.

But, good to talk about it because the grid.txt file is also incorrect. The xsize and the ysize has to be switched, xsize stands for number of columns and ysize stands for the number of lines.

#
  1. gridID 1 #
    gridtype = lonlat
    gridsize = 9331200
    xname = lon
    xlongname = longitude
    xunits = degrees_east
    yname = lat
    ylongname = latitude
    yunits = degrees_north
    ysize = 2160
    xsize = 4320
    xfirst = -179.9583333333333
    xinc = 0.083333333333
    yfirst = -89.9583333333333
    yinc = 0.083333333333

@Estanislao: you must get an error because the number of lines 2166 in the ASCII data file does not match the given ysize value 2160. See https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf#subsection.2.14.4. So you need to delete the header lines first.

RE: Unable to transform ASC fill to netcdf - Added by Estanislao Gavilan 11 months ago

Hi Karin,

thanks you so much for the explanation. It turns out that cdo version 2.0.4 detects the error, but the 1.9.0 it does not. It seems there was a bugged in the old version.

    (1-9/9)