26.6.12

Distance to urban areas in GIS

I've just finished the last updates to my GIS data for using in my ABM and I generated such a cool picture that I thought I would share:


This is a combination of the distance to the main urban areas and distance to tarmac roads. I removed all of the tracks and trails from my road file as this layer is supposed to represent a general cost layer where proximity to humans is detrimental to jaguars and they would rather be in the low cost areas to the far left and upper regions of the map.

Some things to remember where trying to generate these types of maps:
1. the euclidean distance method seems to be the most appropriate:

                 Spatial Analyst - Distance - Euclidean Distance

2. this method can be used on shape file data or on raster data making it a pretty flexible function
3. the output will only be generate for the exact extent of the data you are performing the function on. For instance, if you have polyline data, then the distance will extend only until the smallest rectangle that includes all the lines, and NOT the surrounding NoData areas. Therefore you need to do the distance function on a larger dataset and then clip it to the area you want if this is a problem.
4. In my case, this was not possible so I converted my polyline shape file (roads) to a raster first, then extended the extent to the area required by my model and then performed the distance function.
5. To get the map above, I combined distance maps for urban areas and roads.
6. My urban areas were actually polygons and the distance function worked just fine with this.
7. As I said earlier, I decided to remove the small roads and tracks from my roads dataset before calculating the distances as these do not impact negatively on the movement of my agents (jaguars).
8. Once I had the two datasets that were each of the correct size and extent, I simply added the layers together:
                  Spatial Analyst - Math - Plus

9. Adding the two layers together creates a new layer that matches the size of the smallest input raster, so I actually added together the roadProximity file (purely for the model area) together with the urbanProximity file for the whole of Belize. 



25.6.12

changing extent of GIS file


Another update to my GIS information:

For some reason some of the methods I've outlined in my earlier post (1/12/2011) don't necessarily work !

So, an update to extending the extent of a file is as follows:

This seems pretty impossible to do with shape file, be it a feature, polygon, polyline or point. This makes life more difficult than it needs to be (typical), so the only alternative at the moment is to

1. convert the shape file to a raster
2. Via spatial analyst toolbar (View - Toolbars - Spatial Analyst)

Options - Analysis Extent - same as Layer "TotalClip" (or whatever the file of the right size is, and this needs to be a shape file) - snap extent to 'total area' (this needs to be a raster file).

3. The above method seems to work most effectively at getting the extent of the file to the required area, so its good to ensure you have both a shape file and a raster of the required area.
4. Now all that needs to be done is to add the raster you want to extend to the raster of the required area. In my case this is adding 'finalRoads' to 'totalarea'.
         totalarea has a value of 1 for every cell within the layer as its only purpose is to show the extent of the area I want to use in my simulations.

        Spatial Analyst toolbar - Raster Calculator - [finalRoads] + [totalarea] - evaluate

5. A new temporary file is now created called Calculation and this needs to be made permanent:

       right click on Calculation - Data - Make Permanent - then go to appropriate folder and name the file (allRoads in my case) - save

6. This new permanent file does not get automatically added, so this needs to be manually added if required.
7. For some reason, some of the classes change slightly (all mine increased by 1). The raster can be reclassified from either the temporary Calculation file or the permanent new allRoads file. Reclassifying the Calculation file means that a permanent reclassified file gets created so you no longer need to make the Calculation file permanent.

21.6.12

model decision-making part 2

Movement Decisions

As an update to my post entitled model decision-making (17/01/2012, here), i've changed my mind yet again (!) on the best way for my agents to move around.

Food is by far the most logical incentive, but then 'cost' became an arbitrary factor that counted for nothing real and only worked in making the model use more factors for no apparent reason. The only way I could see around this was to incorporate food and mortality into the cost factor - as was originally intended when I chose to centre my ABM around ideas of least-cost modelling.

so now, my agents make movement choices based on:

  1. road cost
  2. habitat cost
  3. pheromone cost
Food is still available in the cell, depending on the habitat at that location, but a propensity to avoid cells recently inhabited (via the amount of pheromone available) means that agents are directed at cells that are likely to have greater food availability.
Basing movement decisions on habitat and pheromone implicitly include aspects of food, cover, mortality, mating opportunities etc rather than having to specifically include each separate detail in the model.

This makes more sense to me, and reduces the complicatedness of the model. This has become a real issue to me as improving the model tend to naturally lead to an ever-increasing array of parameters and choices and extra code.

Where a road exists, this overwrites the habitat cost.

Feedback and Improvements

I've also had a lot of good feedback from Bart and Beccie, out in Belize, and I hope to incorporate their ideas and suggestions for improvements in subsequent drafts of the model. At the moment, I have simplified some of the habitats (by combining some types of forest together) and simplified the roads to 3 types:
  1. large, regularly used tarmac roads
  2. small, infrequently used non-tarmac roads that allow cars to pass
  3. small trails and tracks inside and outside cockscomb including some pedestrian tracks that have no car use


Interactions Between Agents

At the moment of writing (june 2012) I'm having trouble deciding how best males and females should interact and how best to attract females and males together for appropriate mating opportunities. I seem to have 4 distinct types of interactions that update how the agents view pheromones from other individuals:
  1. own strength - so how strongly individuals interact with their own pheromones
  2. avoidance of males - how strongly females interact with male pheromones (generally they should try to avoid males so as not to be harassed, although this changes when they are in heat and ready to mate, but could potentially be more severe an avoidance if she is pregnant or has cubs?)
  3. mating attraction - how strongly females should be attracted to male pheromones when they are in heat and ready to mate
  4. male mating attraction - how strongly males should be attracted to females when they are in heat and ready to mate
Additional issues arise when males sense a female is ready to mate, as they are likely to stop actively hunting and looking for food and may become quite thin in their pursuit of a mating opportunity. Males also cover more distance per day when searching for a female in heat.

I'm currently running some trial simulations looking for the effects of these pheromone parameters on the territory sizes of males and females, and in the number of individuals that die and are given birth to. It seems the interaction between these various parameters may be causing some unexpected results in my data.

Territory Sizes

Lastly, territory sizes are become a real concern to me. Territories are based on the number of cells that have an individuals pheromone located in them. Two separate parameters dictate how pheromone survive and propagate - pMax (the maximum amount of pheromone deposited in a cell when visited by an agent) and pDegrade (the rate at which the pheromone degrades and eventually disappears). 

My initial trials used pMax of 100 and pDegrade of 0.98, which gave stable territory sizes of around 70-100 cells per individual. Of course, it wasn't until I realised that this was a tenth of the size that territories needed to be that I ran into a problem!

This needs some more work and investigation, and at the moment any combination of settings seems to either generate territory sizes that are still too small, or that steadily increase throughout the simulation (presumably territories would stabilise at some point but too much time is required for them to stabilise for the parameters settings to be effective).

Running the model for 5000 ticks (or around 4 years) currently takes around 15-20 minutes in batch mode and I would rather not wait any longer before proceeding with the intricacies of the model and starting to collect some data.... although its looking increasingly likely that this may be the case.

Some simple statistics in R

so, I'm currently running a series of simulations of my ABM to try and identify why my agents are not doing what I expect them to do (hardly surprising really, seeing as my model seems to be getting more and more complicated each time I try to improve things).

Anyway, this has led me down the statistics route for the first time in a long time actually as without it I'm struggling to tell if any of my results are *actually* different from each other. I've done an initial 30 runs of each set of parameter settings, taking 30 to be enough of a sample size to allow me to perform robust statistical analyses. *this is tedious by the way*

So I've had to re-learn R, as I tend to do each time I have some stats to do. It does get easier each time, but I tend to avoid using scripts so I struggle to remember how to do even the most simple of stats. Hence, the incentive to write this post as a reminder to me of how to do some simple functions in R.


data <- read.table("testSimulations.txt", header = T)
attach(data)
plot(data)
summary(data)

*this creates a single plot, over-writing one plot on top of the other onto the same axes*
par(mfrow=c(1,1))
plot(meanTerritory~pherValue, col = "green")
par(new = T)
plot(femaleTerritory~pherValue, axes = F, col = "red")

*this creates a side-by-side plot of individual graphs*
par(mfrow=c(1,2))
plot(meanTerritory~pherValuecol = "green")
plot(femaleTerritory~pherValuecol = "red")


*a simple linear model, the anova command gives a single p-value for the treatment, the summary command compares all separate groups to the first group*
territories <- lm(meanTerritory~pherValue)
anova(territories)
summary(territories)
plot(territories)

*a pairwise t-test analysis compares all groups to each other
tmales <- pairwise.t.test(maleTerritory, pherValue, p.adj="none")

some simple advice:
  • use .txt. files, rather than .csv files
  • use a script - in Mac, cmd-Enter runs a single line of the script
  • any statistical book should help with interpretation of the anova output

15.6.12

GIS update - transforming coordinate systems

Following on from a previous post about getting my data files ready to use in my model, I need to update the transform coordinates instructions.

I previously stated that this could be done effectively from within ArcMap. However I have been having problems getting this to work correctly through the transform command within ArcMap (View - Data Frame Properties - Coordinate System - Transformations).

Some of the data I have been provided with has an underlying coordinate system of WGS_1984_UTM_Zone_16N, but camera data I have has been supplied in NAD_1927_UTM_Zone_16N and so my data files need converting to the later coordinate system.

There is a difference between the Geographic Coordinate System and the Projected Coordinate System. The supplied WGS_1984 is from the Geographic Coordinate System and transforming this only allows you access to other Geographic Coordinate Systems. The correct NAD1927 coordinate system is not geographic but projected and so the transformation function within ArcMap does not adequately transform the data....

so... this can be done more effectively from within ArcCatalog...

Navigate to the appropriate file in ArcCatalog, i'll run through this for my data layer of rivers

1. Select modelRivers.shp
2. Click on File - Properties
3. Select XY Coordinate
4. Choose Select
5. Chose Projected Coordinate Systems - UTM - NAD 1927 - NAD 1927 UTM Zone 16N.prj
6. Click Add
7. Click Apply - OK

Note, you cannot change the coordinate system if the file is already open in ArcMap, so you need to remove the layer from ArcMap before attempting to change the coordinate system.


12.6.12

batch update

Ok, so i did say i was going to post the relevant files that enabled my model to run in batch mode.
I've just come back to this after a few months and have had to re-learn how to do batch runs, so... heres the relevant information:

Batch mode depends mainly on 2 files
1. batch_params.xml - located within the batch folder
2. parameters.xml - located within the JaguarMovementValidation.rs folder

The parameters file must include those parameters that have been set as requiring user input in the ContextCreator file
Batch_params.xml must then include reference to any parameters that are included within the parameters.xml file

Batch mode does not seem to work properly if you try to by-pass these parameters. For instance, I just want to do multiple runs with the same parameters and tried to by-pass the numberOfJaguars parameter by keeping it the same and removing the end and step variables. Batch mode then reports an error and won't run.

For a simple test of running a single simulation, but increasing the jaguar numbers from 50 to 300 in steps of 50, the batch_params.xml file looks like this:


<?xml version="1.0"?>
<sweep runs="10">
<parameter name = "NumberOfJaguars" type="number" start="50" end="300" step="50">
</parameter>
</sweep>

when viewed from the Repast GUI it looks like this:



The parameters.xml file, when viewed within the Repast GUI looks like this:




What I now want is to simply run my simulation 30 times using the same parameters.. I do this by removing the parameters from the ContextCreator file and removing all links to this parameter from both the parameters.xml file and the batch.xml file.

This works, but I'm now having the problem that the output is being generated once per tick for the first 50 ticks only, whereas I want the output once at the final tick count of 5000 (or 2000, depending on my criteria).... shall update once I have this issue resolved.

6.6.12

Conference Poster

I have just finished preparing a poster for the University of Southampton Biology Postgraduate conference due to take place on June 14th 2012.
I haven't quite got far enough with my current work to do a poster on validating my agent-based model so I've had to do a poster based on my ECAL poster... not too bad considering it only took me a few hours