25.11.14

Paper Published

I've finally had my main thesis chapter published! A lot of hard work and two rounds of edits following reviewer comments and it has finally been released online. See it here for non-paywall freely available copy:

A spatially explicit agent-based model of the interactions between jaguar populations and their habitats:

https://drive.google.com/file/d/0B2itFn5PP0TCenl5cWpKazFBUmM/view?usp=sharing

This should be freely available now. Let me know if there are any problems.

28.7.14

Wrapping up

The last 2 months have been intensive. I finally handed in my thesis, and only about 1 1/2 weeks late. Which personally I think is quite impressive! Although, I honestly have never found anything so stressful.

Following a bit of a break down and a cry, the pressure just seemed so great and I just needed it all to be over. The last four weeks of work nearly broke me. Looking back on it now, I wonder why I put so much pressure on myself, but the end was getting nearer and nearer and yet I couldn't see any light at the end of the tunnel. It just seemed like the final weeks would just stretch on and on and on and on. Nothing would change and I would be stuck in the groundhog day of writing and writing, and stressing, and writing, and getting so entwined in everything that I almost couldn't breathe.

You would think that I would have had this magical moment upon my final hand in. However, I found the whole experience a complete anti-climax. I handed in a complete first draft, and waited a week for comments from my supervisors, before doing another weeks work and finally handing it in. Although at this point, I had found out that my viva couldn't be when I wanted and that I would have to wait 2 months before finally being able to close the door on the last 4 1/2 years. In fact, it will be 5 years almost to the day since I started this whole journey before I will finally hand in the hard copy of the final final final thesis. Dr. Watkins here I come, I hope.

Not only did I have to hand in my thesis, but I have also been furiously hunting for jobs. With a husband and a 2-year old to support I can't sit around and enjoy a nice long break, I need to get right back on the bandwagon and bring in some wages. Luckily, I was able to apply for 2 very good jobs during the last 2 months of my thesis, and scored 2 interviews that coincided nicely (or not) with the same week that I handed in my thesis. Considering I needed to prepare a 5 minute talk for each interview this only added to the stress of the whole experience.

I heard from the first interview within the week. Disappointment was only overshadowed with knowledge of the inevitable. I knew I wasn't going to get the job, after an interview that did not go well and I have to admit I was underprepared and did not show myself off in the best light. The second interview went much better (for the same organisation as the first) and I was pretty convinced that they would have to give me the job. 3 weeks later and I finally found out that I was again unlucky, only getting 1st reserve. This did not offer me the consolation I was looking for. I then spent the next 2 weeks getting more and more worried that I would be in the unemployed limbo forever, as no 2 more job applications didn't even land me an interview.

Still, 2 weeks to the day of getting the rejection from the second interview, I got an email saying that the job had become available and was mine if I wanted it! Thank goodness. Here was the relief and climatic finish I was looking for. I am still waiting to start (over a month after getting that email) but am hoping to hear this week about a start date.

So the last 5 years have not been for nothing. They have been some of the best years of my life and I have found lifelong friends. My research project has been an enjoyable experience, from which I have learned a lot and hopefully opened up the possibility of new applications of modelling for conservation benefits. Now I just need to work on editing a manuscript for publication before I can leave this period of life and move on to the next.

The joys of finally securing a job have now meant that I can enjoy my time off with my little girl and spend some quality summer time together before the reality of working life hits me with a vengeance. It could only be for another week, so I'm off to enjoy my summer.

I'll post back with updates on my viva and any possible publications. But for now, this is me signing off.

Good luck to those still working for your phd. There is an end!

6.5.14

Less haste, more speed.

Todays lesson is a harsh one. Less haste = more speed.

Time and the again I find myself with a significant set back in running simulations due to some stupid, pathetic, rage-inducing idiotic mistake that if I had just taken an extra second to think about things and run through the logical steps of the programme, I could have very easily avoided it!

You would think, after 4 years of doing this that I would have learnt my lesson. But no. Here I am, with less than a month to go and I have just found another completely moronic mistake in model settings that means my lovely model output is now all wrong and has to be re-done. Whats worse is that to was actually *TWO* mistakes, leading to more food in the landscape and more individuals being introduced into the model so that I had a lovely stable long-term population.

I fixed the errors and my population now dies by year 30. This itself is fine, as it actually what I would have expected in the region I'm modelling, but what it does mean is that I now have to re-do the focus of my last chapter, re-think the order of experimental steps, re-think the implications for real-world conservation and what this means for interpretation and future recommendations for conservation management. *aarrgghh*

Some days I wonder how I've managed to survive into my thirties. I think I might just walk around with a giant DUNCE written on my head and be done with it.

Not a good day when I have 4 weeks and counting to hand in the final thesis!

Breathe. Think. Take a second. Fix the error. Check. Check. Double check. Look at the fix. Check it again. Breathe. Look at Facebook. Look at Twitter. Check. Check. .... Run....

(fingers crossed......)

25.4.14

Displaying movement map in R as raster

So I've been busy trying to output suitable information from my model to demonstrate the area sin which agents are moving. I want to get some idea of how well used the map is, and if agents are able to successfully negotiate the central section of the landscape where heterogeneity is highest.

I've outputted a text file that has the number of steps taken in each grid cell and converted this to an ASCII file, replacing all commas with spaces and adding the relevant information at the start of the file as below:


ncols         608
nrows         506
xllcorner     299006.96538007
yllcorner     1898128.1510276
cellsize      100
NODATA_value  0

I can now read this into R with the following:
(which requires several packages - raster, rgdal and scales)


Map1 <- raster ("/Users/aw4g09/Dropbox/ThesisChapters/CorridorLandscapePaper/simulationData/RawData/long_corridorModelOutput/GISMovementMap_1.txt")

and display with several options:
plot(Map1)
or

map.spdf <- as(Map1, "SpatialPixelsDataFrame")
map.df <- as.data.frame(map.spdf)
head(map.df)
gMap <- ggplot(map.df, aes(x=x, y=y)) + geom_tile(aes(fill=layer)) + coord_equal()
gMap <- gMap + theme(panel.background = element_rect(fill='white'))
gMap <- gMap + scale_fill_gradient2(limits = c(0, 30000), low=muted("green"), mid="red", high="white", midpoint=15000)
gMap
This latter option allows me to manipulate the legend extent, choose gradient colours etc.

I also found a VERY cool way to generate a 3D plot of the raster which can be manipulated. This requires some extra packages including rasterVis, rgl and sp, at which point you can simply enter plot3D(Map1). Another application opens to display the 3d plot.

although I am still struggling to figure out how to save an image of the output!

now I'm starting to try and figure out how to compare movement across simulations, i.e. compare the distribution and density of movements between different rasters... I found a very useful website that is helping with this

http://evansmurphy.wix.com/evansspatial#!raster-analysis-in-r/c1n3l

so I'm hoping I should have something more solid to present in my last thesis chapter than a subjective description of movement... fingers crossed.



3.4.14

Clip polygon layer by another polygon layer

Ok, so I did this once, didn't write it down and then couldn't figure out how to do it again.

I continue to lament on the 'improvements' to arcGIS. Version 10 is not my idea of good software design.
Anyway, I have a number of polygon shape files, that design buffers around existing agricultural areas in the landscape. However, I want to remove the existing urban read from these files to ensure that agricultural expansion cannot override existing landscape features - roads, protected areas, urban centres etc. I don't have the 'erase' tool seeing as this requires the advanced version of arcGIS10.

So what I figured out I need to do is use the 'clip' function, but in reverse; i.e. create a shape file that identifies all the areas outside of protected areas, urban centres, etc and then clip the agricultural files by this 'non' file.

Analysis Tools - Extract - Clip

Finally!

A bit of a workaround, but this seems the best that arcGIS10 has to offer.

To create the 'non' file, use the Union function:

Analysis Tools - Overlay - Union
select Urban polygon file
select corridor outline shapefile

output file identifies urban areas on top of corridor file
then simply remove the urban areas via the attribute table - select urban polygon and delete from the file. done!

then need to do this again with the corridor designs 1 and 2.

repeat with the urban area - removing existing agricultural areas as well as protected reserves and corridor designs (in separate files).

2.4.14

Arc GIS 10

I am completely frustrated by this newest version of Arc GIS. My previous version of 9.3 was easy to use, straight-forward and functional. This new version has a complicated menu arrangement and features that were easy-to use and 'available' in version 9 are now not available in the new version!

I have to say, the look and feel of the programme has not been improved either. Floating menu boxes make it easy to lose menus, and the map does not adjust to fit the screen when a new menu is added: for instance, when I add Arc Toolbox, which now seems to be hidden within the Geoprocessing option in the toolbar, I have to adjust the underlying map and the toolbox sits awkwardly at the side of the screen.

I have also been attempting to use a simple feature of GIS all day - all I want to do is clip a shape file by another shape file so that polygons in one file do not overlap with polygons in the second file and it seems impossible! Apparently, the erase tool (which online sources seems to suggest will perform this function) is only available under the advanced software download. Ridiculous!

I am NOT impressed.

7.3.14

Single figure with multiple plots - R ggplot2

So in my efforts to revise some PhD chapters to submit for publication, I've had to figure out how to do some nice graphics in R to reduced, condense and improve the figures in my chapters.

Some simple steps are described below, as well as the example outputs.

I've tested the layout() function in R, as well as facet.grid, but the latter is for when axes on multiple graphs are the same. This is the case with me, and so I've put together each figure independently and then simple added them together and given them the same legends where applicable.

R code as follows:

library("ggplot2")


  • Create the first figure called popPlot - how population changes over time

popPlot <- ggplot(modelPop, aes(x=factor(year), y=currentPop)) + geom_boxplot()
popPlot <- popPlot + theme(panel.background=element_rect(fill='white', colour='black')) + ylab("Population Size") + xlab("Year of Simulation")
***** the following overrides the automatic scale and sets the x axis labels *******
popPlot <- popPlot + scale_x_discrete(breaks=c(11, 20, 30, 40, 50, 60, 70, 80, 90, 100), labels=c("11", "20", "30", "40", "50", "60", "70", "80", "90", "100"))
***** leaving the x axis title as blank() means it doesn't get printed on this figure ******
popPlot <- popPlot + theme(axis.title.x=element_blank(), axis.title.y=element_text(size=30))
popPlot <- popPlot + theme(axis.text.x=element_text(size=25), axis.text.y=element_text(size=25))
****** the following adds the line indicating the mean value for each year of the simulation *****
popPlot <- popPlot + stat_summary(fun.y=mean, geom="line", aes(group=1), colour='red', size=2)
popPlot


  • Create the second figure called popPlot.L - how population changes over a longer time period

popPlot.L <- ggplot(longModelPop, aes(x=factor(year), y=currentPop)) + geom_boxplot()
******* if the axis titles are not set out here, the data column names will be applied automatically ****
popPlot.L <- popPlot.L + theme(panel.background=element_rect(fill='white', colour='black')) + ylab("Population Size") + xlab("Year of Simulation")
popPlot.L <- popPlot.L + scale_x_discrete(breaks=c(11, 100, 200, 300, 400, 500), labels=c("11", "100", "200", "300", "400", "500"))
****note both axis titles are removed in this figure ******
popPlot.L <- popPlot.L + theme(axis.title.x=element_blank(), axis.title.y=element_blank())
popPlot.L <- popPlot.L + theme(axis.text.x=element_text(size=25), axis.text.y=element_text(size=25))
popPlot.L <- popPlot.L + stat_summary(fun.y=mean, geom="line", aes(group=1), colour='red', size=2)
popPlot.L


  • Now plot both figures together
library("grid")
library("gridExtra")

******* this a single line codes for the plotting of both graphs in the same figure *******
grid.arrange(popPlot, popPlot.L, ncol=2, sub = textGrob("Year of simulation", gp=gpar(fontsize=30)))

This produces the figure below:


Concatenate txt files

So I've once again bit a bit silly trying to output a lot of data in as simple a manner as possible from my Repast model. This means I have 500 files, for every run (20) that I now need to analyse.

I've figured out that the easiest method for doing this is to concatenate the files together. These files are intended for me to analyse how agents are moving around the landscape, and if any movement is occurring from south to north, or vice versa.

The easiest method for this seems to be via the terminal on my Mac, and a great, simple and straightforward method is as follows:

Open /Applications/Utilities/Terminal.app

Type 'sort ' (without the quotes, note the trailing space, and do NOT press return)

Drag the file(s) that you want to sort to the terminal window

type '> sorted.txt' (without the quotes)

Press return. Sort will read the files, sort them and put the sorted list into the file called 'sorted.txt' in your home directory.


Easy peasy!

4.2.14

Completion of example model data chapter

So its been a while since my last blog post. On a personal note I have been busy with Christmas and my young daughter and we have also just moved house again - all of which have distracted me from doing the finishing touches to my PhD. I have also just applied for a NERC grant with cardiff University. That was a terrific amount of work in a short space of time, for which I am not going to know the outcome until June!

With all that going on, I'm surprised to have got so far with things.

To make a general update:

I have now completed my third data chapter - the big beast of a chapter that describes my entire model in detail and publishes the model outcomes, sensitivity analysis and validation with empirical data. What a feat! At every turn I felt like mistakes were arising and the model seemed to crash every time I tried to improve things and make output more ecologically realistic. But time waits for no-one and some sage advice form my supervisor has allowed me to close the door on the continually effort for improvement and concentrate on getting it done and moving on to the landscape analysis.

Some bits and pieces from this chapter:

1. territories and population size. females in red, males in blue.



population remains fairly stable, increasing slightly to fill the useable space and has some good stats for individuals inside and outside of the protected areas. agents are younger in the matrix than inside the protected area, have lower energy reserves and less fecundity.

2. Population stats, protected vs non-protected areas



I still have some issues with validation via the empirical data with the number and distribution of agents being captured by model camera traps not matching the empirical data. The fine and local scale movement of agents does not seem to be adequately captured by the model, but considering the landscape scale nature of the simulation and the scale of movements and number of individuals, then its not surprising to get some scaling issues. A higher resolution landscape and were individuals would allow for a bit more work to be done in this area, but this was not the focus of the piece of work so I'm not too worried. As long as the population level events are being captured, and match the empirical population data then I believe we can be happy with the outcome of the model so far.

Its not my intention to get a model that fully encapsulate the complexity of real individual jaguar movements, as this is going to be pretty much impossible. The need to reduce model complexity, but increase model realism is always going to be a battle. We just have to hope that we reduce model complexity in the right places that model outcomes are not adversely affected. 

The next, and last(!) chapter of my thesis will take a look at this by using the model to investigate connectivity and landscape utilisation in a population of jaguars in a far more fragmented area of Belize.  This should give me a better idea of the issues with the model and how these need to be addressed (if any exist).

For now, I'm pleased to have got this chapter done and happy to be moving onto the last phase of my PhD. The end is in sight!