convert

dnppy convert contains functions for conversion between filetypes. Usually between a file type distributed by a NASA Distributed Active Archive Center (DAAC) such as NetCDF or HDF5 to geotiff. Due to differences in metadata standards, many of these functions only operate successfully data from a specific source.

Requires arcpy

Examples

no examples yet!

Code Help

Auto-documentation for functions and classes within this module is generated below!

datatype_library()[source]

This function builds the datatype_library dict out of file datatype_library.csv and returns it. Adding to this datatype library should be done by editing the csv file, not this code. Note that the standard format for names is <product short name>_<resolution identifier>_<coverage area>, such as “TRMM_1.0_GLOBAL”, or “GPM_IMERG_0.1_GLOBAL”.

Geotransform math used to create the array [A, B, C, D, E, F]

x = A + iB + jC
y = D + iE + jF

Where x,y are real spatial coordinates, and i,j are matrix indices. A, B, C, D, E, F and are coefficients that make up the geotransformation array.

Return datatype_library_dict:
 A dictionary
class datatype(name=None, projectionID=None, geotransform=None, projectionTXT=None, downloadSource=None)[source]

simple class for dnppy supported download and convert NASA/NOAA/WeatherService/USGS data types.

Parameters:
  • name – the product name (descriptive string)
  • projectionID – (str) projection ID according to spatialreference.org
  • geotransform – (list of floats) geotransform array, list of 6 float values in the gdal ordering.
extract_archive(filepaths, delete_originals=False)[source]

Input list of filepaths OR a directory path with compressed files in it. Attempts to decompress the following formats

Support formats include .tar.gz, .tar, .gz, .zip.

Parameters:
  • filepaths – list of filepaths to archives for extraction
  • delete_originals – Set to “True” if archives may be deleted after their contents is successful extracted.
extract_GCMO_NetCDF(netcdf_list, variable, outdir)[source]

Extracts all time layers from a “Global Climate Model Output” NetCDF layer

Parameters:
  • netcdf_list – List of netcdfs from CORDEX climate distribution
  • variable – The climate variable of interest (tsmax, tsmin, etc)
  • outdir – Output directory to save files.
Return output_filelist:
 

returns list of files created by this function

extract_GPM_IMERG(hdf_list, layer_indexs, outdir=None, resolution='0.1')[source]

Extracts GPM_IMERG data from its HDF5 format.

Parameters:
  • hdf_list – list of hdf files or directory with hdfs
  • layer_indexs – list of integer layer indexs
  • outdir – directory to place outputs
  • resolution – The size of a pixel in degrees, either “0.1” or “0.15” depending on GPM product.
Returns:

a list of all files created as output

Typical contents of a GPM HDF are:

ID layer shape Layer name data type
0 [3600x1800] HQobservationTime (16-bit int)
1 [3600x1800] HQprecipSource (16-bit int)
2 [3600x1800] HQprecipitation (32-bit float)
3 [3600x1800] IRkalmanFilterWeight (16-bit int)
4 [3600x1800] IRprecipitation (32-bit float)
5 [3600x1800] precipitationCal (32-bit float)
6 [3600x1800] precipitationUncal (32-bit float)
7 [3600x1800] probabilityLiquidPrecipitation (16-bit int)
8 [3600x1800] randomError (32-bit float)
extract_GRACE_DA_binary(folder, outdir=False, npy_file=False)[source]

This function will convert a folder of GRACE Data Assimilation product binary files into individual tiffs or a single three-dimensional NumPy array. The input folder should contain only the binary files.

For more information on GRACE Data Assimilation products, visit [http://drought.unl.edu/MonitoringTools/NASAGRACEDataAssimilation.aspx]

Parameters:
  • folder – the full path to the folder containing the binary files to be converted
  • outdir – Optional full path to the desired output folder. if left False by default, the output file(s) will be place in the input folder
  • npy_file – Option to save the data as a 3-dimensional NumPy array file instead of tiffs enter True to convert data to a single .npy file. if left False by default, each binary file will be converted to tiff format instead
Return outlist:

returns list of files created by this function

extract_MPE_NetCDF(netcdf_list, layer_indexs, outdir, area)[source]

extracts SMOS data from its native NetCDF format.

Parameters:
  • netcdf_list – list of hdf files or directory with netcdfs
  • layer_indexs – list of integer layer indices
  • outdir – directory to place outputs
  • area – presently only supports “CONUS”
Returns:

A list of all files created as output

extract_SMOS_NetCDF(netcdf_list, layer_indexs, outdir, resolution)[source]

Extracts SMOS data from its native NetCDF format.

Parameters:
  • netcdf_list – list of hdf files or directory with netcdfs
  • layer_indexs – list of integer layer indices
  • outdir – directory to place outputs
  • resolution – Presently ONLY supports input of “25k”
Returns:

a list of all files created as output

extract_TRMM_HDF(hdf_list, layer_indexs, outdir, resolution)[source]

Extracts TRMM products from HDF to tif. http://pmm.nasa.gov/data-access/data-products

Parameters:
  • hdf_list – list of hdf files or directory with hdfs
  • layer_indexs – list of integer layer indexs
  • outdir – directory to place outputs
  • resolution – The size of a pixel in degrees, either “0.25”, “0.5”, “1.0”, “5.0” depending on the specific TRMM product you are extracting.
Returns:

a list of all files created as output

TRMM_NetCDF(filelist, outdir)[source]

Function converts NetCDFs to tiffs. Designed to work with TRMM data downloaded from GLOVIS

Parameters:
  • filelist – list of ‘.nc’ files to convert to tifs.
  • outdir – directory to which tif files should be saved
Return output_filelist:
 

list of local filepaths of extracted data.

HDF5_to_numpy(hdfpath, layers=None)[source]

NOTE: This is functionally identical to _extract_HDF_layer_data, but employs an h5py based approach instead of gdal. It is experimental, and not yet used anywhere.

Extracts one or more layers from an HDF5 file and returns a dict of numpy arrays

Parameters:
  • hdfpath – Filepath to an HDF5 file
  • layers – A list of integer values or layer names to extract leave “None” to return numpy arrays for ALL layers
Return layer_dict:
 

Dict with band names as keys and numpy arrays as values

ll_to_utm(lat, lon, utm_zone, hemisphere)[source]

Function converts lat/lon to UTM zone coordinates. Equations from USGS bulletin 1532. East and North are positive, South and West are negative.

Parameters:
  • lat – latitude value in degrees (East is positive)
  • lon – longitude value in degrees (North is positive)
  • utm_zone – UTM zone number as an integer, without the “S” or “N”
  • hemisphere – hemisphere for UTM zone, either “S”, or “N”
Returns:

UTM_easting, UTM_northing

class nongrid_data(lat, lon, data, hemisphere)[source]

This class houses non-gridded datasets. Its methods can be used to build a gridded dataset from a non gridded dataset or point data. It takes three array/matrix like inputs, lat, lon, and data values. These matrix like inputs are then processed into 1d-arrays with two sorting schemes.

The three arrays are represented as (lat_array, lon_array, data_array)

where each array is of equal shape, and the value of each row corresponds to the values in the same row of the other arrays. these arrays are then converted to UTM coordinates and sorted by the utm_x coordinate.

This sorting is done to optimize processing time when building a gridded dataset from what is effectively assumed to be point data.

Parameters:
  • lat – matrix of values representing latitude
  • lon – matrix of values representing longitude
  • data – matrix of values containing spatial data
  • hemisphere – either “N” or “S”
_sample_by_location(utmx_matrix, utmy_matrix, resolution)[source]

performs grid interpolation for a smaller subset of the total dataset. utmx_matrix and utmy_matrix are the two components of a meshgrid

static distance_lat_lon(lat0, lon0, lat1, lon1)[source]

computes the distance between two lat/lon coordinates in meters using the Haversine formula.

static distance_x_y(x0, y0, x1, y1)[source]

computes the approx distance between two utmx, utmy locations

sample_by_grid(resolution)[source]

Grids a dataset to the desired resolution in a UTM projection. input resolution is the length of one square pixel on a side in meters.