Netlogo GIS raster creation speed - netlogo

I am trying to use the Netlogo GIS extension to export patch variables as raster datasets. Example code as I have been trying it (once projection and world-envelope have been set):
to store-raster
let patches_out nobody
ask patches [
set patches_out gis:patch-dataset pcolor
]
gis:store-dataset patches_out "patch_out.asc"
end
This works fine for small world sizes, but the world I'm actually trying to export from is nearly 600 thousand patches; the export takes a very long while. Going the other way with (gis:apply-raster) occurs in a matter of seconds, so I can't help but think I'm missing something. Is there a faster method to extract patch variables into raster format for large world sizes? Thanks in advance.

It turns out that just asking a single patch still exports the entire raster. Each patch was exporting the entire world. Why the gis:patch-dataset primitive isn't therefore called by the observer I don't yet understand, but at least this code solves my issue.
to store-raster-2
let patches_out nobody
ask one-of patches [
set patches_out gis:patch-dataset pcolor
]
gis:store-dataset patches_out "patch_out_check.asc"
end
Note: according to Robert Grider this issue is caused by a bug introduced in Netlogo 6.0; the above workaround should be fine until the issue is resolved.

Related

Why am I getting an error when I disengage world wrap in NetLogo?

I downloaded a working model and I'm adjusting it to fit criteria I have. I want to disable the world wrap so the turtles are constrained in their movement to the initial screen but when I do I get an error telling me: OF expected input to be a turtle agentset or patch agentset or turtle or patch but got NOBODY instead.
Welcome to StackOverflow! For future reference, your question is a bit incomplete as it's hard for others to help you without seeing the code you are using. Try to include enough code for others to answer your question. I cannot directly help resolve your issue, but I can provide some general information.
In NetLogo the behavior of many of the language primitives changes when world wrapping is enabled and when it is not. As an example using patch-ahead, in a world with wrapping in both directions, this code will always succeed:
; turtles will color themselves the color of the patch 1 unit away
ask turtles [
set color ([pcolor] of patch-ahead 1)
]
But if wrapping is disabled in one or both directions, the patch-ahead of a turtle can return nobody when there is no patch in front of the turtle because the turtle is at the edge of the world. In that case you are asking NetLogo to evaluate [pcolor] of nobody, but that is not possible, and you get an error like the one you described.
To resolve this issue you'll have to look through the code and see where these errors are made and handle them appropriately. For my example:
ask turtles [
if patch-ahead 1 != nobody [
set color ([pcolor] of patch-ahead 1)
]
]
You can read more about the world topology of NetLogo models in the docs.

In a Netlogo network, how can turtles "see" properties of other turtles?

I am trying to build a model in which turtles decide to change colour depending on their environment in a network.
The approach would be to "check" the colour of the surrounding turtles and then set an if statement for the turtle in question to switch colour (there will only be 2 colours).
Specifically I would like to know how can a turtle "see" or check other turtles' colour (or other properties).
If possible I would also like to create a slider for "how many links away" can turtles see their neighbouring turtles' (or neighbours of neighbours, etc) colour.
I am new to both Netlogo and Stackoverflow, so please let me know if I should make any modifications to my model and/or question.
Thanks!
Welcome to Stack Overflow! Typically you'll want to stick to a single question per post, both for simplicity and for the benefit of future users with similar questions. As well, in cases where its applicable you should try to include some code to show what you've tried so far, as well as any setup necessary- you want to make a minimal, complete, and verifiable example. In this case, I think you're okay since your questions are clear and well explained, but if you have more complex questions in the future you will be more likely to get useful answers by following those guidelines.
For your first question, it looks like you want the of primitive- check out the dictionary entry for details. of can be used in a few ways, including allowing agents to check the value of a variable (such as color) of another agent. Check out this example code:
to setup
ca
reset-ticks
crt 10 [
setxy random 30 - 15 random 30 - 15
create-link-with one-of other turtles
]
end
to go
ask turtles [
set color [color] of one-of link-neighbors
]
end
Every time the go procedure is called, one of the turtles changes its color to the color of one of its link-neighbors. If you run it long enough, all connected turtles should end up with the same color.
For your second question, I suggest you check out the Nw extension, which is an extension built to deal more easily with Netlogo networks. Specifically, have a look at nw:turtles-in-radius, which should work with your slider approach. To get it working, include the extension using
extensions [ nw ]
at the start of your code. Then, assuming the same setup as above, you can play around with something like
to network-radius
ask one-of turtles [
set color red
ask other nw:turtles-in-radius 2 [
set color white
]
]
end
When you call the network-radius procedure above, you should see one turtle turn red, and any turtles within 2 links of that turtle turn white. To switch to a slider, just swap the "2" out for your slider variable. Hope that helps!

Constraining Movement of Agents to a Home Range in Netlogo

I'm relatively new to NetLogo, and I'm working to model moose density in New Hampshire and its correlation to winter tick parasitism.
I'd like to program my moose agents to move randomly within a set home range (~5km2), that originates from the randomly chosen patch they first enter the model on.
I'm not really sure how to bound agents based on area, rather than just patch color... Any suggestions on how to do this would be most appreciated!
Thank you!
General stackoverflow tip: typically, stackoverflow encourages specific programming questions. So including the code you've actually tried so far is generally preferred.
Alright, on to your problem.
One really simple way to do this is, first, store the mooses' starting patch. Second, when the moose is moving around, check the distance to the starting patch. If the distance exceeds the starting amount, have the moose towards the starting patch. Here's some template code to give you ideas:
breed [ mooses moose ]
mooses-own [
starting-patch
]
to setup
clear-all
;; only using one moose as it's easier to see the behavior
create-mooses 1 [
setxy random-xcor random-ycor
set starting-patch patch-here
]
reset-ticks
end
to go
ask mooses [
move
]
tick
end
to move
;; If farther than 10 patches from starting patching, take a step towards starting patch, otherwise, move randomly
ifelse distance starting-patch > 10 [
face starting-patch
] [
rt random 90
lt random 90
]
fd 1
end

How do I create a vision cone that takes into account the size of other turtles?

I was using in-cone, but then I noticed my turtle was "missing" a lot of other turtles inside the cone. From what I understand, this is due to the fact that, for instance:
ask other turtles in-cone 6 60 [set seen? true]
only "detects" turtles if their xy is within the cone. They are basically points without dimensions. Is there an easy way to make a turtle of size 20 be much more "visible" than one of size 2? I've searched this and the yahoo group for answers and didn't find what I was looking for... maybe I'm not searching for the right terms... I'm new to programming and netlogo and everything so I'm probably missing something obvious here.
Thank you very much.

Trying to make a procedural environment in netlogo

So this simple block of code will create clusters of black patches in the environment.
I would like to know how to procedurally paint and repaint them in the environment.
The effect I'm going for is periodically disappearing patches and reappearing in a random location.
ask patches in-radius random 3.5
[
set pcolor black
]
I don't know how I would apply pseudo code logic like:
while(true)
{
if(ticks % 100)//If ticks are a multiple of hundred
{
clear black patches
paint clusters of patches
}else{ do nothing}
}.
-in netlogo syntax.
Any help is very much appreciated.
Thanks in advance!
ask patches with [pcolor = black and <near a certain point>] [...]
But ... if I am not misunderstanding the nature of your question, I think you need to work through at least the beginning of a tutorial on NetLogo first, or take a look at some of the examples in the Models Library that's available on the File menu. I'm not going to rewrite the tutorial here. For example, you don't need a while loop, given what you've said so far. You need to use a run procedure. That's the sort of basic idea you should learn before doing anything else. Since you already have some understanding of programming, it won't take long.