首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在.ASCII 6.2中导出NetLogo文件?

如何在.ASCII 6.2中导出NetLogo文件?
EN

Stack Overflow用户
提问于 2022-02-13 17:59:08
回答 1查看 65关注 0票数 0

我想知道如何在.csv 6.2中将一个NetLogo文件转换为光栅(ASCII)?

好的,我可以在.csv中导出,以便稍后在另一个程序(如R. )中在.ASCII中进行转换,但是,我认为应该可以通过NetLogo本身在.ASCII中导出输出。同时,我想知道在处理方面,用.csv输出输出NetLogo还是用.ASCII输出比较好?我在NetLogo上的世界是比较大的

提前感谢

代码语言:javascript
复制
extensions [ gis ]

globals [ file output-filename ]

to setup
  clear-all
  reset-ticks
  set output-filename "output-data.csv"
  set-default-shape turtles "person"
  create-turtles 10 [
    setxy random-pxcor random-pycor
  ]
  initialize-data-file

end

to initialize-data-file 
  file-close-all    
  if file-exists? output-filename [
    file-delete output-filename
  ]     
  file-open output-filename
  file-print ( word "xcor, ycor" ) 
end

to go
  ask turtles [
    wander-about 
    if ticks mod 50 = 0  [    
      write-output-data who xcor ycor
    ]
  ]
  tick
end

to write-output-data [ #turtle-id #xpos #ypos ]
  file-open output-filename
  file-print ( word #xpos ", " #ypos )
  file-flush
  
  ; set file gis:patch-dataset xcor ycor
  ;  gis:store-dataset file "test.asc"
  
end

to wander-about 
  rt random 40
  lt random 40
  if not can-move? 1 [ rt 180 ]
  fd 1
end
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-14 00:38:05

使用GIS扩展直接导出到ASCII是正确的。您是否真正需要这样做完全取决于您的应用程序--正如您所说,您可能只需导出海龟坐标列表或补丁值等,就可以完成所需的工作,这取决于您的需要。您是否应该使用ASCII或csv将取决于您的应用程序,但是:对于我的所有较大的模型,在这些模型中,我实际上需要导出整个世界进行分析(更重要的是,将空间数据导入NetLogo),我总是使用地理信息系统扩展,因为它看起来要快得多。如果我只是出口海龟的特性,我可能会出口到csv。

在这里回答你关于如何直接导出到ASC的具体问题--这里有一个方法。您需要设置一些空间信息,以便地理信息系统扩展处理您的数据,但一旦完成,您就可以从修补程序值创建一个光栅数据集,并将其导出到.ASC文件中,该文件除了为您的世界中的每个修补程序设置一个值外,还将包含.ASC头。在这个例子中:

代码语言:javascript
复制
extensions [ gis ]

patches-own [ turtle-here ]

to setup
  ca
  resize-world 0 14 0 14
  ; Pull in some coordinate system 
  gis:load-coordinate-system "utm_11.prj"
  ; Set some envelope. Unless you are actually spatially
  ; referencing your model, this is just a placeholder. 
  ; If you are using actual spatial coordinates, set these
  ; appropriately or use gis:envelope-of
  gis:set-world-envelope [ 55000 50000 55000 50000 ]
  crt 10
  reset-ticks
end


to go
  ask turtles [
    rt random 80 - 40
    ifelse not can-move? 1
    [ rt 180 ]
    [ fd 1 ]
  ]

  if ticks = 50 [
    export-ascii
    stop
  ]
  tick
end

to export-ascii
  ask patches with [ any? turtles-here ] [
    set turtle-here 1
  ]
  let ras_out gis:patch-dataset turtle-here
  gis:store-dataset ras_out "any_turtle_here.asc"
end

这将导出一个ascii文件,该文件存储名为patches-ownturtle-here变量,该变量仅指示导出时修补程序中是否存在海龟:

代码语言:javascript
复制
NCOLS 15
NROWS 15
XLLCORNER 50000
YLLCORNER 50000
CELLSIZE 333.333333
NODATA_VALUE NaN
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 
0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 
0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71103447

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档