IHEWAwapor.WPdownload.download package

Submodules

IHEWAwapor.WPdownload.download.GIS_functions module

Created on Tue Jul 30 14:16:35 2019

@author: Bert Coerver

IHEWAwapor.WPdownload.download.GIS_functions.CreateGeoTiff(fh, Array, driver, NDV, xsize, ysize, GeoT, Projection, explicit=True, compress=None, print_job=False)[source]

Creates a geotiff from a numpy array.

Parameters
  • fh (str) – Filehandle for output.

  • Array (ndarray) – Array to convert to geotiff.

  • driver (str) – Driver of the fh.

  • NDV (float) – No-data-value of the fh.

  • xsize (int) – Amount of pixels in x direction.

  • ysize (int) – Amount of pixels in y direction.

  • GeoT (list) – List with geotransform values.

  • Projection (str) – Projection of fh.

  • print_job (bool) – Print job details, default True.

IHEWAwapor.WPdownload.download.GIS_functions.GetGeoInfo(fh, subdataset=0, print_job=False)[source]

Substract metadata from a geotiff, HDF4 or netCDF file.

Parameters
  • fh (str) – Filehandle to file to be scrutinized.

  • subdataset (int, optional) – Layer to be used in case of HDF4 or netCDF format, default is 0.

  • print_job (bool) – Print job details, default True.

Returns

  • driver (str) – Driver of the fh.

  • NDV (float) – No-data-value of the fh.

  • xsize (int) – Amount of pixels in x direction.

  • ysize (int) – Amount of pixels in y direction.

  • GeoT (list) – List with geotransform values.

  • Projection (str) – Projection of fh.

IHEWAwapor.WPdownload.download.GIS_functions.MatchProjResNDV(source_file, target_fhs, output_dir, resample='near', dtype='float32', scale=None, ndv_to_zero=False, print_job=False)[source]

Matches the projection, resolution and no-data-value of a list of target-files with a source-file and saves the new maps in output_dir.

Parameters
  • source_file (str) – The file to match the projection, resolution and ndv with.

  • target_fhs (list) – The files to be reprojected.

  • output_dir (str) – Folder to store the output.

  • resample (str, optional) – Resampling method to use, default is ‘near’ (nearest neighbour).

  • dtype (str, optional) – Datatype of output, default is ‘float32’.

  • scale (int, optional) – Multiple all maps with this value, default is None.

  • print_job (bool) – Print job details, default True.

Returns

output_files – Filehandles of the created files.

Return type

numpy.ndarray

IHEWAwapor.WPdownload.download.GIS_functions.OpenAsArray(fh, bandnumber=1, dtype='float32', nan_values=False, print_job=False)[source]

Open a map as an numpy array.

Parameters
  • fh (str) – Filehandle to map to open.

  • bandnumber (int, optional) – Band or layer to open as array, default is 1.

  • dtype (str, optional) – Datatype of output array, default is ‘float32’.

  • nan_values (boolean, optional) – Convert he no-data-values into np.nan values, note that dtype needs to be a float if True. Default is False.

  • print_job (bool) – Print job details, default True.

Returns

Array – Array with the pixel values.

Return type

numpy.ndarray

IHEWAwapor.WPdownload.download.GIS_functions.checkMemory(txt='', print_job=False)[source]

Check available memory.

Parameters
  • txt (str) – Prefix text.

  • print_job (bool) – Print job details, default True.

IHEWAwapor.WPdownload.download.WaporAPI module

Authors: Bich Tran

IHE Delft 2019

Contact: b.tran@un-ihe.org

FAO WaPOR GIS Manager API

class IHEWAwapor.WPdownload.download.WaporAPI.WaPOR_API_class(print_job=True)[source]

Bases: object

WaPOR API Class

API Docs

Parameters

print_job (bool) – Print job details, default True.

getAreaTimeseries(shapefile_fh, cube_code, time_range='2009-01-01,2018-12-31', APIToken='')[source]

Get Area Timeseries

Do need Authorization

Parameters
  • shapefile_fh (str) – ex. “E:/Area.shp”.

  • cube_code (str) – Cube code.

  • time_range (str, optional) – “YYYY-MM-DD,YYYY-MM-DD”.

  • APIToken (str) – WaPOR API Token.

Returns

timeseries – Area timeseries table.

Return type

pandas.DataFrame

getAvailData(cube_code, time_range='2009-01-01,2018-12-31', location=[], season=[], stage=[], version=None, level=None)[source]

Get Available Data

Parameters
  • cube_code (str) – ex. ‘L2_CTY_PHE_S’.

  • time_range (str, optional) – ex. ‘2009-01-01,2018-12-31’.

  • location (list, str, optional) – default: empty list, return all available locations, ex. [‘ETH’].

  • season (list, str, optional) – default: empty list, return all available seasons, ex. [‘S1’].

  • stage (list, str, optional) – default: empty list, return all available stages, ex. [‘EOS’,’SOS’].

  • version (int, optional) – WaPOR workspace version, default 2.

  • level (int, optional) – Data resolution level, default None.

Returns

data – Available Data table.

Return type

pandas.DataFrame

getCatalog(version=None, level=None, cubeInfo=True)[source]

Get catalog from workspace

Parameters
  • version (int, optional) – WaPOR workspace version, default 2.

  • level (int, optional) – Data resolution level, default None.

  • cubeInfo (bool, optional) – Get cube information, default True.

Returns

catalog – Catalog table.

Return type

pandas.DataFrame

getCropRasterURL(bbox, cube_code, time_code, rasterId)[source]

Get Crop Raster Url

Do need Authorization

Parameters
  • bbox (list) – [xmin,ymin,xmax,ymax], latitude and longitude.

  • cube_code (str) – Cube code.

  • time_code (str) – Time code, from Available Data table “raster_id”, ex. “[2009-01-01,2009-02-01)”.

  • rasterId (str) – Raster ID, from Available Data table “raster_id”, ex. “L1_PCP_0901M”.

Returns

download – Download url.

Return type

str

getCubeInfo(cube_code, version=None, level=None)[source]

Get cube info

Parameters
  • cube_code (str) – Cube code.

  • version (int, optional) – WaPOR workspace version, default 2.

  • level (int, optional) – Data resolution level, default None.

Returns

cube_info – Cube information.

Return type

dict

getLocations(version=None, level=None)[source]

Get Locations

Parameters
  • version (int, optional) – WaPOR workspace version, default 2.

  • level (int, optional) – Data resolution level, 2 or 3, default None.

Returns

locations – Locations table.

Return type

pandas.DataFrame

getPixelTimeseries(pixelCoordinates, cube_code, time_range='2009-01-01,2018-12-31')[source]

Get Pixel Timeseries

Do not need Authorization

Parameters
  • pixelCoordinates (list) – ex. [37.95883206252312, 7.89534].

  • cube_code (str) – Cube code.

  • time_range (str, optional) – “YYYY-MM-DD,YYYY-MM-DD”.

Returns

timeseries – Point timeseries table.

Return type

pandas.DataFrame

getRasterUrl(cube_code, rasterId, APIToken='')[source]

Get Raster Url

Parameters
  • cube_code (str) – Cube code.

  • rasterId (str) – Raster ID, from Available Data table “raster_id”, ex. “L1_PCP_0901M”.

Returns

download – Download url and expiry_datetime.

Return type

dict

getWorkspaces()[source]

Get workspace

isAPITokenExpired()[source]

Check AccessToken expires, and refresh token

isAPITokenSet()[source]

Check AccessToken is set

setAPIToken(APIToken)[source]

Initiate AccessToken and RefreshToken

Parameters

APIToken (str) – Input WaPOR API token.

Module contents

module for FAO WAPOR API