Re: temporal interpolation with linint1_n_Wrap

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Thu Feb 28 2013 - 14:32:53 MST

Hi Francesc,

Looks like nobody picked this one up.

I think the issue is that you are not using the same units for the interpolation. In order to interpolate a set of values from one time array to another, the two time arrays should be in the same units.

Using your code below, I think you want to use cd_convert to convert from "days since" to "hours since", and then, since you know the hours are 6 hours apart, you can simply create a new array that goes from the same min/max as the original array, but with double the number of points, so you get values inbetween.

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"

begin
  print("reading the variables")
  setfileoption("nc","MissingToFillValue",False)
  a = addfile("cruncep_tair_2010_1x1_2time.nc","r")
  temp=a->y
  printVarSummary(temp)
  temp@_FillValue = -9.99999979021477e+33
  temp@missing_value = temp@_FillValue

;reverse the latitude values
  temp = temp (:,::-1,:)

;create a sequence for the new values of time
  time_in_days = a->time

;---Convert from "days since" to "hours since"
  new_units = str_sub_str(time_in_days@units,"days","hours")
  time_in_6hours = cd_convert(time_in_days,new_units)
  ntime6 = dimsizes(time_in_6hours)
  print(time_in_6hours)

;
; Create new time array that goes every 3 hours. Basically, take the
; every-6-hours array and insert values in between each value.
;
  time_in_3hours = fspan(min(time_in_6hours),max(time_in_6hours),(2*ntime6-1))
  time_in_3hours@units = new_units

;---Interpolate to new time array
  tair1=linint1_n_Wrap(time_in_6hours, temp, False, time_in_3hours, 0, 0)

  printVarSummary(temp)
  printVarSummary(tair1)
  printMinMax(temp,0)
  printMinMax(tair1,0)

  output_filename = "cruncep_tairnew_2010_1x1_3h_2time.nc"
  system("rm -f " + output_filename)
  fout=addfile(output_filename,"c")
  fout@title="Temperature interpolated into 3-h resolution for 12-h in January 2010"
  fout->y=tair1

end

On Feb 25, 2013, at 12:03 PM, Montane Caminal, Francesc wrote:

> Hello NCL users,
>
> I need to do a temporal interpolation of my climate variable of interest from 6-h in the original file to 3-h in the new file.
>
> Attached is a file that includes temperature values for 2 times measured in 6-hours interval (total time 12 hours). I was trying to interpolate temperature values using “linint1_n_Wrap” to get 4 measures of temperature, one every 3-h (interpolate temperature values from 6-h to 3-h in the new file, for the total time of 12 hours), but the new created file after interpolating has empty values of temperature.
>
> I attach my original netcdf file and also the script I used to do the temporal interpolation using “linint1_n_Wrap”. Is there a more recommended function than “linint1_n_Wrap” to do this? Can anyone, please tell me what do I need to modify in the script to get the right output with the interpolated values in 3-h instead of 6-h?
>
> Any help will be very appreciated!
> Thanks.
>
> Francesc
>
>
> SCRIPT:
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
>
> begin
> print("reading the variables")
> setfileoption("nc","MissingToFillValue",False)
> a = addfile("cruncep_tair_2010_1x1_2time.nc","r")
>
> temp=a->y
> printVarSummary(temp)
> temp@_FillValue = -9.99999979021477e+33
> temp@missing_value = temp@_FillValue
> ;reverse the latitude values
> temp = temp (:,::-1,:)
>
> ;create a sequence for the new values of time, which has to be a double precision variable
> tNew=fspan(21600.00,43200.00,4)
> tNew@units = "seconds since December 31, 2009 21:00:00"
>  
> time2=a->time
>  
> tair1=linint1_n_Wrap(time2, temp, False, tNew, 0, 0)
> printVarSummary(tair1)
> print("tair1: min="+min(tair1)+" max="+max(tair1))
> tair1!0 = "time"
> tair1!1 = "lat"
> tair1!2 = "lon"
>  
>  
>  
> fout=addfile("cruncep_tairnew_2010_1x1_3h_2time.nc", "c")
> fout@title="Temperature interpolated into 3-h resolution for 12-h in January 2010"
> fout->y=tair1
>  
> end
> <cruncep_tair_2010_1x1_2time.nc>_______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Feb 28 14:33:02 2013

This archive was generated by hypermail 2.1.8 : Thu Feb 28 2013 - 14:47:31 MST