0

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!

2 Answers 2

1

Some others might find this helpful, so here's the answer to the problem. A friend figured it out for me. "land" is the index of the flattened array nav_lat, nav_lon, i.e. the first entry of "land" corresponds to the latitude: lat.flat[land[0]] and lon.flat[land[0]].

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

1 Comment

Ah gotchya now. You can also use numpy reshape to convert that flattened 1D array to 2D to match the lat/lon arrays.
0

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.

1 Comment

Hi and thanks for your answer. I think I might not have formulated my problem properly. I know how to get lat and lon if there are variables named nav_lat and nav_lon. My problem is that in my original netcdf file, there are no variables lat and lon, but only a variable "land", which is 1D. My question is: How do I extract the information (lat, lon) from the 1D array "land"?

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.