Skip to content

User Guide

kyang2014 edited this page Jun 20, 2019 · 22 revisions

This document explains how to use pytaf for developing your Python application.

Pytaf has been developed for TerraFusion data products. However, it is a general package that can be used to resample between any two pairs of geospatial arrays. The input arrays are: source latitude & longitude, target latitude & longitude and the source data. It returns target data that are re-sampled to match the target latitude & longitude.

Load Package

Once pytaf is installed, you can use it by importing the package at the beginning.

import pytaf

High Level Functions

These high level functions accept both 1D and 2D latitude and longitude pairs. If 1D lat/lon are provided, they will be converted into 2D internally before they are sent to C functions. After processing is done by C functions, the function will return target value. If 1D lat/lon are used as target, the return target value will be 1D array. For 2D target lat/lon, 2D array will be returned.

If 3 or more dimension variables are passed arguments, these functions will print error message and return None for target values.

resample_n

This function picks the nearest neighbor pixel within the radius. It requires 6 arguments.

  1. source latitude
  2. source longitude
  3. target latitude
  4. target longitude
  5. source data
  6. radius (Note: the radius is the maximum search radius in meters, It is usually the distance which one wants to find the nearest neighbor within For Terra Advanced Fusion, this is the pixel resolution of the source instrument.)

resample_s

This function calculates the average value from the source pixels that lie within the radius. If you re-sample data from high resolution (e.g., MISR) to low resolution (e.g., CERES), you must use this function.

This function requires the same 6 arguments that resample_n requires and 2 more for output the following:

  1. standard deviation
  2. number of pixels used Also for the Terra advanced fusion, the radius is close to the resolution of the target instrument, which is generally the low resolution.

The additional arguments must be numpy array and their shape should match target latitude/longitude variable's shape. The number of pixels and the standard deviation of the data values will return after calling the resample_s function.

One should keep in mind that the radius argument for this function should be the maximum search radius for the target instrument. One caveat is that the number of pixels this function includes to calculate the average value may be less than the total of number of pixels within the radius. In that case, a multiple iterations may be needed to achieve the accurate results.

Low Level Functions

The low level functions have 1-to-1 relationship with C functions. They are called by high level functions. Users do not have to call these directly but advanced users may want to call them.

  1. clip
  2. find_nn_block_index
  3. interpolate_nn
  4. interpolate_summary

For example, calling resample_s() will call both find_nn_block_index() and interpolate_summary(). See pytaf.pyx code to learn the relationship between these wrapper functions and C code.

Clone this wiki locally