Hope you are well. I have been using Linear Baroclinic Model (Watanabe 2000) for a study and I prepared a forcing file of latent heating using xarray. The file is in of course netcdf format. However, I need to transform it to a .grd file (and corresponding .ctl file) to incorporate it into the model. Scouring the internet, I have not been able to solve this issue. I have tried ncl, cdo etc. CDO for example changes the vertical levels to pressure from sigma. I need the file to be in sigma coordinates.
I would really appreciate if someone could help me on this. Thank you.
Nazimur
International Centre for Theoretical Physics
My understanding is that the .grd file is just a binary file, and the .ctl describes the dimensions and coordinates … see this link for a simple example of converting from netcdf using the air temperature tutorial dataset shipped with xarray:
The code works perfectly for a 3-d data but i tend to run to issues converting a 4d dataset (time, level, lat, lon). The first time step displays perfectly in Grads but other time steps have a distorted longitude while the whole data have the same longitude axis. Also i’m trying to combine multiple variables into the grid file. my sample code is as below;
with open(output_grd, ‘wb’) as f:
for vr in [‘t’,‘u’]:#[‘u’,‘v’,‘t’,‘z’,‘q’,‘slp’]:
dd=data[vr].values.byteswap().astype(‘float32’)
f.write(dd)