0

My question is simple.
With an wrfout file "out.nc" for example.
The file contain Geo2D, Geo3D and 1D variables.

Using GDAL package in Python 2.7, I can extract the Geo2D variables easily like this:

## T2 is 2-d variable means temperature 2 m above the ground
temp = gdal.Open('NETCDF:"'+"out.nc"+'":T2')          

But when I want to use this code to extract 1d array, it failed.

## Time is 1-d array represent the timeseries throught the simulation period
time = gdal.Open('NETCDF:"'+"out.nc"+'":Time')       

Nothing happened! Wish some one offer some advice to read any-dimension of WRF output variables easyily!

1
  • 1
    Have You tried using python-netcdf4 instead of gdal? Commented Mar 27, 2016 at 17:54

1 Answer 1

3

You can also use the NetCDF reader in scipy.io:

import scipy.io.netcdf as nc

# Open a netcdf file object and assign the data values to a variable
time = nc.netcdf_file('out.nc', 'r').variables['Time'][:]

It has the benefit of scipy being a very popular and widely installed package, while working similar to opening files in some respects.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your reply. I'll try!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.