1.12.11

Some GIS analysis

Ok, so I'm fed up of doing something in GIS, forgetting to write it down and then having to repeat the process due to an update of GIS data, or a change in my model needs etc that I am now trying to make a note of the main GIS analysis to get the data into some format that I can then use in my models, so here goes.

Data I need at the moment:
Habitat Map in raster format, cells of size 100m x 100m
Roads and trails, in raster format, cells of size 100x100
Cockscomb, raster - a simple map of where the protected forest is
CameraTraps - a shape file of the location of all 47 camera traps (in suitable projection to match the raster data
Sample area - a raster dataset of a buffer around the camera traps that represents the sampling area of the traps
Rivers, in raster formation, cells of size 100x100
Model Area, a shape file created to represent the area to be used in the model

Each of these datasets also needs to be of the same area (an annoying problem in some cases)

So, all data was provided in shape file format which meant it all had to be converted or processed and then converted to raster.

All information is relevant to ArcGIS version 9.3. (ArcMap unless otherwise stated).

HabitatMap
1. A simple conversion from 'feature to raster', using Ecosystem field as the field of interest and stating a cell size of 100.
[Conversion Tools - To Raster - Feature To Raster]

2. This raster then covered the entire area of Belize, so it needed to be clipped to meet the model area of interest. (I'll discuss how to create a shape file of the required area next), but otherwise use the 'clip' command. Some commands from the various toolboxes only work on specific types of dataset, such as the clip command within the Analysis Tools toolbox only works with feature/shapefile data and NOT with rasters. For Rasters, use the following, putting the shape file to use as the 'clipping' feature in the 'output extent' box and selecting the 'use input features for clipping geometry box', otherwise you can designate your own coordinates to create a rectangle to use to clip...

 [Data Management Tools - Raster - Raster Processing - Clip]

3. Now we should have a raster of cell size 100x100, but only having data for the required region/area of Belize. This now needs to be converted to an ASCII file for me to use and import into RePast.

[Conversion Tools - From Raster - Raster to ASCII]


Model Area
For this we need to create a new shape file and then amend it to create a new polygon for the area we want to use as our model area.

1. Open Arc Catalog, locate the folder you want the file to be created in.

2. Right click in the main box (showing contents of the folder you are looking at), go to New, and shape file. Then give it an appropriate name.

3. Ok, now go back into ArcMap and add the new shape file to the display.

4. Now you need to edit the shape file
[View (from the top bar) - Toolbars - Editor - Editor - Start Editing]

5. At this point, you may need to select the fold or database which you would like to edit. Select the folder which houses the newly created and added shape file, click OK.

6. Make sure the correct shape file is displayed in the Target box on the Editor Toolbar

7. Now you need to create a polygon of the area you want to be the model area
[Editor -More Editing Tools - Advanced Editing]

8. A new toolbox should have popped up called Advanced Editing. Select the rectangle icon (last but one on the right) and now you should be able to draw a rectangle within the correct shape file layer. You can have other layers open so you can see where to draw the rectangle. If the rectangle is selected it can also be deleted so it doesn't matter if it isn't correct first time. Once you have the area you are happy with, go back to the editor toolbar
[Editor - Save Edits- Stop Editing]

9. There should now be a shape file with a single polygon representing the outline of the model area you want to use. This shape file can now be used to 'clip' any dataset required (as in step 2 above).


Cockscomb
1. Ok, so I was given a dataset with all the protected areas outlined on it, as well as a single dataset with the outline of Cockscomb Basin Wildlife Sanctuary. This simply needed to be clipped to the model area (my model area only covers a portion of the sanctuary) and then converted to a raster and then ask ASCII.
So first, clip the polygon of Cockscomb, and use the newly created ModelArea file (above) as the 'clip features'
[Analysis Tools - Extract - Clip]

2. Now convert it to raster (you could also convert it to a raster first and then use the raster clip function (outlined above) to clip the raster).
[Conversion Tools - To Raster - Feature To Raster]

3. Now convert the raster to an ASCII file
[Conversion Tools - From Raster - Raster To ASCII]


Roads/Trails and Rivers
1. These are both done in the same manner so can be dealt with together. They came in polyline format (shape file) so they need processing and then converting to a raster. Firstly, they needed transforming form they current WGS-1984 projection to the required NAD1927-16N projection (all GPS and camera data information is in the latter format). This is relatively simple. If you have other data open when you add the roads/rivers data it will tell you it is in a different coordinate system and you can change it from that pop-up box, otherwise do the following:
[View (top bar) - Data Frame Properties - Coordinate System]

2. You should now see what coordinate system your current data is in, if it needs to be change:
[Transformations - Select the correct coordinate system in the 'Convert from' box and make sure the correct new coordinate system is in the 'Into' box, now select a transformation technique from the 'Using' box, (they should all do the same job), then press OK - Apply - OK] 
Data should now match.

3. Now the data is in the correct coordinate system, it needs to be processed. I had several different files that needed merging together to create a single file of the entire road/river network. This can be done several ways, but the easiest (and most effective) way I found was via the editor toolbox. I also needed to create some additional trails from point data supplied.

4. Creating new trails, need to create a new shape file layer in Arc Catalog (as above for the Model Area). Add the new empty layer into ArcMap. Display the data of points that represents the information you need. 
[View - Toolbars - Edtor - Editor - Start Editing]

5. Now all you need to do is draw over the points to create a line. The trick is to make lots of joins to make sure the line follows the points. Selecting the pencil icon on the editor toolbar allows you to draw onto the empty shape file layer. A single click make a join and a double click ends the current line. You can connect separate lines together at the end, so I zoomed in and make several lines that I then joined up at the end to create the entire trail network. Once all the lines have been drawn, you can then merge them.

 [Click on the arrow head on the editor toolbar - draw a large square around your newly created lines to select them all - Editor - Merge]

6. Now all the lines should be joined up but still selected. Selection(from top bar) - Clear Selected Features, will clear a selection at any time. Now you need to join the newly created trails with the several existing datasets. A similar process can work successfully, or you can do it via the Data Management Tools 
[Data Management Tools - General - Merge]

7. Now you should have one layer with all the relevant roads or rivers in. Now this needs to be clipped using the Model Area shape file.
[Analysis Tools - Extract - Clip]

8. Again now convert it to a raster and then to an ASCII file.

9. Some problem I encountered - the original roads data was given to me, not of the whole of Belize, but of a small area within the area I was using as my model area. Therefore the dataset was SMALLER than the model area I needed. Problem!

10. Much investigation didn't come up with a good process for extending the display of the dataset (it only needed additional NoData information to make up the entire area). You can extend the display of the layers 
[right-click on the layer - Properties - Extent - choose any layer in the 'set the extent to' drop down box]

11. Whilst this seemed to work when I converted the layer to a raster it lost this additional extent. So do this instead, you need to convert the ModelArea shape file to a raster and then add the two raster layers together:
[ModelArea = Conversion Tools - To Raster - Feature to Raster]
[View(top tool bar) - Toolbars - Spatial Analyst - Options - Extent - Union of Inputs] then
[Spatial Analyst - Raster Calculator - select the new raster of the modelArea then select the + and then select the roads raster file]

12. This should create a raster layer of the roads that same size as the modelArea. The raster layer of the ModelArea needs to have a non-negative, non-zero value (mine went to 1 automatically) so that this value is added to the value of the roads (I have 6 classes of roads all with a value from 1 to 6 representing the class). The values of my new raster went from 2 to 7 so I used the reclass function to put them back to 1 - 6, with the NoData values sticking at -9999. I had some problems converting these values to anything else in the reclass function so I left them at the default value.

[Spatial Analyst Tools - Reclass - Reclassify - choose the new roads raster and enter in the new values in the NewValues column in the box in the centre]

Camera Traps
1. These were fairly straightforward. I had the data as x and y coordinates in an excel spreadsheet. So add the spreadsheet to the ArcMap display:

[right click on the spreadsheet - Display XY Data - and choose the correct columns that represent the x and y data - choose the correct coordinate system, via - Edit - Select - Projected Coordinate Systems - UTM - NAD 1927 - NAD 1927 UTM Zone 16N.prj - Add]

2. You might then need to make the layer permanent, to do this you need to export it as a shape file:

[right-click on the new 'events' - Data - Export Data - then choose All Features in the 'Export' box and the folder you want in the 'Output shape file or feature class' box and give it a name you want - OK]

Sample Area
1. So this is the effective sampling area of my dataset - basically just a circle around each camera Trap of a specified radius - calculated from the average home range of a jaguar - 1784m in this case (half of the full estimated diameter of 3568m - taken from thesis if Rebecca Foster (currently working for Panthera in Belize and collaborating on this work)). So to do this you use the buffer function: 

[Analysis Tools - Proximity - Buffer - new cameraTrap file as the 'Input Features', choose an appropriate name and location for the output file, put the radius in the 'Linear Unit' box and make sure the next box is in the correct units]

2. This now needs to be converted to a raster and made the same size as the modelArea, then converted to an ASCII.

All these files need to be converted to .pgm files (apart from the cameraTraps) for importing into RePast. I'll cover this in a later post.


Book

An interesting new book but Alison Heppenstall, Andrew Crooks, Linda See and Mike Batty
"Agent-Based Model of Geographical Systems"





as stated on Andrew Crooks' blog 'GIS and agent-based modelling':

[the book] brings together a comprehensive set of papers on the background, theory, technical issues and applications of agent-based modelling (ABM) within geographical systems. This collection of papers (see below) is an invaluable reference point for the experienced agent-based modeller as well those new to the area. Specific geographical issues such as handling scale and space are dealt with as well as practical advice from leading experts about designing and creating ABMs, handling complexity, visualising and validating model outputs. With contributions from many of the world’s leading research institutions (see map below), the latest applied research (micro and macro applications) from around the globe exemplify what can be achieved in geographical context.


This book is relevant to researchers, postgraduate and advanced undergraduate students, and professionals in the areas of quantitative geography, spatial analysis, spatial modelling, social simulation modelling and geographical information sciences.

Book Contents:

Part 1: Computational Modelling: Techniques for Simulating Geographical Systems
  1. Perspectives on Agent-Based Models and Geographical Systems.
  2. A Generic Framework for Computational Spatial Modelling.
  3. A Review of Microsimulation and Hybrid Agent Based Approach.
  4. Cellular Automata in Urban Spatial Modelling.
  5. Introduction to Agent-Based Modelling.
Part 2: Principles and Concepts of Agent-Based Modelling.
  1. Agent-Based Models - Because they're Worth it?
  2. Agent-Based Modelling and Complexity.
  3. Designing and Building an Agent-Based Model.
  4. Modelling Human Behaviour in Agent-Based Models.
  5. Calibration and Validation of Agent-Based Models of Land Cover Change.
  6. Networks in Agent-Based Social Simulation.
Part 3: Methods, Techniques and Tools for the Design and Construction of Agent-Based Models: 
  1. The Integration of Agent-Based Modelling and Geographical Information for Geospatial Simulation.
  2. Space in Agent-Based Models.-
  3. Large Scale Agent-Based Modelling: A Review and Guidelines for Model Scaling.
  4. Uncertainty and Error.-
  5. Agent-Based Extensions to a Spatial Microsimulation Model of Demographic Change.
  6. Designing, Formulating, and Communicating Agent-Based Models.-
  7. Agent Tools Techniques and Methods for Macro and Microscopic Simulation.
Part 4: Fine-Scale, Micro Applications of Agent-Based Models: 
  1. Using Agent-Based Models to Simulate Crime.
  2. Urban Geosimulation.
  3. Applied Pedestrian Modelling.
  4. Business Applications and Research Questions using Spatial Agent-Based Models.
  5. Using Agent-Based Models for Education Planning. Is the UK Education System Agent Based?
  6. Simulating Spatial Health Inequalities.
  7. ABM of Residential Mobility, Housing Choice and Regeneration.-
  8. Do Land Markets Matter? A Modelling Ontology and Experimental Design to Test the Effects of Land Markets for an Agent-Based Model of Ex-urban Residential Land-Use Change.
  9. Exploring Coupled Housing and Land Market Interactions Through an Economic Agent-Based Model (CHALMS).
Part 5: Linking Agent-Based Models to Aggregate Applications Macro:
  1. Exploring Urban Dynamics in Latin American Cities using an Agent-Based Simulation Approach.
  2. An Agent-Based/Network Approach to Spatial Epidemics.
  3. An Agent-Based Modelling Application of Shifting Cultivation.
  4. Towards New Metrics for Urban Road Networks. Some Preliminary Evidence from Agent-Based Simulations.
  5. A Logistic Based Cellular Automata Model for Continuous Urban Growth Simulation: A Case Study of the Gold Coast City, Australia.
  6. Exploring Demographic and Lot Effects in an ABM/LUCC of Agriculture in the Brazilian Amazon.
  7. Beyond Zipf: An Agent Based Understanding of City Size Distributions.
  8. The Relationship of Dynamic Entropy Maximising and Agent Based Approaches in Urban Modelling.
  9. Multi-Agent System Modelling for Urban Systems: The Series of SIMPOP Models.
  10. Reflections and Conclusions: Geographical Models to Address Grand Challenges
Looks particularly interesting but I'll be waiting to hear a few more reviews before I take the plunge and buy it on impulse. Very interesting though....

3.11.11

VERY relevant paper from 2001

I just found an extremely relevant paper form 2001 where someone has actually implemented an agent-based model of panther movements to explore the feasibility of re-introducing panthers to a location in Northern Florida.

The paper doesn't explicitly acknowledge its agent-based modelling methodology, but it definitely uses ABMs to model panthers moving around a real landscape. There are many similarities to my work here. The exact methodology does differ but is essence they have panthers looking at neighbouring cells, choosing a location and moving to that location, based on habitat, prey resource, roads and human density, whilst simultaneously interacting with other panthers in the area.

This is THE paper to reference.

And I am one very happy camper! :)

Reference:
Cramer, P.C. & Portier, K.M. (2001) Modelling Florida panther movements in response to human attributes of the landscape and ecological settings. Ecological Modelling 140: 51-80
(available from ScienceDirect, or Mendeley).

1.11.11

Habitat preference and territory development

Getting jaguar agents to mimic real-life individuals and create territories is one of the most important features to try and get right in this type of agent-based model.

Exploring the way jaguars move through landscapes involves understanding how they interact with each other and with the environment. Territory formation and avoidance (or not) of conspecifics are integral to getting these interactions to be as close to mimicking those found in real populations as possible.

So.... some kind of pheromone seems that it should elicit an easy territory response in the agents. 'Marking' each cell with some level of pheromone as the agents move into and out of the cell and then allowing this 'pheromone' to degrade over time should allow territories to organically emerge during the simulation and with a bit of tweaking as to how quickly the pheromones should degrade and how 'strong' they should be to other individuals and to themselves.

The main idea is that individuals should not want to re-trace their steps too often, and that generally individuals should try and avoid each other - either due to possible conflicts between adults and due to resource depletion.

We know a bit about how large and flexible territories are in wild jaguar populations and so we settled on a maximum pheromone level of 100, with a degradation rate of 0.98, so that the pheromone reduced by 0.02% each timestep. This gave realistic territory sizes.

The strength of the pheromone is equal to its level, except for an agents own pheromone which is reduced to 0.15% of its current level; a deterrent to re-entering the cell but not enough to mean that the individual would not want to re-treat to its territory if meeting another individual or unsuitable habitat was the only other option.

The addition of pheromones, and the basic least-cost model idea of the simulation led to the following output, where clearly define territories (individuals in different colours) and habitat preferences can be seen:



Some individuals have been 'pushed' out of the forest area due to the population size. This is intentional. A higher number of individuals creates stress for any single individual. Without some level of stress, individuals will be content on remaining in fairly isolated areas. Some stress is needed in order for individuals to move and seek new areas in which lead a lifestyle of least-cost, so prompting the migration of individuals from one side of the landscape to the other.

14.10.11

Jaguar vs Leopard Identification

I found this and thought it summed things up pretty well for anyone not sure on what the differences are between a jaguar and a leopard.


Jaguars also live in central and south America, whilst Leopards are found in central and southern Africa  and parts of Asia.
Jaguars also tend to be heavier and stockier than their leopard cousins.

p.s. The Leopard scientific name should read Panthera Pardus.

20.9.11

1st jaguar simulation model

With my case study involving complicated landscape structures and real-world scenarios, I needed to first get to grips with getting an agent-based model of jaguar movements up and running in a simplified landscape that would enable some interpretation of population dynamics without the need for an in-depth and overly detailed landscape.
After discussing several options, a very abstract and basic landscape structure was decided on to try to answer some fundamental questions important to my on-going research:

1) Can we get a model of jaguar movements working, with plausible daily movements and territory sizes close to those found in real world populations?

2) Does landscape structure seem to influence the way jaguars move around the landscape and does it affect the fitness of individuals and the population as a whole?

3) Can habitat corridors help to increase the connectivity of the landscape and facilitate movement of individuals between habitat patches?

9 landscape structures were defined to help explore these questions, including 3 control landscapes (top row), 3 connected corridors (middle row) and three non-connected corridors (bottom row) :




'Good' habitat here is forest (in green). This is where jaguars will prefer to be. Intermediate habitat is marked in blue, and represented edge habitat; the edge of the forest that meets the non-forest habitat. This is deemed to be less desirable than the forest itself but more desirable than the non-forest habitat. Non-forest (matrix) is coloured beige, and represents any habitat where the jaguar do not want to be; urban areas, agricultural land, roads etc etc.

Landscapes were designed to cover a range of potential options. All designs (bar the first two; the all forest and the 2 distinct habitat patches) have exactly the same amount of forest and matrix habitat. Edge habitat changes depending on the design of the landscape.

The model is designed as a grid, with individual jaguars occupying any one grid cell at a time. Least-cost methodologies are employed so that each habitat has a cost; forest of 1, edge of 5 and non-forest (or matrix) as 25. This represents the strength of the preference of jaguars to any habitat (lower cost equals a much stronger preference).


Next post - more information about jaguar movements and getting territories to develop.













14.9.11

Jaguars as a case study

Ok,

So now I have all things technical working and sorted I can continue discussing my actual work :)

I've mentioned that my work has its roots in ongoing fieldwork in Belize. My target species is the Jaguar: an apex predator, the third largest feline in the world (behind the lion and the tiger) and a probable keystone species: the jaguar plays an important role in stabilising and controlling the ecosystems in which they are found.


Jaguars were historically found from the southern United States to northern Argentina, although this range has been reduced but up to 40-50%, with much of the existing area more highly fragmented and vulnerable to disturbance.



Territories of typical individuals range from approximately 10-40km2 for females to 30-80 km2 for males. Density varies a lot, with maybe 0.2 per 100km2 in some areas of Brazil to 8-10 per 100km2 in the Cockscomb Basin Wildlife Sanctuary in Belize.

The main reasons for this flexibility and variability in density and territory size is thought to centre around prey density and availability and amount/quality of habitat.  Belize has some of the highest density of Jaguars throughout its entire range.

Jaguars are, in their own right, deserved of conservation efforts. However, with their large ranges and daily movement requirements (up to 4km in a single day), any effort to conserve habitat for jaguars will lead to extensive biodiversity preservation, with numerous species and vegetation communities protected within the cats range.

The jaguar can therefore be viewed in the basic sense as an indicator of the quality and extend of suitable habitat in any landscape. My modelling efforts use the jaguar as a case study, to promote jaguar conservation itself but also to address larger scale ecosystem function and resilience questions.








2.9.11

GRASS GIS

I'm now mainly working on Mac OS so using ArcGIS is becoming a bit of a problem. I have it on my Del laptop, but this is getting a bit slow now and it takes a while to do anything with the big datasets that I need to use of Belize. I also have VMWare on my iMac, but its linked to my university desktop environment, rather than being standalone and so the whole windows experience is quite a painful one.

Roll in - GRASS. An open source GIS package, find more information here.
GRASS works on any platform which makes it appear a good choice. I've yet to test its capabilities but I'll be updating my progress with it in the near future.

To get GRASS working, it requires three frameworks (GDAL Complete, Freetype and Cairo) to be installed prior to installing the GRASS package. Find them, and more info at www.kyngchaos.com/software/grass.


1.9.11

Some useful technical information

If the eclipse.ini file needs editing, (to increase memory or 'Java heap space') this can be found easily by going through the eclipse directory in Windows. In Mac OSX, go to eclipse.app, right-click, open package contents, contents, Mac OS, then open the eclipse.ini file in text edit.

JDK and JRE are needed for model development. The Java Runtime Environment is needed to run the java applications, the Java Development Kit is needed to develop java applications.

Subversion needs to use the SVNKit rather than the JavaHL in eclipse. This is true for Windows and Mac OS.
Subversion also brings problems when trying to save the scenario in repast. The projectName.rs folder and the styles sub folders both need to be un-checked as read-only. I've found this problem with both Windows and MacOS. In Windows, a secondary projectName.rs.bak folder is created if saving the scenario encounters this problem. In this case the subfolders and files need to be moved back into the projectName.rs folder and the projectName.rs.bak folder deleted. This doesn't seem to occur in Mac OS.

JOGL and Java3D jar files can be downloaded and installed directly from the repast homepage; http://repast.sourceforge.net/download-extras.html, again this is true for Windows and Mac OS.
Java3D files allow applications with 3D displays to run.
JOGL is Java OpenGL which is a wrapper that allows OpenGL to be used, necessary for repast models to run successfully.

Python plugin for eclipse - need to also download ActiveTcl (currently version 8.5.10 as of Sept 11) to allow use of TKinter.

GeoTools seems to be a set of java open source code library classes which provide standard compliant methods for manipulation of geospatial data. Should allow use of raster files, without converting to .pgm files. Currently testing this as of Sept 11.
There is a website dedicated to the open source files - http://geotools.org/
My current version of eclipse seems to have access to these class files without the need to download anything extra. The geoTools website seems to indicate you need to download and install the GeoTools code into both eclipse and netBeans. Will update when I know more.

24.8.11

Demo models for repast

After struggling to remember how to get access to the repast demo models, which are EXTREMELY helpful when trying to figure out how repast works, they can be downloaded from http://repast.sourceforge.net/models.zip

After extracting the files, get the models into Eclipse easily by:
1. Select File -> Import Repast Examples from the Eclipse main menu
2. Check Select root directory: /home/rlr/Repast/Repast-Models/models (not: Select archive file)
3. Check the boxes for the example projects you would like to import select all copy projects into workspace
4. Click Finish
Now they all appear in the packages panel

On a Mac eveything should work fine, if working on Windows there may now be problems running some of the example models due to JOGL and Java3D errors.

Meghan Hutchins provides an excellent outline of how to fix these errors, please see the link on the left to her blog, or else click here for the specfici pages related to demo models and how to fix errors that may occur. (User guide to Eclipse/Repast)
http://meghanhutchins.com/pmwiki.php/Main/InstallJava3DLibraries

19.7.11

Eclipse plugins and configurations

Ok, so now I've moved on from netlogo, the decision of which interface and language to use is a pretty big one. After some considerable time looking into the pros and cons of different languages I settled on java, with its flexible use and wealth of support information available.

I trialled NetBeans for a while which I quite liked, but then settled on Eclipse after some recommendations from friends. The brilliant thing with Eclipse is also that i can use it for more or less EVERYTHING! Via plugins, I now use it as my base for java, python and LaTeX, linking it up to my university server repository via the subclipse plugin.

Some details on setting up plugins is as follows (all configured for the most recent Eclipse Indigo):

For LaTeX:
Texclipse - found at http://texlipse.sourceforge.net
In eclipse, go to Help > Install New Software > type the above URL in the  'work with' box and press 'Enter'
select the texlipse box and press next until the process is finished.

For Version Control
Subclipse - found at http://subclipse.tigris.org/update_1.6.x (this is the version for Eclipse Helios. There is currently no updated version for Indigo)

Again, go to Install New Software and enter the URL above.

After installing this there are several things to note. Using a windows machine, I had problems using the JavaHL interface, so I recommend using the SVNKit bundle instead (go to Windows > preferences > team > SVN > SVN interface - choose SVNKit.)

In order to checkout a project from an online repository:
go to the required perspective, right click > import > SVN > checkout from SVN > put the repository location in the URL, for me this was svn+ssh://username@svn.forge.ecs.soton.ac.uk/folder/repositoryProjectName

You dont seem to need the Tortoise SVN programme that is recommended for Windows machines if you use the subclipse plugin.

For Python
Pydev - found at http://pydev.org/updates

Install new Software > enter in URL > select Pydev (NOT PyDev Mylyn Integration)
> click next to finish.
A box should pop up asking you to trust the certificates, YOU NEED TO SELECT THE Antana PyDev; Pydev; Aptana CHOICE, OTHERWISE PYDEV WILL NOT INSTALL
You then need to restart Eclipse

Pydev then needs configuring - you need python already installed on your computer
Windows > preferences > pydev > interpreter Python > new > then browse to the current version of Python.exe > ok > select all of the options EXCEPT PySrc and python.zip > then ok as many times as needed to end the process

All of the information on the PyDev plugin and more can be found on:
www.rose-human.edu/class/csse/resources/Eclipse/eclipse-python-configuration.htm

For Repast Simphony
You need three separate installations for this plugin
1. Groovy-Eclipse
found at http://dist.springsource.org/release/GRECLIPSE/e3.7/ (3.7 refers to the version for Indigo, older version of eclipse will need the relevant version of groovy)
2. Web, XML & Java EE development
found at http://download.eclipse.org/releases/indigo (again you need the relevant site for the eclipse version you have)
under the Eclipse XML editors and Tools menu
3. Repast
found at http://mirror.anl.gov/pub/repastsimphony/2.0.0.beta

there are a LOT of example models available within the repast plugin that show a great range of things that repast can do.

I'm currently trying to work my way around repast, I hope to have more on this at a later date.

27.6.11

Student Conference on Complexity Science

If you are a PhD student researching a complexity science problem, then you are invited to submit an abstract for the first annual Student Conference on Complexity Science. This conference is an opportunity for postgraduate students to network and meet others in the complexity science community.

The SCCS will be held at the Stripe Theatre, Winchester University, from 5th to 6th of August 2011; attendance is free of charge. All prospective attendees to the conference must submit an abstract, and be prepared to either give a 20 minute talk, or to present a poster to share their research.

Due to the interdisciplinary nature of complex systems, research presented at this conference is expected to span a broad range of scientific disciplines. Work may be theoretical or applied and, for example, could cover social systems, networks, ecosystem dynamics, evolution, or non-linear systems.

Prizes will be awarded for the best presentation and for the best poster at the close of the conference.
If you are interested in presenting your work at this conference, please submit an abstract to sccs@soton.ac.uk by 8th July in the following format:
  • Email subject: ABSTRACT - Poster/Presentation (please specify your preference)
  • Project title
  • Your name, University/department and supervisor(s)
  • Contact information
  • The abstract, which must have a maximum of 250 words and should outline your project, summarise your methodology and results, and include any conclusions you have drawn.
If you have any queries, please do not hesitate to contact the SCCS organisation team on sccs@soton.ac.uk.

24.6.11

PhD - first step

So first year over, now its on to some new research.


My first thought was, where do I go next?

My PhD is aimed at a real-life problems. My case study is a corridor area in Belize, in central america.

The issues remain the same as with the hedgehog work. How do mammals move through the landscape? How will increased habitat fragmentation affect the movement of mammals through the landscape? How do we measure landscape permeability? How can we best model the effects of landscape structure on the movement of mammals in a landscape?


These questions have huge implications on the persistence of populations in a landscape and on the amount of disturbance and development that a landscape can absorb before a population reaches a threshold tipping point. My research is really focused on questions surrounding ecosystem function and resilience.
"To halt the decline of an ecosystem, it is necessary to think like an ecosystem."
Douglas P. WheelerEPA Journal,September-October 1990
The overall goal of my research is to attempt to understand how a species views and interacts with its environment. Exploring these issues and gaining some understanding of the relationship between animals and their environment can help us understand ecosystems function and how anthropogenic processes may affect ecosystem processes.

15.6.11

Final thoughts on Netlogo model

I was really happy with how things turned out with my first foray into agent-based modelling.

My friend Melissa first got me interested in Netlogo and I have to say it was a perfect choice for a short-term relatively simplified and low-level model. I avoided the necessity of having to learn a new programming language as I found the netlogo language easy, intuitive and quick to pick up.

I would recommend anyone new to programming or agent-based modelling to start with something like Netlogo to break yourself in gently.

Some negatives, however, obviously I am no expert at netlogo modelling, but my first experience left me feeling that the scope of the language was limited and that if I wanted to explore some more complicated and detailed modelling options then I would need to progress to a language that allowed me more freedom. The level of automatic generation of output and ready-made agents and patches makes netlogo an ideal starting point, but not necessarily an ideal language to really start exploring what agent-based modelling can do.

next post: java

13.6.11

Netlogo Code (summer project)

breed [randomH]    ;; create two breeds of turtle to compare random walks vs the 'real' hedghogs in any landscape
breed [hedgehog]
breed [arable]
breed [ pasture]
breed [ garden]
breed [ wood]
breed [ water]
breed [ urban]
breed [ road]

turtles-own [energy Harable Hpasture Hwood Hgarden Hwater Hurban Hroad]                ;;energy relates to the cost of the path taken by the hedgehogs

patches-own [habitat cost visit]    ;; habitat assigns a land-cover type to each patch colour  
                                    ;;includes the cost of the habitat as a patch feature - allowing hedgehogs to search for low cost patches


globals [timestep time hour]


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  setup patches and turtles   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to setup
  clear-all
  set time 0
  set hour 0
  set timestep 1
  setup-patches
  setup-turtles
end

to setup-turtles                        ;; creates 10 of each breed, assigning the paw footprint for an icon.  create-randomH Number-of-Random-Hedgehogs-red ;; the random hedgehogs are red, the 'real' are white.   create-hedgehog Number-of-Non-Random-Hedgehogs-white
    ask turtles [set shape "hedgehog paw"]  ;;this is the footprint other renamed to hedgehog - the closest icon resembling a hedgehog!  ask turtles [
    if breed = randomH [set color red]
    if breed = hedgehog [set color white]         ;;need to find a colour that shows on map and on the plot  ]
  ask turtles [setxy random-xcor random-ycor]   ;; sets the newly created turtles at random locations on the map  end

                                        
to setup-patches 
  colour-turtles
  ask turtles [repeat 100 [expand-habitats] ]         ;; proportions are supposed to be approx pasture/arable - 30%, garden/urban - 10%, wood - 13%, roads - 5%, water - 2%  ask patches [
    ifelse show-cellcosts? [
      set plabel cost] [
      set plabel ""]
    ifelse show-habitat? [
      set plabel habitat] [
      set plabel ""]
      ]
  ask patches [set visit 5]
  ask patches [
    if pcolor = yellow [set cost 150 set habitat "arable"]
    if pcolor = green [set cost 10 set habitat "pasture"]
    if pcolor = brown [set cost 1 set habitat "wood"]
    if pcolor = lime [set cost 5 set habitat "garden"]
    if pcolor = grey [set cost 15 set habitat "urban"]
    if pcolor = blue [set cost 300 set habitat "water"]
    if pcolor = black + 2 [set cost 150 set habitat "road"]
  ] 
  ask patches [
    if random 100 <= fragmentation-of-habitats
    [swap self one-of patches]
    ]
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  go statement   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 
to go                   ;;need to include all procedures here if they are required to run during the model run
  set time time + 1
  set hour (time * timestep)
  cost-path
 
  if hour mod 24 >= 6 and hour mod 24 < 18 [
  move-randomH
  ifelse day-and-night-mode? [
    repeat 10 [move-hedgehog-day]][
    move-hedgehog]
  ]
 
  if hour mod 24 >= 18 or hour mod 24 < 6 [
  move-randomH
  ifelse day-and-night-mode? [
    repeat 10 [move-hedgehog-night]][  ;; this increments tick counter by one everytime the model completes a single turn of each procedure
    move-hedgehog]
  ]
 
  do-plots      
  if days = Number-of-days [stop]  ;; allows output to run faster as it updates after every tick onlyend
 

;;;;;;;;;;;    do reports on interface for length of time passed in the model  ;;;;;;;;;;;;;;;;;

 
to-report days
  report hour / 24
end

to-report hours
  report hour - (floor days * 24)
end
 
 
;;;;;;;;;;;;;;     defines how to create the landscape ;;;;;;;;;;;;;;;;;;;;;;;;;;; 

to colour-turtles                                        ;; creates 7 turtles, one for each of the habitats
  create-arable 1
  create-pasture 1
  create-wood 1
  create-garden 1
  create-water 1
  create-urban 1
  create-road 1 
  ask turtles [
    set Harable 312
    set Hpasture 313
    set Hwood 173
    set Hgarden 107
    set Hwater 19
    set Hurban 107
    set Hroad 51]
  ask turtles [
    if breed = arable [set color yellow]
    if breed = pasture [set color green]
    if breed = wood [set color brown]
    if breed = garden [set color lime]
    if breed = water [set color blue]
    if breed = urban [set color grey]
    if breed = road [set color black + 2]                                       
  ]                                     
  ask turtles [
    setxy random-xcor random-ycor
    hide-turtle
    move-to patch-here
    set pcolor color]  ;; puts turtles in a random place in landscape and sets patch color to turtle colourend

to expand-habitats
  ifelse (Harable = 0) and (Hpasture = 0) and (Hwood = 0) and (Hgarden = 0) and (Hwater = 0) and (Hurban = 0) and (Hroad = 0) [stop] [
    expand-habitatarable
    expand-habitatpasture
    expand-habitatwood
    expand-habitatgarden
    expand-habitatwater
    expand-habitaturban
    expand-habitatroad
  ]
end 

;;;;;;;;;;;;;functions for 'building' habitats from scratch ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; one run of each function only creates 8 cells. The functions need to be repeated in order to create the appropriate number of cellsto expand-habitatarable
  ask arable [
    if all? patches [pcolor != black] [stop]
    if Harable = 0 [stop]
    ifelse all? neighbors [pcolor != black]
      [move-to one-of patches with [pcolor = black]
        set pcolor color
        reduce-colours]
      [ifelse all? neighbors4 [pcolor != black] [
         move-to one-of neighbors with [pcolor = black]
         set pcolor color
         reduce-colours
         ][
         move-to one-of neighbors4 with [pcolor = black]
         set pcolor color
         reduce-colours]
         ]
  ]
end

to expand-habitatpasture
  ask pasture [
    if all? patches [pcolor != black] [stop]
    if Hpasture = 0 [stop]
    ifelse all? neighbors [pcolor != black]
      [move-to one-of patches with [pcolor = black]
        set pcolor color
        reduce-colours]          
      [ifelse all? neighbors4 [pcolor != black] [
         move-to one-of neighbors with [pcolor = black]
         set pcolor color
         reduce-colours
         ][
         move-to one-of neighbors4 with [pcolor = black]
         set pcolor color
         reduce-colours]
  ]
  ]
end

to expand-habitatwood
  ask wood [
    if all? patches [pcolor != black] [stop]
    if Hwood = 0 [stop]
    ifelse all? neighbors [pcolor != black]
      [move-to one-of patches with [pcolor = black]
        set pcolor color
        reduce-colours]       
      [ifelse all? neighbors4 [pcolor != black] [
         move-to one-of neighbors with [pcolor = black]
         set pcolor color
         reduce-colours
         ][
         move-to one-of neighbors4 with [pcolor = black]
         set pcolor color
         reduce-colours]
  ]
  ]
end

to expand-habitatgarden
  ask garden [
    if all? patches [pcolor != black] [stop]
    if Hgarden = 0 [stop]
    ifelse all? neighbors [pcolor != black]
      [move-to one-of patches with [pcolor = black]
        set pcolor color
        reduce-colours]         
      [ifelse all? neighbors4 [pcolor != black] [
         move-to one-of neighbors with [pcolor = black]
         set pcolor color
         reduce-colours
         ][
         move-to one-of neighbors4 with [pcolor = black]
         set pcolor color
         reduce-colours]
      ]
  ]
end

to expand-habitatwater
  ask water [
    if Hwater = 0 [stop]
    if all? patches [pcolor != black] [stop]
    ifelse all? neighbors [pcolor != black]
      [move-to one-of patches with [pcolor = black]
        set pcolor color
        reduce-colours]          
      [ifelse all? neighbors4 [pcolor != black] [
         move-to one-of neighbors with [pcolor = black]
         set pcolor color
         reduce-colours
         ][
         move-to one-of neighbors4 with [pcolor = black]
         set pcolor color
         reduce-colours]
      ]
  ]
end

to expand-habitaturban
  ask urban [
    if all? patches [pcolor != black] [stop]
    if Hurban = 0 [stop]
    ifelse all? neighbors [pcolor != black]
      [move-to one-of patches with [pcolor = black]
        set pcolor color
        reduce-colours]         
      [ifelse all? neighbors4 [pcolor != black] [
         move-to one-of neighbors with [pcolor = black]
         set pcolor color
         reduce-colours
         ][
         move-to one-of neighbors4 with [pcolor = black]
         set pcolor color
         reduce-colours]
      ]
  ]
end

to expand-habitatroad
  ask road [
    if all? patches [pcolor != black] [stop]
    if Hroad = 0 [stop]
    ifelse all? neighbors [pcolor != black]
      [move-to one-of patches with [pcolor = black]
        set pcolor color
        reduce-colours]
      [ifelse all? neighbors4 [pcolor != black] [
         move-to one-of neighbors with [pcolor = black]
         set pcolor color
         reduce-colours
         ][
         move-to one-of neighbors4 with [pcolor = black]
         set pcolor color
         reduce-colours]
      ]
  ]
end

;;;; function to reduce number of habitat cells by one each time a new cell is created ;;;;;

to reduce-colours
  let tempcolor 0
  set tempcolor [pcolor] of patch-here
  if tempcolor = yellow [set Harable Harable - 1]
  if tempcolor = green [set Hpasture Hpasture - 1]
  if tempcolor = brown [set Hwood Hwood - 1]
  if tempcolor = lime [set Hgarden Hgarden - 1]
  if tempcolor = blue [set Hwater Hwater - 1]
  if tempcolor = grey [set Hurban Hurban - 1]
  if tempcolor = black + 2 [set Hroad Hroad - 1]
end

;;;;;;;;;;;;; don't allow a turtle to re-visit a cell it has visited recently ;;;;;;;;;;;;;

to swap [original new]
  let oldcolor 0
  let newcolor 0
  ask original [set oldcolor pcolor]
  ask new [set newcolor pcolor]
  ask original [set pcolor newcolor]
  ask new [set pcolor oldcolor]
end

;;;;;;;;;;;;;;;;;;;;;;;;   move turtles   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 
to move-randomH
  ask randomH [pen-down]                             
  ask randomH [right random 360 forward 1]
end

to move-hedgehog
  ask hedgehog[pen-down]
  ask patches [set visit visit - 1]
  ask hedgehog [
      face one-of neighbors with-min [cost]
      forward 1]
end

to move-hedgehog-day ;; if patch is not wood, move to lowest cost cell until you reachwood  ask hedgehog [pen-down]    ;; ensure hedgehogs reach desired colour before the function finishes  ask patches [set visit visit - 1]
  ask hedgehog [ 
    ifelse pcolor = brown
       [stop]
       [face one-of neighbors with-min [cost]
        forward 1]
      ]                        
end

to move-hedgehog-night ;;if patch is not preferred eating habitat, move to the lowest cost cell until you reach a preferred eating habitat  ask hedgehog [pen-down]
  ask patches [set visit visit - 1]
  ask hedgehog [
    if (pcolor = green) or (pcolor = lime) [stop]
    ifelse any? neighbors with [pcolor = lime] [
      face one-of neighbors with [pcolor = lime]
      forward 1][
        ifelse any? neighbors with [pcolor = green] [
          face one-of neighbors with [pcolor = green]
          forward 1][
            face one-of neighbors with-min [cost]
            forward 1]
      ] 
  ]                                  
end

;;;;;;;;;;;;;;;evaluate the cost of each path taken by a turtle    ;;;;;;;;;;;;;;;;;;;;;

to cost-path                       ;;ok this is the cost of the path taken by the hedgehogs so far in the model....
  ask turtles [
      if pcolor = green [set energy energy + 10]
      if pcolor = grey [set energy energy + 15]
      if pcolor = brown [set energy energy + 1]
      if pcolor = lime [set energy energy + 5]
      if pcolor = black + 2 [set energy energy + 150]        
      if pcolor = blue [set energy energy + 300]
  ]
  ask turtles [
    ifelse show-costpaths?
    [set label energy]
    [set label ""]
  ]
end 

;;;;;;;;;;draw the plots for mean path cost for both turtle breeds   ;;;;;;;;;;;;;;;;
 
to do-plots                               ;;this sets up and runs the plot box in the interface screen. titles need to match EXACTLY in order for it to work.
  set-current-plot "Average Total Path Cost for Random and Non-Random Hedgehogs"
  set-current-plot-pen "Random Hedgehogs"
  plot mean [energy] of randomH
  set-current-plot-pen "Non-Random Hedgehogs"
  plot mean [energy] of hedgehog
end

Netlogo models

Ok, so now I've tested some least-cost models against empirical data of hedgehog dispersal I can use the best-fit least cost model as the basis for some exploratory agent-based simulations.

Luckily there was one clear winner in the least-cost model analysis so I can be fairly confident that this provides a good fit to the way that hedgehoge actually view and move around the landscape. With this in mind I simplified things abit by reducing the number of habitat types from 22, from the original GIS maps, to 7 in the simulations. Whilst this sounds dramatic, it was logical and simply meant lumping all water features together into a single habitat, all urban features together etc. Most of the habitats that we lumped together were given the same cost value anyway, but to clarify, this is how I simplified the landscape:

The proportions of each landscape were for the most part arbitrary, although were estimated from the original GIS maps.

So.... Netlogo. The building of the model was fairly straightforward. Netlogo is brilliant at making it easy to get something up and running fairly quickly. Turtles represent agents and the simplified language and syntax of netlogo makes it really easy to get the turtles to move around in a random direction at every time step.

Of course, by using the least-cost model as a base, turtles were amended so that they searched the cells in their immediate neighbourhood and moved to the cell of the least cost. Sample code is below:

to move-hedgehog
  ask hedgehog[pen-down]
  ask patches [set visit visit - 1]
  ask hedgehog [
      face one-of neighbors with-min [cost]
      forward 1]
end

The biggest problem I faced with the enitre netlogo model was how to construct the landscape. It is easy to generate different habitats by stating which cells to be of which colour(habitat). What is much harder to get a landscape to develop on its own, randomly each time the simulation is run, and then for the landscape to represent some level of fragmentation. This was particularly tricky and get me and my supervisor busy for a while in coming up with suitable ideas. In the end, we 'seeded' the habitats, so that each habitat started at a random cell and moved outward to neighbouring cells. If the cell it wanted to convert to its habitat is alreayd assigned it jumps to a free random cell on the landscape.

Netlogo code (this was done for each of the 7 habitat types):

to expand-habitatarable
  ask arable [
    if all? patches [pcolor != black] [stop]
    if Harable = 0 [stop]
    ifelse all? neighbors [pcolor != black]
      [move-to one-of patches with [pcolor = black]
        set pcolor color
        reduce-colours]
      [ifelse all? neighbors4 [pcolor != black] [
         move-to one-of neighbors with [pcolor = black]
         set pcolor color
         reduce-colours
         ][
         move-to one-of neighbors4 with [pcolor = black]
         set pcolor color
         reduce-colours]
         ]
  ]
end

the method to used to call the habitat methods:

to expand-habitats
  ifelse (Harable = 0) and (Hpasture = 0) and (Hwood = 0) and (Hgarden = 0) and (Hwater = 0) and (Hurban = 0) and (Hroad = 0) [stop] [
    expand-habitatarable
    expand-habitatpasture
    expand-habitatwood
    expand-habitatgarden
    expand-habitatwater
    expand-habitaturban
    expand-habitatroad
  ]
end

Fragmentation was achieved by swapping cells with other random cells at a given probability. 50% probability of swapping leads to 100% fragmentation. (The definition of fragmentation is actually really difficult to find so this is a good enough demonstration for these purposes):


The extension to the model involved giving the hedgehogs a bit more realistic behaviour, so instead of simply choosing the nearest cell with the lowest cost at every step, they mimicked real hedgehogs by choosing habitat depending on the time of day: i.e. during the daytime, they preferred cover (forest) as they would in reality in order to rest, and during the night time they preferred areas where they could feed (pasture, gardens etc):

to move-hedgehog-day                        
  ask hedgehog [pen-down]                  
  ask patches [set visit visit - 1]
  ask hedgehog [ 
    ifelse pcolor = brown
       [stop]
       [face one-of neighbors with-min [cost]
        forward 1]
      ]                        
end

to move-hedgehog-night                      
  ask hedgehog [pen-down]
  ask patches [set visit visit - 1]
  ask hedgehog [
    if (pcolor = green) or (pcolor = lime) [stop]
    ifelse any? neighbors with [pcolor = lime] [
      face one-of neighbors with [pcolor = lime]
      forward 1][
        ifelse any? neighbors with [pcolor = green] [
          face one-of neighbors with [pcolor = green]
          forward 1][
            face one-of neighbors with-min [cost]
            forward 1]
      ] 
  ]                                  
end

I'm currently trying to find a way to upload the netlogo model as an applet and will post it when I can. The code to the full model can be found in the links on the left.
In a nutshell, by looking at the average cost of a path taken by any hedgehog in any landscape, if you look at the hedgehogs that move simply by least-cost pathways, the average cost of path increases dramatically as the landscape becomes more fragmented. If you look at the hedgehogs with some differentation between night and day, then there average path cost stays more or less the same with any level of fragmentation:


Fig 1. a) Simple hedgehogs,                                               b) hedgehogs with day and night preferences










If there are any questions about Netlogo, or how to specifically code for similar process as I've outlined here then please get in touch.