2

I want to extract time series from a variable in a 3D (lon,lat,time) netcdf file at specific lon/lat points. The raster is a nc file where:

cell: ×ばつ1.5°
time step: 1 month
lat extension: (0.75,89.25,1.5)
lon extension: (0.75,359.25,1.5)
time: (201001,205012)
step scale: cell center 

I have a point shapefile (lat/lon) where a point is (108.3°,58.6°). I just want to extract the cell values of the whole time steps in where points located. Are there directly method to carry out it?

I think a way that round the points number according to lat/lon step: changing the P lat/long to cell lat/lon where point located. For instance, P(108.3°, 58.6°) is in cell (108°,60°) because scale step is 1.5°. Now, the question is how to change P(108.3°,58.6°) to cell(108°,60°) used to slice .nc file.

Rich Signell
2,2821 gold badge19 silver badges28 bronze badges
asked Jan 19, 2017 at 11:21

1 Answer 1

9

So you have 3D data (lon,lat,time) in a netcdf file and you want to extract a time-series as a specific location in Python, right?

Here's one way using netCDF4: http://nbviewer.jupyter.org/gist/rsignell-usgs/4113653

But it's way easier using Xarray: http://nbviewer.jupyter.org/gist/rsignell-usgs/e032db75e748cf5922d38d8be9e0ecef

import xarray as xr
fname = 'http://thredds.ucar.edu/thredds/dodsC/grib/NCEP/GFS/Global_onedeg/Best' # Remote OPeNDAP Dataset 
#fname = 'my_raster_time_series_data.nc' # Local NetCDF file
ds = xr.open_dataset(fname)
dsloc = ds.sel(lon=230.5,lat=55.0,method='nearest')
dsloc['Wind_speed_gust_surface'].plot();

enter image description here

answered Jan 20, 2017 at 12:26
1
  • The easiest way to install xarray is with the free Anaconda python distribution. After installing Anaconda, just type conda install -c conda-forge xarray Commented Jan 20, 2017 at 12:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.