Why are my ouput values different from patch values?

43 views
Skip to first unread message

Tanya Esteves

unread,
May 3, 2024, 3:14:32 PMMay 3
to netlogo-users

Hi all, 

I have a code that calculates emissions for different types of vehicles (old combustion, middle-aged combustion, new combustion, hybrid and electric) in a given study area using the gis extension. I ran BehaviorSpace with an emission diffusion variable for the patches-own variable p-emissions (0.0 to 1.0, in 0.1 increments) and it gives me the global and differentiated values emitted in the region. I have also exported the final maps as ASCII, transformed them in Arcgis Pro through a series of operations to polygon format so that I can know how many emissions there are in a given municipality. The problem here is that the sum of the municipality emissions obtained from the exported asci file aren't the same (or even close) as the global emissions from BehaviorSpace. For example, for 10 runs of emission diffusion 0.5, BehaviorSpace .xls gives me an average for the 10 runs of 1760,49 kg of daily CO2 emissions for the region (final run values are very similar between them). When using the shapefile information, it gives me a total of 201,1 kg of daily CO2 emissions. It seems to me that either the model is miscalculating the emissions of my cars or that for some reason, patches information is giving me wrong values. 

I am a novice in Netlogo and had a lot of help developing this code. But I know my way around ArcGis fairly well, so I'm quite certain my procedure is correct and I am not somehow losing information. 

Here is how I calculate total emissions for the cars in Netlogo:

to calculate-total-emissions  ; Calculate emissions for each car
  ask turtles
  [
    calculate-emissions self ; self refers to the current turtle
    set all-emissions (all-emissions + emissions)
    set emissions-turtle [emissions-turtle + emissions] of self
  ]

  ; Aggregate total emissions for each car type
  ask turtles with [car-type = "ev"]
  [
    set all-ev-emissions (all-ev-emissions + emissions)
  ]
  ask turtles with [car-type = "hybrid"]
  [
    set all-hybrid-emissions (all-hybrid-emissions + emissions)
  ]
  ask turtles with [car-type = "ICE-old"]
  [
    set all-ICE-emissions-old (all-ICE-emissions-old + emissions)
  ]
  ask turtles with [car-type = "ICE-middle"]
  [
    set all-ICE-emissions-middle (all-ICE-emissions-middle + emissions)
  ]
  ask turtles with [car-type = "ICE-new"]
  [
    set all-ICE-emissions-new (all-ICE-emissions-new + emissions)
  ]
end

As for the patch emissions, I think it calculates in the Drive procedure:

to pick-where-to-drive-traffic ;; This is how the cars navigate with traffic
                               ;if road ahead is road and no other cars there, head there
  let cars-ahead 0
  let target-patch patch-ahead speed
  if target-patch != nobody and any? turtles-on target-patch
  [
    set cars-ahead count turtles-on target-patch
  ]
  ; Checks if there are cars ahead
  if  patch-ahead speed != nobody  [
    ifelse patch-ahead speed != nobody and [pcolor] of patch-ahead speed >= road and cars-ahead = 0
    [
      set heading towards patch-ahead speed
    ]
    ; Else, if the patch ahead is dirt or has a car,
    [
      ; Then, if the patch of the road ahead and 30 degrees off center to the right is road, and has no cars, head there.
      if patch-right-and-ahead 30 speed != nobody
      [
        set cars-ahead [count turtles-here] of patch-right-and-ahead 30 speed
      ]
      ifelse patch-right-and-ahead 30 speed != nobody and [pcolor] of patch-right-and-ahead 30 speed > road and cars-ahead = 0
      [
        set heading towards patch-right-and-ahead 30 speed
      ]
      [ ; Else if that isn't road or has a car then, if the road the road left and ahead at 30 degrees is a road, head there instead.
        if patch-left-and-ahead 30 speed != nobody [set cars-ahead [count turtles-here] of patch-left-and-ahead 30 speed]
        if patch-left-and-ahead 30 speed != nobody and [pcolor] of patch-left-and-ahead 30 speed > road and cars-ahead = 0
        [ ; after setting heading towards a patch of road at speed "speed" that doesn't have a car on it
          set heading towards patch-left-and-ahead 30 speed
          fd speed ;; the cars go forward here, because it merely makes the cars movement "look" more realistic. But it is an arbitrary move that isn't really consistent.
        ]
      ]
    ]
  ]
  ; Random turning to get out of stuck states
  rt random 25
  lt random 25
  ; if the patch ahead is road and is empty of cars
  if patch-ahead speed != nobody
  [
    set cars-ahead [count turtles-here] of patch-ahead speed
  ]
  if patch-ahead speed != nobody and [pcolor] of patch-ahead speed > road and cars-ahead = 0
  [ ;go there, but check if the car is at the edge of the view, and if it is turn around and go another direction.
        set heading towards patch-ahead speed ifelse can-move? 1
    [
      fd speed
      set p-emissions emissions
    ]
    [
      right 180
    ]
  ]
  if random 100 < 2
  [
   right 180
  ] ;; turn around if at a dead end every 10 ticks. This helps get cars unstuck.
end

Emissions are turtles-own (along with the emissions for different types of cars) and all-emissions (and different variations) are globals. 

Maybe here patch emissions are overwritten every time a new car goes through that patch? If so, I have tried: set p-emissions (p-emissions + emissions), still with wrong results.

Am I wrong in assuming that the total values should be approximately the same for exported Netlogo map and BehaviorSapce xls? Or at least in the same ballpark?  Because produced CO2 has to go somewhere... It can't just disappear, right? I appreciate any help I can get.

Thank you.

Pradeesh Kumar K V

unread,
May 5, 2024, 3:19:08 AMMay 5
to netlogo-users
Since you export the final map ( which I assume is the map shown after completion of Behavior Space runs), the input data (value of patch variable) used by both NetLogo and ArcGis must be the same. Therefore, I would suggest the following:

1. Sample a few data points (patches and the corresponding data points in the exported file) to ensure that data is consistent.
2. Review how the total emission is calculated in NetLogo. What is the formula used to aggregate patch data? Does the aggregate value need to be reset during each run, and if yes, is it getting reset correctly?
3. Is the formula used to aggregate ArcGis data point values correct? For example, does the aggregate for each municipality refer to the sum or is it an average?

Hope this helps.

--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/3313b0ab-d6fb-4f1a-b511-0360281b3521n%40googlegroups.com.

Tanya Esteves

unread,
May 6, 2024, 12:16:41 PMMay 6
to netlogo-users
Hi Pradeeshkkv
First of all, thank you for your input. Yes, the final exported map is the one shown after completion of BehaviorSapce runs. As for you suggestions, here are the respective replies:
1. Will try to do that, thank you. Just need to figure out how to do this in netlogo. 
2. I think where it calculates patch data is in my drive procedure (set p-emissions emissions), where p-emissions is the patch variable and emissions are CO2 emissions made by the car agents. I've tried changing it to set p-emissions p-emissions+emissions but minor changes were made. Yes, the aggregate value needs to be set every run (1 run = 1 day), but emissions in each patch should accumulate with every tick in the run. 
3. When exporting from Netlogo to ArcGis, the asci file has to be turned into a raster and then into polygons through a series of steps. So I end up having 30m*30m polygons that should correspond to the patches from the Netlogo´s exported file, having the respective available emissions for each polygon/patch in the table. This will enable me to do my calculations. From there, I can calculate CO2 emissions for the whole region, each municipality or even a specific area of interest. In simple terms, it's basically just selecting the area I'm interested in, looking up the table and performing a sum of the CO2 emissions for those selected polygons. Of course, other statistical operations can be used - like e.g., average - , but I'm positive I'm simply performing a sum operation. 

Once again, I appreciate your comments and will try to use them to further explore a solution. 

Kind regards, Tanya
Reply all
Reply to author
Forward
0 new messages