2.8 MtkReProject

class MtkReProject
Contains ReProjection Functionality.

>>> reproj = MtkReProject()

create_geogrid( )
Create a geo-grid array in decimal degress for lat/lon.

>>> reproj.create_geogrid(40,-120,30,-110,0.25,0.25)
(array([[ 40.  ,  40.  ,  40.  , ...,  40.  ,  40.  ,  40.  ],
       [ 39.75,  39.75,  39.75, ...,  39.75,  39.75,  39.75],
       [ 39.5 ,  39.5 ,  39.5 , ...,  39.5 ,  39.5 ,  39.5 ],
       ...,
       [ 30.5 ,  30.5 ,  30.5 , ...,  30.5 ,  30.5 ,  30.5 ],
       [ 30.25,  30.25,  30.25, ...,  30.25,  30.25,  30.25],
       [ 30.  ,  30.  ,  30.  , ...,  30.  ,  30.  ,  30.  ]]), 
       
array([[-120.  , -119.75, -119.5 , ..., -110.5 , -110.25, -110.  ],
       [-120.  , -119.75, -119.5 , ..., -110.5 , -110.25, -110.  ],
       [-120.  , -119.75, -119.5 , ..., -110.5 , -110.25, -110.  ],
       ...,
       [-120.  , -119.75, -119.5 , ..., -110.5 , -110.25, -110.  ],
       [-120.  , -119.75, -119.5 , ..., -110.5 , -110.25, -110.  ],
       [-120.  , -119.75, -119.5 , ..., -110.5 , -110.25, -110.  ]]))

resample_cubic_convolution( )
Resample source data at the given coordinates using interpolation by cubic convolution.

>>> srcdata = numpy.ones((128,512), dtype=numpy.float32) * 0.04
>>> datashape = srcdata.shape
>>> srcmask = numpy.ones(datashape, dtype=numpy.uint8)
>>> a = -0.5;
>>> regrshape = tuple((float(dimen) * abs(a)) for dimen in datashape)
>>> lines = numpy.tile(numpy.linspace(4.1,((10*regrshape[0]) + 4.1), regrshape[1]), (regrshape[0],1)).astype('float32')
>>> samples = numpy.tile(numpy.linspace(4.1,((10*regrshape[1]) + 4.1), regrshape[0]), (regrshape[1],1)).transpose().astype('float32')
>>> myproj.resample_cubic_convolution(srcdata, srcmask, lines, samples, a )
(array([[ 0.  ,  0.  ,  0.  , ...,  0.  ,  0.  ,  0.  ],
       [ 0.04,  0.04,  0.04, ...,  0.04,  0.04,  0.04],
       [ 0.04,  0.04,  0.04, ...,  0.04,  0.04,  0.04],
       ...,
       [ 0.04,  0.04,  0.04, ...,  0.04,  0.04,  0.04],
       [ 0.04,  0.04,  0.04, ...,  0.04,  0.04,  0.04],
       [ 0.04,  0.04,  0.04, ...,  0.04,  0.04,  0.04]], dtype=float32),
       
array([[0, 0, 0, ..., 0, 0, 0],
       [1, 1, 1, ..., 1, 1, 1],
       [1, 1, 1, ..., 1, 1, 1],
       ...,
       [1, 1, 1, ..., 1, 1, 1],
       [1, 1, 1, ..., 1, 1, 1],
       [1, 1, 1, ..., 1, 1, 1]], dtype=int8))

resample_nearest_neighbor( )
Performs nearest neighbor resampling.

>>> srcdata = numpy.ones((128,512), dtype=numpy.float32) * 20
>>> datashape = srcdata.shape
>>> regrshape = tuple( (float(dimen) * 0.5) for dimen in datashape)
>>> lines = numpy.tile(numpy.linspace(4.1,((10*regrshape[0]) + 4.1), regrshape[1]), (regrshape[0],1)).astype('float32')
>>> samples = numpy.tile(numpy.linspace(4.1,((10*regrshape[1]) + 4.1), regrshape[0]), (regrshape[1],1)).transpose().astype('float32')
>>> myproj.resample_nearest_neighbor(srcdata, lines, samples)
array([[ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       ...,
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.]], dtype=float32)

transform_coordinates( )
Transforms latitude/longitude coordinates into line/sample coordinates.

>>> r = Mtk.MtkRegion(39, 51, 52)
>>> mapinfo = r.snap_to_grid(39, 275)
>>> (lat, lon) = reproj.create_geogrid(49.0, -113.0, 47.5, -114.0, 0.02, 0.02)
>>> reproj.transform_coordinates(mapinfo, lat, lon)
(array([[475.7129 , 474.96417, 474.21405, ..., 512.7551 , 512.07776,
        511.39905],
       [483.72412, 482.97504, 482.22458, ..., 520.7843 , 520.1066 ,
        519.4276 ],
       [491.73526, 490.98584, 490.23502, ..., 528.8135 , 528.13544,
        527.45605],
       ...,
       [ -1.     ,  -1.     ,  -1.     , ...,  -1.     ,  -1.     ,
         -1.     ],
       [ -1.     ,  -1.     ,  -1.     , ...,  -1.     ,  -1.     ,
         -1.     ],
       [ -1.     ,  -1.     ,  -1.     , ...,  -1.     ,  -1.     ,
         -1.     ]], dtype=float32), array([[313.62213 , 318.89313 , 324.1639  , ...,  39.21427 ,  44.49714 ,
         49.779778],
       [314.75842 , 320.03152 , 325.30438 , ...,  40.2419  ,  45.526855,
         50.811584],
       [315.89478 , 321.16998 , 326.44495 , ...,  41.269634,  46.556675,
         51.843494],
       ...,
       [ -1.      ,  -1.      ,  -1.      , ...,  -1.      ,  -1.      ,
         -1.      ],
       [ -1.      ,  -1.      ,  -1.      , ...,  -1.      ,  -1.      ,
         -1.      ],
       [ -1.      ,  -1.      ,  -1.      , ...,  -1.      ,  -1.      ,
         -1.      ]], dtype=float32))