Loading ...
Sorry, an error occurred while loading the content.
 

Re: [netlogo-users] Importing per-patch data

Expand Messages
  • James Steiner
    patches can own variables just like turtles. use a patches-own statement. the easiest way to import data, outside of importing formatted GIS info using the
    Message 1 of 3 , May 1, 2012

      patches can own variables just like turtles. use a "patches-own" statement.

      the easiest way to import data, outside of importing formatted GIS info using the GIS extension,  is to format the data in the file in the form of a netlogo literal list. An entire list, including sublists, can be read in a single file-read statement. if the data is structured into rows and columns, then each patch can directly extract it's part of the data from within that list, or those lists.

      example for a 3x3 patch field

      [ 0 "n"
      [
         [ 1 2 3 ]
         [ 4 5 6 ]
         [ 7 8 9 ]
        ]
      ]

      now that's data for layer 0 of variable n for nine patches.  call that L.

      you can have as  many layers in the  file as needed. wrap those in a list, too. below, each L represents a layer list, as above.

      [
        L0
        L1
        L2
      ]

      that's three layers of one variable. call that V.

      repeat for additional  variables. enclose that in brackets, too.

      [
        V1
        V2
        V3
      ]

      that's three variables

      the beginning of your file now looks like this:

      [
        [
          [
            [ 0 "n"
             [
               [ 1 2 3 ]
              .......

      write separate procedures to deal with each level of this structure.

      in outline, you read the whole thing with a single file read, then parse using foreach

      to load data [ filename ]
      file-open filename
      let variables file-read
      file-close

      foreach variables
      [ load-variable ? ]
      end

      to load-variable [ v ] 
         foreach v
         [ load-layer ? ]
      end

      to load-layer [ L ]
         let LL item 0 ? ;; layer num
         let VV item 1 ? ;; various name
         let DD item 2 ? ;; data
         ask patches [ ingest LL VV CELL DD ]
      end

      to-report CELL [ k ]
         let x  pxcor - min-pxcor
         let y pycor - min-pycor
         report item x ( item y k )
      end

      the details of ingest depend on how you are storing the layer data in the patch.

      you can organize your soil layers as a list, or  lists, or lists of lists;; or you can use turtles, one turtle per.patch per  layer, each turtle owning variables to describe the layer. you ccould also use the tables extension to use key:value pairs to store variables. or a combination, like turtles that own a layer number and key:value table for the layer data,  or a list where each items is a layer, storing a key:value table.

      hope this helps,

      ~~James

      On Apr 30, 2012 1:07 PM, "newmodturtle" <no_reply@yahoogroups.com> wrote:
      Hey there,

      I'm new to NetLogo and have a question considering the data for patches. During my research on the internet I found a lot of suggestions how to add data like age etc. to turtles, but not to patches.
      My goal is to build a cross section soil model where certain variables as water content, pH etc are part of the patch data and vary with the depth and over time. They should be imported through a list or several lists.
      I created a model where I'm able to set the patch data through an imported list, but only for colors (so just one variable). Furthermore this list contains each x and y coordinate which would be way to much data for my actual purpose.


      Does anyone have an idea about how to add various data to patches (easiest would be via lists) and what form this lists have to have?

      I appreciate every idea and hints.

      Thanks a lot, Vanessa



      ------------------------------------

      Yahoo! Groups Links

      <*> To visit your group on the web, go to:
         http://groups.yahoo.com/group/netlogo-users/

      <*> Your email settings:
         Individual Email | Traditional

      <*> To change settings online go to:
         http://groups.yahoo.com/group/netlogo-users/join
         (Yahoo! ID required)

      <*> To change settings via email:
         netlogo-users-digest@yahoogroups.com
         netlogo-users-fullfeatured@yahoogroups.com

      <*> To unsubscribe from this group, send an email to:
         netlogo-users-unsubscribe@yahoogroups.com

      <*> Your use of Yahoo! Groups is subject to:
         http://docs.yahoo.com/info/terms/

    • newmodturtle
      Hello James, At first I d like to thank you for your quick response. I know that you are an advanced NetLogo user (kind of celebrity ;) ) but I am with NetLogo
      Message 2 of 3 , May 3, 2012
        Hello James,

        At first I'd like to thank you for your quick response. I know that you are an advanced NetLogo user (kind of celebrity ;) ) but I am with NetLogo since 2.5 weeks now and have some problems with understanding your answer:

        The structure you suggested, is it supposed to be a "patches-own" statement? I tried to use the code you sent, but honestly I didn't get it completely and I'm not sure if it's working, since I want to have a 100s x 100s patch field.

        In my question I might have miss-used the word "lists", because actually I want to import .txt files each containing one variable for each layer (because this data will come out of PEARL and then be rearranged to be read by NetLogo). The lists or these text files (like excel tables) should be resolved in time versus depth (of soil) for each variable (like e.g. for water-content) such as:


        Depth [cm] 50 49 48 47 ...
        days

        1
        2
        3
        .
        .
        .
        366



        containing the values for the patches (all together approx. 1 m depth or 1.5 m and 3 years each with 366 days - time goes by with ticks).

        What has the code to be like to be able to read this files and to put it as patch data or is it possible at all? Or is there a certain design for such tables/lists? Can I use your suggested code? Or is there another approach? I actually liked your suggestion with the layers very much, but don't really know how to use it.


        I hope I don't bother you too much, otherwise I will address this question to the community again, but you seem to be an expert considering lists and layers.


        I appreciate your help very much and thank you again for your time,
        Cheers,
        Vanessa
      Your message has been successfully submitted and would be delivered to recipients shortly.