flexmeasures.utils.grid_cells

Functions

flexmeasures.utils.grid_cells.get_cell_nums(tl: tuple[float, float], br: tuple[float, float], num_cells: int = 9) tuple[int, int]

Compute the number of cells in both directions, latitude and longitude. By default, a square grid with N=9 cells is computed, so 3 by 3. For N with non-integer square root, the function will determine a nice cell pattern. :param tl: top-left (lat, lng) tuple of ROI :param br: bottom-right (lat, lng) tuple of ROI :param num_cells: number of cells (9 by default, leading to a 3x3 grid)

Classes

class flexmeasures.utils.grid_cells.LatLngGrid(top_left: tuple[float, float], bottom_right: tuple[float, float], num_cells_lat: int, num_cells_lng: int)

Represents a grid in latitude and longitude notation for some rectangular region of interest (ROI). The specs are a top-left and a bottom-right coordinate, as well as the number of cells in both directions. The class provides two ways of conceptualising cells which nicely cover the grid: square cells and hexagonal cells. For both, locations can be computed which represent the corners of said cells. Examples:

  • 4 cells in square: 9 unique locations in a 2x2 grid (4*4 locations, of which 7 are covered by another cell)

  • 4 cells in hex: 13 unique locations in a 2x2 grid (4*6 locations, of which 11 are already covered)

  • 10 cells in square: 18 unique locations in a 5x2 grid (10*4 locations, of which 11 are already covered)

  • 10 cells in hex: 34 unique locations in a 5x2 grid (10*6 locations, of which 26 are already covered)

The top-right and bottom-left locations are always at the center of a cell, unless the grid has 1 row or 1 column. In those case, these locations are closer to one side of the cell.

__init__(top_left: tuple[float, float], bottom_right: tuple[float, float], num_cells_lat: int, num_cells_lng: int)
compute_cell_size_lat() float

Calculate the step size between latitudes

compute_cell_size_lng() float

Calculate the step size between longitudes

get_locations(method: str) list[tuple[float, float]]

Get locations by method (“square” or “hex”)

locations_hex() list[tuple[float, float]]

The hexagonal pattern - actually leaves out one cell for every even row.

locations_square() list[tuple[float, float]]

square pattern