looking for code to export turtle properties

Viewed 76

I want to export all of the individual turtle properties to a csv file at setup and then at the end of the run.

I have tried to modify the csv model to accomplish this, but but am new to netlogo and to coding and as such, am having difficulty determining how and what code to write. I understand this part of the code:

to write-turtles-to-csv ; we use the of primitive to make a list of lists and then ; use the csv extension to write that list of lists to a file. csv:to-file "turtles.csv" [ (list xcor ycor size color heading) ] of turtles end

But am not sure how to write the code to gather the individual turtle properties for all of the turtles (I am looking for the properties that are displayed when one "inspects" an individual turtle).

I am working with the conspiracy theory model and would like to analyze both of those sets of data along with the initial set of slider parameters.

I would appreciate any info/direction that can be provided.

Thanks

1 Answers

The CSV extension does make this very easy. All you need to do is replace the list of variables following the word "(list" with all the variables you want from your turtles. These can be turtle variables, patch variables (of the patch the turtle is on), or global variables such as "ticks".

to write-turtles-to-csv
  ; we use the `of` primitive to make a list of lists and then
  ; use the csv extension to write that list of lists to a file.
  csv:to-file "turtles.csv" [ (list turtle-var-1 turtle-var-2) ] of turtles
end

The problem with this approach is that it writes a new file each time, so you cannot get turtle variables from both the start and end of the simulation in the same file. The easiest solution would be to write two separate files. Use a statement like this at the end of setup:

csv:to-file "turtles-at-setup.csv" [ (list turtle-var-1 turtle-var-2) ] of turtles

and the same statement but with a different file name when your code stops.

Related