Posts

Showing posts from March 16, 2008

OGR python projection

OGR Projection

If you're using shapely and you need to do projections, you'll either have a lot of boilerplate or a function like this one. Actually, even in OGR, there's a lot of bioler plate involved in transforming....



from osgeo import ogr
from shapely.wkb import loads

def project(geom, to_epsg=900913, from_epsg=4326):
"""utility function to do quick projection with ogr,
to and from shapely objects
>>> from shapely.geometry import LineString
>>> l = LineString([[-121, 43], [-122, 42]])
>>> lp = project(l, from_epsg=4326, to_epsg=26910)
>>> lp.wkt
'LINESTRING (663019.0700828594854102 4762755.6415722491219640, 582818.0692490270594135 4650259.8474613213911653)'
"""

to_srs = ogr.osr.SpatialReference()
to_srs.ImportFromEPSG(to_epsg)

from_srs = ogr.osr.SpatialReference()
from_srs.ImportFromEPSG(from_epsg)

ogr_geom = ogr.CreateGeometryFromWkb(geom.wkb)
ogr_geom.Assi…

spatially explicit metapopulation models in scipy.

Image
Making Pretty Pictures
I started to learn to program about 5 years ago running population ecology models in mathematica. Yesterday, I found an old mma notebook with a model modified to include differential parasitoid dispersal to adjacent host cells depending on the host density in those cells. It's bascially a discrete-time Nicholson-Bailey model. But in a grid of cells, where each cell contains a population of hosts (H) and parasitoids (P) that give birth, die, eat, and get eaten according to the NB model. Each generation, following birth/reproduction/predation, the hosts and parasitoids disperse. The hosts disperse equally to the 8 surrounding cells in their neigbhorhood. The parasitoids can move irrespective of host densities when the aggregation parameter (eta) is 0. When aggregation is 1 (eta == 1), the parasitoids move to adjacent cells in exact proportion to host densities in each of the surrounding cells. muH and muP (i'm too lazy to figure out how to write the symbols…