Reference 〉 Class
basePatches

PatchesGeo(wrapbool|tuple(bool,bool), cornersbool|floatTrue, offmapboolFalse)

PatchesGeo with North Carolina counties as patches.

Initializes a spatial model with arbitrary polygonal patches, which are added one at a time afterward with the add() method. This coordinate system can be instantiated with model.spatial(geometry='geo'), and requires Shapely in order to function. Patches are stored in a one-dimensional list, and can be accessed by patch name (e.g. model.patches['ROWAN']) or by ID.

Initialization Parameters

  • wrap bool|tuple(bool,bool), required

    Whether the map wraps along the horizontal or vertical axes, or both.

  • corners bool|float, optional

    Whether patches touching at a single point should be neighbors, and if so, what weight.

    Default value: True

  • offmap bool, optional

    Whether agents can take a position with no patch underneath.

    Default value: False

Methods

Click a method name for more detailed documentation.

  • add( shape, name )

    Adds a polygonal patch to the map.

  • at( x, y )

    Returns the patch at the specified coordinate.

  • revive( coords )

    Reinstates a dead patch.

  • neighbors( model )

    Establishes the spatial network among the patches after initialization. This function is registered automatically as a modelPostSetup hook during spatial setup and should not be called by user code.

  • place( patch )

    Organizes Patch objects within the Patches object. Takes a patch object when created by Agents.initialize(), places it in the appropriate list, and assigns its position property.

Object Properties

  • offmap bool

    Whether agents can enter areas of the map with no patch. If False and an agent tries to move() to a coordinate with no patch, the move will fail and a warning will be raised. Set from the offmap argument of model.spatial().

    Initial value: False

  • boundaries tuple(tuple(int,int), tuple(int,int))

    A tuple of tuples with the maximum and minimum coordinates that agents can take, given the grid dimensions. ((xmin, xmax), (ymin, ymax)).

  • corners bool|float

    Whether the 'spatial' network includes patches connected only by a corner. Corresponds to the corners argument of model.spatial().

    Initial value: False

  • wrap tuple(bool, bool)

    Whether each respective dimension wraps around beyond the limits of boundaries.

  • dim tuple(int, int)

    The (x,y) dimensions of the grid.

Static Properties

  • geometry str

    The name of the patch geometry, to be set by subclasses.

    Initial value: ''

Notes and Examples

  1. charwick

    May 30, 2023 at 2:25

    Patches can be imported from GeoJSON files, along with others, using the Geopandas package.

    import geopandas,os
    
    mapPlot = heli.spatial(corners=True, geometry='geo')
    __location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
    gdf = geopandas.read_file(os.path.join(__location__, 'NC_Counties.geojson'))
    for i,county in gdf.iterrows():
        heli.patches.add(county['geometry'], county['CO_NAME'])
  2. Contribute a Note

    Your email address will not be published. Required fields are marked *

    You may use limited HTML for formatting. Please embed blocks of code in <pre><code> </code></pre> tags.

History