[ncl-talk] How to change time co-ordinates from "Hours since ....." to YYYYMMDD while plotting
Dilip V
dilip.v at students.iiserpune.ac.in
Mon Jul 16 03:22:04 MDT 2018
Hello!
I wanted to plot a contour map of lat v/s time for Precipitation anomaly
over certain longitude. The time coordinates were given in "Hours since
1900-01-01 00:00:00". I converted them to YYYYMMDD using 'cd_calendar' and
saved it as a new time coordinates. When i tried plotting, i got the
following error message
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
warning:IrTransInitialize: trXCoordPoints contains invalid coordinate
array: defaulting trXAxisType to LinearAxis
warning:_NhlCreateSplineCoordApprox: Attempt to create spline approximation
for X axis failed: consider adjusting trXTensionF value
warning:_NhlCreateSplineCoordApprox: Attempt to create spline approximation
for X axis failed: consider adjusting trXTensionF value
warning:_NhlCreateSplineCoordApprox: Attempt to create spline approximation
for X axis failed: consider adjusting trXTensionF value
fatal:IrTransInitialize: spline coordinate approximation not possible:
fatal:Unable to initialize layer-Can't Create
fatal:ContourPlotInitialize: Error creating transformation object
fatal:ContourPlotInitialize: error setting up transformation
fatal:Unable to initialize layer-Can't Create
fatal:Unable to access object with id:-4
fatal:PID #-4 can't be found in NhlSetValues
fatal:NhlGetValues:PID #-4 is invalid
fatal:["Execute.c":8640]:Execute: Error occurred at or near line 2222 in
file /apps/codes/gnu/ncl_stable/lib/ncarg/nclscripts/csm/gsn_code.ncl
fatal:["Execute.c":8640]:Execute: Error occurred at or near line 9571 in
file /apps/codes/gnu/ncl_stable/lib/ncarg/nclscripts/csm/gsn_code.ncl
fatal:["Execute.c":8640]:Execute: Error occurred at or near line 13393 in
file /apps/codes/gnu/ncl_stable/lib/ncarg/nclscripts/csm/gsn_csm.ncl
fatal:["Execute.c":8640]:Execute: Error occurred at or near line 224 in
file pract8.ncl
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
My data includes only one year of daily precipitation data with
specifications as below.
----------------------------------------------------------------------------------------------------------------------------
Variable: p
Type: float
Total Size: 52560 bytes
13140 values
Number of Dimensions: 3
Dimensions and sizes: [time | 365] x [lat | 6] x [lon | 6]
Coordinates:
time: [990552..999288]
lat: [28.75..31.25]
lon: [78.25..80.75]
Number Of Attributes: 14
_FillValue : -9.96921e+36
var_desc : Precipitation
valid_range : ( 0, 1000 )
units : mm
statistic : Total
parent_stat : Other
missing_value : -9.96921e+36
long_name : Daily total of precipitation
level_desc : Surface
dataset : CPC Global Precipitation
cell_methods : time: sum
avg_period : 0000-00-01 00:00:00
actual_range : ( 0, 473.6278 )
DIMENSION_LIST : -2147483647
----------------------------------------------------------------------------------------------------------------------------------
*How do i plot contour map of lat v/s time with time coordinates in
YYYYMMDD format for a certain time period? *
My code for the above is as follows:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
read = 1
if (read.ne.0) then
f = addfile("precip_2013.nc","r")
p = f->precip(:,{28.75:31.25},{78.25:80.75})
pr = p(lat|:,lon|:,time|:)
prm = dim_avg_Wrap(pr)
prnew = new((/6,6,365/),float)
t = f->time
tim = cd_calendar(t,2)
;computing anomoly at all points
do i = 0,5
do j = 0,5
do k = 0,364
prnew(i,j,k) = (pr(i,j,k)-prm(i,j))
end do
end do
end do
prnew!0 = "lat"
prnew!1 = "lon"
prnew!2 = "time"
prn = prnew(time|:,lat|:,lon|:)
;applying fft over anomoly at all points
ft = new((/2,365,6,6/),float)
do h = 0,5
do k = 0,5
gt = cfftf(prn(:,h,k),0.0,0)
ft(0,:,h,k) = gt(0,:)
ft(1,:,h,k) = gt(1,:)
end do
end do
;filtering out unwanted frequencies
do h = 0,5
do k = 0,5
ft(0,13:352,h,k) = 0.0
ft(1,13:352,h,k) = 0.0
ft(0,360:,h,k) = 0.0
ft(1,360:,h,k) = 0.0
ft(0,0:5,h,k) = 0.0
ft(1,0:5,h,k) = 0.0
end do
end do
;ifft of required frequencies
ift = new((/365,6,6/),float)
do h = 0,5
do k = 0,5
kt = cfftb(ft(:,:,h,k),1)
ift(:,h,k) = kt(:)
end do
end do
ift!0 = "time"
ift!1 = "lat"
ift!2 = "lon"
iftnew = ift(lat|:,lon|:,time|:)
copy_VarAtts(pr,iftnew)
copy_VarCoords(pr,iftnew)
oxn = iftnew(lon|:,lat|:,time|:)
oxn at long_name = "30-60 day anomoly of precipitation"
oxn&time = tim
wks = gsn_open_wks ("png", "lat_time" ) ; send graphics to PNG
file
res = True ; plot mods desired
res at cnFillOn = True ; turn on color fill
res at cnFillPalette = "BlWhRe" ; set color map
res at cnLinesOn = False
res at tiMainString = "Uttarkhand at 79.25E" ; title
res at tiYAxisString = "Latitude"
res at cnLevelSelectionMode = "AutomaticLevels" ; manual contour levels
res at lbOrientation = "Vertical"
plot = gsn_csm_contour(wks, oxn({79.25},:,160:170), res)
end if
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*By,*
*Dilip.V*
*Master's Student,*
*Indian Institute of Science Education and Research,*
*Pune, India*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180716/7f8a41c3/attachment.html>
More information about the ncl-talk
mailing list