PyNGL Home > Functions > Miscellaneous

Ngl.ndctodata

Converts coordinates in NDC space to coordinates in data space.

Available in version 1.3.0 or later.

Prototype

x_out, y_out = Ngl.ndctodata(plotid, x_in, y_in)

Arguments

plotid

The identifier returned from any PyNGL graphics function that returns a PlotId.

x_in, y_in

One-dimensional (masked) arrays of x and y NDC coordinates. They must be the same length.

Return values

x_out, y_out

One-dimensional (masked) arrays of the same length as x_in and y_in containing the data coordinates that the input arrays were mapped onto by the coordinate transform function. For map plots, x_out contains longitude values, and y_out contains latitude values.

Description

Coordinate pairs from the input arrays are mapped to the corresponding pairs in the output arrays.

If either input array is a masked array and any of the values are missing, or if any of the output values are out-of-range, then masked arrays are returned with fill values of 1.e30 placed in the corresponding indexes in both output arrays.

See Also

Ngl.datatondc

Examples

Example 1

This example creates and draws a map plot, and then shows how to use Ngl.datatondc to convert some longitude coordinates along a single latitude value to NDC coordinates. It then uses the reverse function, Ngl.ndctodata to convert the NDC coordinates back to the original values.

import math,sys
import Ngl,numpy

wks = Ngl.open_wks("x11","ndctodata_0_py")

res = Ngl.Resources()
res.nglMaximize = False
res.vpXF        = 0.1  
res.vpYF        = 0.9
res.vpHeightF   = 0.8
res.vpWidthF    = 0.8

map = Ngl.map(wks,"CylindricalEquidistant",res)

npts = 10
x_in = Ngl.fspan(-180.,180.,npts)
y_in = 30.*numpy.ones(npts,'f')

x_out,y_out = Ngl.datatondc(map,x_in,y_in)
for i in xrange(len(x_out)):
  print "%4d  data: (%6.1f, %3.1f)  NDC: (%8.6f, %8.6f)" % \
               (i,x_in[i],y_in[i],x_out[i],y_out[i])

print "ndctodata"
x_out2,y_out2 = Ngl.ndctodata(map,x_out,y_out)

for i in xrange(len(x_out2)):
   print "%4d  data: (%6.1f, %3.1f)  original data: (%6.1f, %3.1f)" % \
               (i,x_in[i],y_in[i],x_out2[i],y_out2[i])

Ngl.end()

The output should look like:

   0  data: (-180.0, 30.0)  NDC: (0.100000, 0.566667)
   1  data: (-140.0, 30.0)  NDC: (0.188889, 0.566667)
   2  data: (-100.0, 30.0)  NDC: (0.277778, 0.566667)
   3  data: ( -60.0, 30.0)  NDC: (0.366667, 0.566667)
   4  data: ( -20.0, 30.0)  NDC: (0.455556, 0.566667)
   5  data: (  20.0, 30.0)  NDC: (0.544444, 0.566667)
   6  data: (  60.0, 30.0)  NDC: (0.633333, 0.566667)
   7  data: ( 100.0, 30.0)  NDC: (0.722222, 0.566667)
   8  data: ( 140.0, 30.0)  NDC: (0.811111, 0.566667)
   9  data: ( 180.0, 30.0)  NDC: (0.900000, 0.566667)
ndctodata
   0  data: (-180.0, 30.0)  original data: (-180.0, 30.0)
   1  data: (-140.0, 30.0)  original data: (-140.0, 30.0)
   2  data: (-100.0, 30.0)  original data: (-100.0, 30.0)
   3  data: ( -60.0, 30.0)  original data: ( -60.0, 30.0)
   4  data: ( -20.0, 30.0)  original data: ( -20.0, 30.0)
   5  data: (  20.0, 30.0)  original data: (  20.0, 30.0)
   6  data: (  60.0, 30.0)  original data: (  60.0, 30.0)
   7  data: ( 100.0, 30.0)  original data: ( 100.0, 30.0)
   8  data: ( 140.0, 30.0)  original data: ( 140.0, 30.0)
   9  data: ( 180.0, 30.0)  original data: ( 180.0, 30.0)