ecoscope.base.utils#

Module Contents#

ecoscope.base.utils.create_meshgrid(aoi, in_crs, out_crs, xlen=1000, ylen=1000, return_intersecting_only=True, align_to_existing=None)[source]#

Create a grid covering aoi.

Parameters:
  • aoi (shapely.geometry.base.BaseGeometry) – The area of interest. Should be in a UTM CRS.

  • in_crs (value) – Coordinate Reference System of input aoi. Can be anything accepted by pyproj.CRS.from_user_input(). Geometry is automatically converted to UTM CRS as an intermediate for computation.

  • out_crs (value) – Coordinate Reference System of output gs. Can be anything accepted by pyproj.CRS.from_user_input(). Geometry is automatically converted to UTM CRS as an intermediate for computation.

  • xlen (int, optional) – The width of a grid cell in meters.

  • ylen (int, optional) – The height of a grid cell in meters.

  • return_intersecting_only (bool, optional) – Whether to return only grid cells intersecting with the aoi.

  • align_to_existing (geopandas.GeoSeries or geopandas.GeoDataFrame, optional) – If provided, attempts to align created grid to start of existing grid. Requires a CRS and valid geometry.

Returns:

gs – Grid of boxes. CRS is converted to out_crs.

Return type:

geopandas.GeoSeries

class ecoscope.base.utils.cachedproperty(func)[source]#

The cachedproperty is used similar to property, except that the wrapped method is only called once. This is commonly used to implement lazy attributes.

func#
__doc__()[source]#
__isabstractmethod__()[source]#
__get__(obj, objtype=None)[source]#
__repr__()[source]#
ecoscope.base.utils.groupby_intervals(df, col, intervals)[source]#
Parameters:
  • df (pd.DataFrame) – Data to group

  • col (str) – Name of column to group on

  • intervals (pd.IntervalIndex) – Intervals to group on

Return type:

pd.core.groupby.DataFrameGroupBy

ecoscope.base.utils.create_interval_index(start, intervals, freq, overlap=pd.Timedelta(0), closed='right', round_down_to_freq=False)[source]#
Parameters:
  • start (str or datetime-like) – Left bound for creating IntervalIndex

  • intervals (int, optional) – Number of intervals to create

  • freq (str, Timedelta or DateOffset) – Length of each interval

  • overlap (Timedelta or DateOffset, optional) – Length of overlap between intervals

  • closed ({"left", "right", "both", "neither"}, default "right") – Whether the intervals are closed on the left-side, right-side, both or neither

  • round_down_to_freq (bool) – Start will be rounded down to freq

Returns:

interval_index

Return type:

pd.IntervalIndex

class ecoscope.base.utils.ModisBegin[source]#

Bases: pandas._libs.tslibs.offsets.SingleConstructorOffset

Primitive DateOffset to support MODIS period start times.

apply(other)[source]#
Parameters:

other (pandas.Timestamp)

Return type:

pandas.Timestamp

ecoscope.base.utils.create_modis_interval_index(start, intervals, overlap=pd.Timedelta(0), closed='right')[source]#
Parameters:
  • start (str or datetime-like) – Left bound for creating IntervalIndex. Will be rounded up to next start of MODIS period

  • intervals (int, optional) – Number of intervals to create

  • overlap (Timedelta or DateOffset, optional) – Length of overlap between intervals

  • closed ({"left", "right", "both", "neither"}, default "right") – Whether the intervals are closed on the left-side, right-side, both or neither

Returns:

interval_index

Return type:

pd.IntervalIndex

ecoscope.base.utils.add_val_index(df, index_name, val)[source]#
Parameters:
  • df (pd.DataFrame) – Dataframe to create index on

  • index_name (str) – Name of index

  • val (str) – Current column to rename and set as index

Return type:

pd.DataFrame

ecoscope.base.utils.add_temporal_index(df, index_name, time_col, directive)[source]#
Parameters:
  • df (pd.DataFrame) – Dataframe to create index on

  • index_name (str) – Name of temporal index

  • time_col (str) – Name of the time column

  • directive (str) – Time format string

Return type:

pd.DataFrame

ecoscope.base.utils.hex_to_rgba(input)[source]#
Parameters:

input (str)

Return type:

tuple

ecoscope.base.utils.color_tuple_to_css(color)[source]#
Parameters:

color (Tuple[int, int, int, int])