Project

General

Profile

NetCDF file into .asc file

Added by Sean Benny over 3 years ago

Hi,

I am trying to convert my NetCDF files into ascii format to be used in MaxEnt for my dissertation.
When i use the function: cdo outputtab,name,date,lon,lat,value infile.nc

I receive the following error: cdo outputtab (Abort): Too many different grids!

Is there any way to fix this, or another way of converting my netcdf files into .asc files?

I have attached my files and the code i used below,

Thank you very much for the help.

1) remapped the files to 1 by 1 degree grid using: cdo remapbil,r360x180 infile.nc outfile.nc
2) Then calculated the mean of the file using: cdo timmean infile.nc outfile.nc
3) Then cropped the files to the Indo-Pacific region using: cdo selllonlatbox,80,170,-30 infile.nc outfile.nc

4) Lastly to convert the file into ascii: cdo outputtab,name,date,lon,lat,value infile.nc
which is when i receive the error.


Replies (6)

RE: NetCDF file into .asc file - Added by Karin Meier-Fleischer over 3 years ago

Hi Sean,

happy new year!

The input file contains variables which are depending on different lon/lat grids and different vertical levels. You can select the variable you want first and then retrieve the data in ASCII. (By the way the sellonlatbox command line is wrong).

E.g.

cdo sellonlatbox,80,170,-30,-5 PARmean.1980-2000.nc outfile.nc
cdo sinfon outfile.nc

   File format : NetCDF4 classic
    -1 : Institut Source   T Steptype Levels Num    Points Num Dtype : Parameter ID
     1 : unknown  CCSM     c instant      60   1         1   1  F32  : -1            
     2 : unknown  CCSM     c instant      60   2         1   1  F32  : -2            
     3 : unknown  CCSM     c instant       1   3     64800   2  I32  : -3            
     4 : unknown  CCSM     c instant       1   3     64800   2  I32  : -4            
     5 : unknown  CCSM     c instant       1   3     64800   2  I32  : -5            
     6 : unknown  CCSM     c instant       1   3     64800   2  F64  : -6            
     7 : unknown  CCSM     c instant       1   3     64800   2  F64  : -7            
     8 : unknown  CCSM     c instant       1   3     64800   2  F64  : -8            
     9 : unknown  CCSM     c instant       1   3     64800   2  F64  : -9            
    10 : unknown  CCSM     c instant       1   3     64800   2  F64  : -10           
    11 : unknown  CCSM     c instant       1   3     64800   2  F64  : -11           
    12 : unknown  CCSM     c instant       1   3     64800   2  F64  : -12           
    13 : unknown  CCSM     c instant       1   3     64800   2  F64  : -13           
    14 : unknown  CCSM     c instant       1   3     64800   2  F64  : -14           
    15 : unknown  CCSM     c instant       1   3     64800   2  F64  : -15           
    16 : unknown  CCSM     c instant       1   3     64800   2  F64  : -16           
    17 : unknown  CCSM     c instant       1   3     64800   2  F64  : -17           
    18 : unknown  CCSM     c instant       1   3     64800   2  F64  : -18           
    19 : unknown  CCSM     c instant       1   3     64800   2  F64  : -19           
    20 : unknown  CCSM     v instant      15   4     64800   2  F32  : -20           
   Grid coordinates :
     1 : generic                  : points=1
     2 : lonlat                   : points=64800 (360x180)
                              lon : 0 to 359 by 1 degrees_east  circular
                              lat : -89.5 to 89.5 by 1 degrees_north
   Vertical coordinates :
     1 : generic                  : levels=60
                              z_t : 500 to 537500 centimeters
     2 : generic                  : levels=60
                              z_w : 0 to 525000.9 centimeters
     3 : surface                  : levels=1
     4 : generic                  : levels=15
                         z_t_150m : 500 to 14500 by 1000 centimeters
   Time coordinate :  1 step
     RefTime =  0000-01-01 00:00:00  Units = days  Calendar = 365_day  Bounds = true
  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss
  1990-06-16 00:00:00
cdo    sinfo: Processed 20 variables over 1 timestep [0.02s 11MB].

cdo outputtab,name,date,lon,lat,value -selname,PAR_avg outfile.nc > data.asc
less data.asc

#    name       date    lon    lat    value 
 PAR_avg  1990-06-16     80  -29.5 77.44279 
 PAR_avg  1990-06-16     81  -29.5 77.48569 
 PAR_avg  1990-06-16     82  -29.5 77.57729 
 PAR_avg  1990-06-16     83  -29.5 77.63586 
 PAR_avg  1990-06-16     84  -29.5   77.772 
 PAR_avg  1990-06-16     85  -29.5 77.95641 
 PAR_avg  1990-06-16     86  -29.5 78.08635 
 PAR_avg  1990-06-16     87  -29.5 78.19922 
 PAR_avg  1990-06-16     88  -29.5 78.35629 
 PAR_avg  1990-06-16     89  -29.5 78.49512 
 PAR_avg  1990-06-16     90  -29.5 78.57363 
 PAR_avg  1990-06-16     91  -29.5 78.65914 
 PAR_avg  1990-06-16     92  -29.5 78.69856 
 PAR_avg  1990-06-16     93  -29.5 78.62453 
 PAR_avg  1990-06-16     94  -29.5 78.47848 
 PAR_avg  1990-06-16     95  -29.5 78.31543 
 PAR_avg  1990-06-16     96  -29.5 78.13854 
 PAR_avg  1990-06-16     97  -29.5 77.90493 
 PAR_avg  1990-06-16     98  -29.5 77.59462 
 PAR_avg  1990-06-16     99  -29.5 77.28925 
 PAR_avg  1990-06-16    100  -29.5  77.0677 
 PAR_avg  1990-06-16    101  -29.5 76.60764 
 PAR_avg  1990-06-16    102  -29.5 76.12521 
 PAR_avg  1990-06-16    103  -29.5 75.59827 
 PAR_avg  1990-06-16    104  -29.5 74.98427 
 PAR_avg  1990-06-16    105  -29.5 74.37739 
 PAR_avg  1990-06-16    106  -29.5 73.93988 
 PAR_avg  1990-06-16    107  -29.5 73.78814 
 PAR_avg  1990-06-16    108  -29.5 74.02541 
 PAR_avg  1990-06-16    109  -29.5 74.78417 
 PAR_avg  1990-06-16    110  -29.5 76.08097 
 PAR_avg  1990-06-16    111  -29.5 78.14844 
 PAR_avg  1990-06-16    112  -29.5 80.55319 
 PAR_avg  1990-06-16    113  -29.5 82.55566 
 PAR_avg  1990-06-16    114  -29.5 84.39691 
 PAR_avg  1990-06-16    115  -29.5 9.96921e+36 
...

-Karin

RE: NetCDF file into .asc file - Added by Sean Benny over 3 years ago

Hi Karin,

Happy new year thank you so much for help!

Is there a way to only collect data from the first 20m underwater from the PAR file as i am doing a species distribution model for coral reefs on MaxEnt?

Thank you

RE: NetCDF file into .asc file - Added by Karin Meier-Fleischer over 3 years ago

You can use the operator lec to create a mask.

Select the variable and the sub-region:

cdo -sellonlatbox,80,170,-30,-5 -selname,PAR_avg PARmean.1980-2000.nc data.nc

Create the mask to get only values less than 20:

cdo -lec,20 data.nc tmp.nc

Retrieve only values less than 20:

cdo -ifthen tmp.nc data.nc data_le_20.nc

Write data to ASCII file:

cdo -outputtab,name,date,lon,lat,value data_le_20.nc > data_le_20.asc

RE: NetCDF file into .asc file - Added by Sean Benny over 3 years ago

Thank you very much for all the help Karin :)

RE: NetCDF file into .asc file - Added by Sean Benny over 3 years ago

Hi Karin,

I have another error with my files.

Whenever i try and merge my two files together using: cdo mergetime PAR_avg.192001-200512.nc PAR_avg.200601-208012.nc PAR_avg.1920-2080.nc

I get the error message: mergetime (Abort): Grid size of the input parameter ANGLE do not match!

I have tried remapping them both using remapbil,r360x180 and then merging them but still get the same error.

Also, if i were to only collect data from the first 20m below sea level, would i use the same code as described above for the bathymetry file?

Thanks so much for help

I am not able to attach the files below as they are too large so i'll give the information that is given from cdo sinfon:

PARavg.192001-200512.nc:
Warning (cdfCheckVars): Unsupported data type (char/string), skipped variable moc_components!
Warning (cdfCheckVars): Unsupported data type (char/string), skipped variable transport_components!
Warning (cdfCheckVars): Unsupported data type (char/string), skipped variable transport_regions!
Warning (cdfInqContents): Coordinates variable z_t_150m can't be assigned!
File format : NetCDF4 zip
-1 : Institut Source T Steptype Levels Num Points Num Dtype : Parameter name
1 : unknown CCSM c instant 1 1 122880 1 F64z : ANGLE
2 : unknown CCSM c instant 1 1 122880 2 F64z : ANGLET
3 : unknown CCSM c instant 1 1 122880 2 F64z : DXT
4 : unknown CCSM c instant 1 1 122880 1 F64z : DXU
5 : unknown CCSM c instant 1 1 122880 2 F64z : DYT
6 : unknown CCSM c instant 1 1 122880 1 F64z : DYU
7 : unknown CCSM c instant 1 1 122880 2 F64z : HT
8 : unknown CCSM c instant 1 1 122880 2 F64z : HTE
9 : unknown CCSM c instant 1 1 122880 2 F64z : HTN
10 : unknown CCSM c instant 1 1 122880 1 F64z : HU
11 : unknown CCSM c instant 1 1 122880 1 F64z : HUS
12 : unknown CCSM c instant 1 1 122880 1 F64z : HUW
13 : unknown CCSM c instant 1 1 122880 2 I32z : KMT
14 : unknown CCSM c instant 1 1 122880 1 I32z : KMU
15 : unknown CCSM v instant 15 2 122880 2 F32z : PAR_avg
16 : unknown CCSM c instant 1 1 122880 2 I32z : REGION_MASK
17 : unknown CCSM c instant 1 1 122880 2 F64z : TAREA
18 : unknown CCSM c instant 1 1 122880 1 F64z : UAREA
19 : unknown CCSM c instant 60 3 1 3 F32z : dz
20 : unknown CCSM c instant 60 4 1 3 F32z : dzw
Grid coordinates :
1 : curvilinear : points=122880 (320x384)
ULONG : 0.007270741 to 359.9962 degrees_east circular
ULAT : -78.9529 to 89.97734 degrees_north
2 : curvilinear : points=122880 (320x384)
TLONG : 0.0147311 to 359.996 degrees_east circular
TLAT : -79.22052 to 89.70641 degrees_north
3 : generic : points=1
Vertical coordinates :
1 : surface : levels=1
2 : generic : levels=15
z_t_150m : 500 to 14500 by 1000 centimeters
3 : generic : levels=60
z_t : 500 to 537500 centimeters
4 : generic : levels=60
z_w : 0 to 525000.9 centimeters
Time coordinate : 1032 steps
RefTime = 0000-01-01 00:00:00 Units = days Calendar = 365_day Bounds = true
YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss
1920-02-01 00:00:00 1920-03-01 00:00:00 1920-04-01 00:00:00 1920-05-01 00:00:00
1920-06-01 00:00:00 1920-07-01 00:00:00 1920-08-01 00:00:00 1920-09-01 00:00:00
1920-10-01 00:00:00 1920-11-01 00:00:00 1920-12-01 00:00:00 1921-01-01 00:00:00
1921-02-01 00:00:00 1921-03-01 00:00:00 1921-04-01 00:00:00 1921-05-01 00:00:00
1921-06-01 00:00:00 1921-07-01 00:00:00 1921-08-01 00:00:00 1921-09-01 00:00:00
1921-10-01 00:00:00 1921-11-01 00:00:00 1921-12-01 00:00:00 1922-01-01 00:00:00
................................................................................
................................................................................
.
2005-06-01 00:00:00 2005-07-01 00:00:00 2005-08-01 00:00:00 2005-09-01 00:00:00
2005-10-01 00:00:00 2005-11-01 00:00:00 2005-12-01 00:00:00 2006-01-01 00:00:00
cdo sinfon: Processed 20 variables over 1032 timesteps [0.56s 41MB].

and for PAR_avg.200601-208012.nc:

Warning (cdfCheckVars): Unsupported data type (char/string), skipped variable moc_components!
Warning (cdfCheckVars): Unsupported data type (char/string), skipped variable transport_components!
Warning (cdfCheckVars): Unsupported data type (char/string), skipped variable transport_regions!
Warning (cdfInqContents): Coordinates variable z_t_150m can't be assigned!
File format : NetCDF4 classic zip
-1 : Institut Source T Steptype Levels Num Points Num Dtype : Parameter name
1 : unknown CCSM c instant 60 1 1 1 F32z : dz
2 : unknown CCSM c instant 60 2 1 1 F32z : dzw
3 : unknown CCSM c instant 1 3 122880 2 I32z : KMT
4 : unknown CCSM c instant 1 3 122880 3 I32z : KMU
5 : unknown CCSM c instant 1 3 122880 2 I32z : REGION_MASK
6 : unknown CCSM c instant 1 3 122880 3 F64z : UAREA
7 : unknown CCSM c instant 1 3 122880 2 F64z : TAREA
8 : unknown CCSM c instant 1 3 122880 3 F64z : HU
9 : unknown CCSM c instant 1 3 122880 2 F64z : HT
10 : unknown CCSM c instant 1 3 122880 3 F64z : DXU
11 : unknown CCSM c instant 1 3 122880 3 F64z : DYU
12 : unknown CCSM c instant 1 3 122880 2 F64z : DXT
13 : unknown CCSM c instant 1 3 122880 2 F64z : DYT
14 : unknown CCSM c instant 1 3 122880 2 F64z : HTN
15 : unknown CCSM c instant 1 3 122880 2 F64z : HTE
16 : unknown CCSM c instant 1 3 122880 3 F64z : HUS
17 : unknown CCSM c instant 1 3 122880 3 F64z : HUW
18 : unknown CCSM c instant 1 3 122880 3 F64z : ANGLE
19 : unknown CCSM c instant 1 3 122880 2 F64z : ANGLET
20 : unknown CCSM v instant 15 4 122880 2 F32z : PAR_avg
Grid coordinates :
1 : generic : points=1
2 : curvilinear : points=122880 (320x384)
TLONG : 0.0147311 to 359.996 degrees_east circular
TLAT : -79.22052 to 89.70641 degrees_north
3 : curvilinear : points=122880 (320x384)
ULONG : 0.007270741 to 359.9962 degrees_east circular
ULAT : -78.9529 to 89.97734 degrees_north
Vertical coordinates :
1 : generic : levels=60
z_t : 500 to 537500 centimeters
2 : generic : levels=60
z_w : 0 to 525000.9 centimeters
3 : surface : levels=1
4 : generic : levels=15
z_t_150m : 500 to 14500 by 1000 centimeters
Time coordinate : 900 steps
RefTime = 0000-01-01 00:00:00 Units = days Calendar = 365_day Bounds = true
YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss
2006-02-01 00:00:00 2006-03-01 00:00:00 2006-04-01 00:00:00 2006-05-01 00:00:00
2006-06-01 00:00:00 2006-07-01 00:00:00 2006-08-01 00:00:00 2006-09-01 00:00:00
2006-10-01 00:00:00 2006-11-01 00:00:00 2006-12-01 00:00:00 2007-01-01 00:00:00
2007-02-01 00:00:00 2007-03-01 00:00:00 2007-04-01 00:00:00 2007-05-01 00:00:00
................................................................................
......................................................................
2080-06-01 00:00:00 2080-07-01 00:00:00 2080-08-01 00:00:00 2080-09-01 00:00:00
2080-10-01 00:00:00 2080-11-01 00:00:00 2080-12-01 00:00:00 2081-01-01 00:00:00
cdo sinfon: Processed 20 variables over 900 timesteps [0.79s 38MB].

RE: NetCDF file into .asc file - Added by Karin Meier-Fleischer over 3 years ago

Well, that's a problem because your files don't have the same structure.

CDO doc about mergetime operator says:

Merges all timesteps of all input files sorted by date and time. 
All input files need to have the same structure with the same variables on different timesteps.
After this operation every input timestep is in outfile and all timesteps are sorted by date and time.

The variable ANGLE for example depends on grid number 1 in the first file but it depends on grid number 3 in the second file. All files should have been created the same way.

PARavg.192001-200512.nc:

1 : unknown CCSM c instant 1 1 122880 1 F64z : ANGLE

PAR_avg.200601-208012.nc:

18 : unknown CCSM c instant 1 3 122880 3 F64z : ANGLE

Q: Also, if i were to only collect data from the first 20m below sea level, would i use the same code as described above for the bathymetry file?

Yes, why not? It is the same kind of selection if the variable has values from 0 to +???. Have a look at your data values first. If you have negative values you have to use the operator gec instead (see CDO docs).

    (1-6/6)