[MITgcm-support] Read NetCDF data (Internal Waves)

Martin Losch Martin.Losch at awi.de
Wed May 11 03:55:50 EDT 2016


Hi Alejandro,

I suggest that you have a look at GRID.h, where the grid layout is nicely explained. Then there is this section:
<http://mitgcm.org/public/r2_manual/latest/online_documents/node43.html>
in the documentation which will also help in understanding the staggering of a C-grid.

With netcdf (mnc) output, you get grid.t???.nc files, don’t you? I usually use utils/python/MITgcmutils/scripts/gluemncbig to combine them into one file, but you can also use the python version of “rdmnc” (also in the utils/python/MITgcmutils directory) to read these (or any othe tiled MITgcm mnc outputfiles). Once you have done that, you’ll have coordinates pairs xC,yC for the center points and xG,yG for the corner points and all dxC/F/G, etc. to compute fluxes/derivatives. 

The mnc-output has the special feature that some of the variables, that are defined at the interfaces, (e.g. uVel, UVELMASS, vVel, VVELMASS) or at the corners (e.g. rAz, vorticity) have extra rows and/or columns to reflect the default “wrap around” periodic boundary conditions. That makes it sometimes confusing, because in the default ieee-be output (mds, which you probably don’t use), all fields have the same horizontal dimensions and you’ll have to figure out the extra rows and columns yourselves, should you need them. So for mnc output, you then have, e.g.
xC.shape => (30,40)
xG.shape => (31,41)
averaging u-velocities to central points could look like this (just the 2D fields, I am neglecting the third dimension now):
uc = 0.5*(u[:,:-1] + u[:1,:])
and for v-velocities
vc = 0.5*(v[:-1,:] + v[:1,:])

whereas for mds output it would more like this (with import numpy as np)
uc = 0.5*(u + np.roll(u,1,1))
vc = 0.5*(v + np.roll(v,1,0))

etc.

Hope that helps,

M.


> On 10 May 2016, at 16:25, Alejandro Jiménez Rico <paulexca at hotmail.com> wrote:
> 
> I am using python.
> 
> Look, I wrote this:
> 
> from matplotlib import pyplot as
>  plt
> 
> import pandas as
>  pd
> 
> import numpy as
>  np
> 
> import
>  netCDF4
> fp
> ='toread.nc'
> 
> nc 
> = netCDF4.Dataset(fp)
> print "Stationary or animated? (Say 'st' or 'a')"
> 
> q1 
> = raw_input()
> print "Filled contours or an image? (Say 'fc' or 'image')"
> 
> q2 
> = raw_input()
> print(nc['Temp'].shape)
> 
> t 
> = 1
> 
> y 
> = 0
> if q1 == 'a':
> while t< 10000:
> 
>     
> if q2 == 'image':
> 
>         plt
> .imshow(nc['Temp'][t,:,y,:])
> 
>     
> if q2 == 'fc':
> 
>         a
> =nc['Temp'][t,:,y,:]
> 
>         b
> =np.flipup(a)
> 
>         plt
> .contourf(nc['Temp'][t,:,y,:])
> 
>     plt
> .pause(.001)
> 
>     t
> =t+1
> 
>     plt
> .draw()
> if q1 == 'st':
> if q2 == 'image':
> 
>     plt
> .imshow(nc['Temp'][t,:,y,:])
> if q2 == 'fc':
> 
>     a
> =nc['Temp'][t,:,y,:]
> 
>     b
> =np.flipup(a)
> 
>     plt
> .contourf(nc['Temp'][t,:,y,:])
> 
> plt
> .show()
> But now I would like to not just looking the data, I want to touch it a bit.
> 
> I assume that you know that the position coordinates are no centralized; well, I would like to centralize it so then I will can calculate more interesting things like (for example) the kinetic energy of the fluid particles and plot it. 
> 
> How could I do it? Do that things is what - essentially - I am trying to learn about.
> 
> Again, really thank you for your help;
> Alejandro
> From: jklymak at uvic.ca
> Date: Mon, 2 May 2016 08:53:40 -0700
> To: mitgcm-support at mitgcm.org
> Subject: Re: [MITgcm-support] Read NetCDF data (Internal Waves)
> 
> What package are you using to do the analysis?  Matlab and python are the most common, and they both have excellent netcdf libraries.  
> 
> Cheers,   Jody
> 
> 
> 
> On May 2, 2016, at  2:59 AM, Alejandro Jiménez Rico <paulexca at hotmail.com> wrote:
> 
> 
> 
> From: paulexca at hotmail.com
> To: mitgcm-support at mitgcm.org
> Subject: RE: [MITgcm-support] Read NetCDF data (Internal Waves)
> Date: Mon, 2 May 2016 09:59:24 +0000
> 
> Hello Roland,
> 
> Thank you for answering me. Actually I am trying to completely understand the Internal Waves model to carry out my own simulations using it.
> 
> First of all I would like to get the full matrix data of the .nc output of this model; so I'll can read it in a different ways and more personalized than using ncview (for example, I would like to see the time evolution of velocity in a precise point of the space, like field experiments).
> 
> Moreover, I'm trying to get the scale of this model (miles, kilometers, seconds, etc.) and all the information I can find about the performance of the model.
> 
> I hope you can help me and - again - really thank you for your help.
> 
> Alejandro
> 
> From: Roland.Young at physics.ox.ac.uk
> To: mitgcm-support at mitgcm.org
> Date: Wed, 20 Apr 2016 11:30:55 +0000
> Subject: Re: [MITgcm-support] Read NetCDF data (Internal Waves)
> 
> Hi Alejandro,
> 
> I’m not entirely sure what you are trying to do; ncdump is useful for looking inside a NetCDF file but not for manipulating its contents, which is what I think you are trying to do.
> 
> If you want to view the fields themselves I suggest using ncview, which is very useful for doing this quickly. There are other programs that can read in NetCDF files for viewing, such as xconv and Panoply (the second of which is very powerful).
> 
> ncdump -c $file should print the values of all the grid variables in the .nc file, typically X, Y, Z, T for longitude, latitude, pressure/height, time. 
> 
> ncdump -h $file will just print the headers (i.e. a list of variables in the file).
> 
> ncdump -v <variable> $file will print the complete record for a single variable to the screen. For example, ncdump -v U $file will print the entire zonal velocity field in the .nc file to the screen. This is not particularly useful if you want to manipulate the data, however.
> 
> You can manipulate NetCDF files directly using the NCO library: http://nco.sourceforge.net
> 
> However, most useful for manipulating the data itself rather than just view it using ncview is an interpreter such as IDL, Matlab, or Python. Each of these have libraries to read NetCDF files, after which you can do what you like with the data.
> 
> Don’t forget that if you are running a parallel model run you will need to stitch the tiles together using gluemncbig, otherwise each .nc file only contains one tile’s worth of data.
> 
> Hope that helps,
> 
> Roland
> 
> 
> 
> 
> 
> On 20 Apr 2016, at 11:52, Alejandro Jiménez Rico <paulexca at hotmail.com> wrote:
> 
> Hello, I am trying to figure out how to read all the netcdf data using ncdump. I did $ ndump -c filetoread.nc
> 
> But I would want to organize all this data a little bit. How do I do this? I don't find information about the dimensions or the variables of this NetCDF in the mitgcm documentation.
> 
> Thank you,
> Alejandro
> _______________________________________________
> MITgcm-support mailing list
> MITgcm-support at mitgcm.org
> http://mitgcm.org/mailman/listinfo/mitgcm-support
> 
> 
> _______________________________________________ MITgcm-support mailing list MITgcm-support at mitgcm.orghttp://mitgcm.org/mailman/listinfo/mitgcm-support
> _______________________________________________
> MITgcm-support mailing list
> MITgcm-support at mitgcm.org
> http://mitgcm.org/mailman/listinfo/mitgcm-support
> 
> 
> _______________________________________________ MITgcm-support mailing list MITgcm-support at mitgcm.org http://mitgcm.org/mailman/listinfo/mitgcm-support
> _______________________________________________
> MITgcm-support mailing list
> MITgcm-support at mitgcm.org
> http://mitgcm.org/mailman/listinfo/mitgcm-support




More information about the MITgcm-support mailing list