comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Finding pixel values of NETCDF image based on lat/lon
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Finding pixel values of NETCDF image based on lat/lon [message #89066] Mon, 21 July 2014 20:46 Go to next message
Marta Yebra is currently offline  Marta Yebra
Messages: 16
Registered: August 2012
Junior Member
Hi all,

I am just introducing myself to NETCDF format and I have been able to read and access the data but Now I need to extract a time-serie of the values for a point location (lat/lon) and I do not know how to do it.


This is my piece of bad coding :):

filename='C:\UserData\yebram\GPP\2014516145028EnsembleGPP_GL .nc'
file_sites='C:\UserData\yebram\GPP\Sites_locations.csv'

;1. Open the file and assign it a file ID

NCDF_Id = ncdf_open(filename)

;When you are completely through with the file you should close it using the ncdf_close, fileID command.

;2. Find the number of file attributes and datasets (or variables). The information will be contained in the structure variable that we have named 'fileinq_struct',
;but you may give it any name you wish so long as you use the proper record names.

fileinq_struct=ncdf_inquire(NCDF_Id)

Ndims=fileinq_struct.Ndims ;The number of dimensions defined for this NetCDF file.
nvars = fileinq_struct.nvars ;The number of variables defined for this NetCDF file.
ngatts = fileinq_struct.ngatts ;The number of global attributes defined for this NetCDF file
RecDim=fileinq_struct.RecDim; The ID of the unlimited dimension, if there is one, for this NetCDF file. If there is no unlimited dimension, RecDim is set to -1.

; retrieve GPP data
; units = "kg m-2 s-1";
; _FillValue = -9999.0f; // float
; float gpp(time=360, lat=360, lon=720);
nameGPP='gpp'
NCDF_VARID_GPP = NCDF_VARID(NCDF_Id, nameGPP)
NCDF_VARGET, NCDF_Id, NCDF_VARID_GPP, GPP
GPP[where(GPP eq -9999)] = !VALUES.F_NAN

; retrieve long data
; units = "degrees_east";
nameLon='lon'
NCDF_VARID_lon = NCDF_VARID(NCDF_Id, nameLon)
NCDF_VARGET, NCDF_Id, NCDF_VARID_lon, Lon
Lon[where(Lon eq -9999)] = !VALUES.F_NAN

; retrieve lat data
; units = "degrees_north";
nameLat='lat'
NCDF_VARID_lat = NCDF_VARID(NCDF_Id, nameLat)
NCDF_VARGET, NCDF_Id, NCDF_VARID_lat, lat
lat[where(lat eq -9999)] = !VALUES.F_NAN

; retrieve time data
; units = "days since 1582-10-14 00:00:00";
; calendar = "standard";

nameTime='time'
NCDF_VARID_Time = NCDF_VARID(NCDF_Id, nameTime)
NCDF_VARGET, NCDF_Id, NCDF_VARID_Time, Time
Time[where(Time eq -9999)] = !VALUES.F_NAN

;open file with coordinates for teh sites

my_data=read_csvok(file_sites)

sites=my_data.Name_site
Lat_sites=my_data.Lat
Lon_sites=my_data.Lon

find_lon=where(Lon EQ Lon_sites, countlon)
find_lat=where(Lat EQ Lat_sites, countLat)

but this cannot find anything since my coordinate is for example 41.160000 and that value is not in the NETCDF.

How can I select the pixel that contains my point?

Your help is very much appreciate.

Kind regards,

Marta
Re: Finding pixel values of NETCDF image based on lat/lon [message #89068 is a reply to message #89066] Tue, 22 July 2014 00:37 Go to previous messageGo to next message
Fabzi is currently offline  Fabzi
Messages: 305
Registered: July 2010
Senior Member
Hi,

On 22.07.2014 05:46, Marta Yebra wrote:
> I need to extract a time-serie of the values for a point location (lat/lon)

This is not a netcdf specific problem. You might want to look at:

https://www.idlcoyote.com/map_tips/latlon2pixel.php

Cheers,

Fab
Re: Finding pixel values of NETCDF image based on lat/lon [message #89077 is a reply to message #89066] Tue, 22 July 2014 23:04 Go to previous messageGo to next message
Marta Yebra is currently offline  Marta Yebra
Messages: 16
Registered: August 2012
Junior Member
Thanks Fabian but the example from David Fanning is for GEOTIFF imagen (for example cggeomap). Do I need to convert the NETCDF to GEOTIFF? If yes, can you let mek now how can I do it?
Re: Finding pixel values of NETCDF image based on lat/lon [message #89078 is a reply to message #89077] Tue, 22 July 2014 23:44 Go to previous message
Fabzi is currently offline  Fabzi
Messages: 305
Registered: July 2010
Senior Member
On 23.07.2014 08:04, Marta Yebra wrote:
> Do I need to convert the NETCDF to GEOTIFF?

No!

In your example you write:

> sites = my_data.Name_site
> Lat_sites=my_data.Lat
> Lon_sites=my_data.Lon
> find_lon=where(Lon EQ Lon_sites, countlon)
> find_lat=where(Lat EQ Lat_sites, countLat)

There are two problems here:
- the EQ operator does not work when the arrays are of different length
- as you point out, where() cannot work since what you really need is
the coordinates of the nearest grid point

For this, several options are available, depending on what you want to
do (interpolate the gridded data to your point? Take the nearest grid
point) and depending on whether or not the lon/lat grid in your netcdf
file is regular or not...
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Maxwell equation solver in IDL
Next Topic: IDL Training

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:07:34 PDT 2025

Total time taken to generate the page: 0.00560 seconds