Function Reference

ocgis.format_return(ret_path, ops, with_auxiliary_files=False)[source]

Format an OpenClimateGIS path returning an absolute path to a zip file or simply passing ret_path through.

>>> import ocgis
>>> ops = ocgis.OcgOperations(...)
>>> ret = ops.execute()
>>> new_path = ocgis.format_return(ret,ops)




ocgis.util.helpers.add_shapefile_unique_identifier(in_path, out_path, name=None, template=None)[source]
>>> add_shapefile_unique_identifier('/path/to/foo.shp', '/path/to/new_foo.shp')
  • in_path (str) – Full path to the input shapefile.
  • out_path (str) – Full path to the output shapefile.
  • name (str) – The name of the unique identifer. If None, defaults to ocgis.constants.OCGIS_UNIQUE_GEOMETRY_IDENTIFIER.
  • template (str) – The integer attribute to copy as the unique identifier.

Path to the copied shapefile with the addition of a unique integer attribute called name.

Return type:


Parameters:centroids (numpy.ndarray) – Vector representing center coordinates from which to interpolate bounds.
Returns:A n-by-2 array with n equal to the shape of centroids.
>>> import numpy as np
>>> centroids = np.array([1,2,3])
>>> get_bounds_from_1d(centroids)
np.array([[0, 1],[1, 2],[2, 3]])
Return type:numpy.ndarray
Raises:NotImplementedError, ValueError
ocgis.util.helpers.get_sorted_uris_by_time_dimension(uris, variable=None)[source]

Sort a sequence of NetCDF URIs by the maximum time extent in ascending order.

Parameters:uris (list[str]) – The sequence of NetCDF URIs to sort.
>>> uris = ['/path/to/', 'path/to/']
Parameters:variable (str) – The target variable for sorting. If None is provided, then the variable will be autodiscovered.
Returns:A sequence of sorted URIs.
Return type:list[str]
ocgis.util.large_array.compute(ops, tile_dimension, verbose=False, use_optimizations=True)[source]

Used for computations on large arrays where memory limitations are a consideration. It is is also useful for extracting data from a server that has limitations on the size of requested data arrays. This function creates an empty destination NetCDF file that is then filled by executing the operations on chunks of the requested target dataset(s) and filling the destination NetCDF file.

  • ops (ocgis.OcgOperations) – The target operations to tile. There must be a calculation associated with the operations.
  • tile_dimension (int) – The target tile/chunk dimension. This integer value must be greater than zero.
  • verbose (bool) – If True, print more verbose information to terminal.
  • use_optimizations (bool) – If True, cache Field and TemporalGroupDimension objects for reuse during tile iteration.

AssertionError, ValuError


Path to the output NetCDF file.

Return type:


>>> from ocgis import RequestDataset, OcgOperations
>>> from ocgis.util.large_array import compute
>>> rd = RequestDataset(uri='/path/to/file', variable='tas')
>>> ops = OcgOperations(dataset=rd,calc=[{'func':'mean','name':'mean'}],output_format='nc')
>>> ret = compute(ops, 25)
ocgis.variable.stack(targets, stack_dim)[source]

Stack targets vertically using the stack dimension. For example, this function may be used to concatenate variables along the time dimension.

  • For variables, the stack dimension object, value, and mask on the new variable will be a deep copy.
  • For variables, the collection hierarchy is not traversed. Use the parent collections directly for the stack method.
  • For collections, the returned value is a copy of the first field with stacked variables as deep copies. If a variable’s dimensions does not contain the stacked dimension, it is a returned as a copy.
  • targets ([Variable | VariableCollection | Field, …]) – List of variables, variable collections, or fields to stack vertically along the stack dimension.
  • stack_dim (str | Dimension) – Dimension to use for vertical stacking.
Return type:

Same as input type to targets.