Convert netcdf "land" variable to latitude and longitude with Python
Question: I have a global meteorological dataset and I want to access the data for a
certain grid (lat,lon). However, the data is compressed, i.e. the parameters
of interest do not have the dimensions (lat, lon), but "land". "land" is a 1D
array of integers.

I imported the file in python using

`import scipy.io.netcdf as netcdf`

`path = '/path/.../ncfile.nc'`

`ncfile = netcdf.netcdf_file(path,'r')`

Then I checked what variables there were and found that, e.g. the "Rainf"
variable has the dimensions (tstep, land). I researched this on the internet
and found the file landmask_gswp.nc
(<http://dods.ipsl.jussieu.fr/gswp/Fixed/landmask_gswp.nc>), which is supposed
to contain the information I need, that is, how to extract the information
(lat, lon) from "land". This file contains the variables nav_lat, nav_lon and
landmask. nav_lat and nav_lon relate, to my understanding, the coordinate
variables x and y to latitude and longitude. "landmask" is a 2D array and
contains the information ocean = 0 or land = 1. Indeed, the number of
landpoints agrees with the length of my "land" 1D array. However, I cannot
figure out how to extract the (lat, lon) information from it. Any help would
be much appreciated.

I hope I made my problem somewhat understandable; I am not experienced with
programming and/or using netcdf, so I hope that you can help out! Thanks in
advance!


Answer: You can extract variables from `ncfile` using

    
    
    lat = ncfile.variables['nav_lat'][:,:]
    lon = ncfile.variables['nav_lon'][:,:] 
    

This will create 2D numpy arrays `lat` and `lon`.

