User Tools

Site Tools


howtos:toolcoding:using_maps

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
howtos:toolcoding:using_maps [2011/06/14 18:08]
chris.strashok
howtos:toolcoding:using_maps [2011/06/17 16:03] (current)
chris.strashok
Line 1: Line 1:
 ====== Working with Maps ====== ====== Working with Maps ======
  
-Mapping allows you to pass the elements from one variable into the elemants of another variable based on defined map structure. Here we will outline the instances that mapping is used.+Mapping allows you to transform ​the data in one variable ​(defined by one or more informants) ​into another variable ​(with different informants), ​based on defined map structure. Here we will outline the instances that mapping is used.
  
 ===== Map Tool ===== ===== Map Tool =====
  
-The map tool is the main way to map the elements in one variable according to a map into the elements in another variable. There are three main types of maps that the map tool uses: full matrix, dimension and index. Examples and uses of these mapping types are explored below+The map tool is the main way to map the elements in one variable according to a map into the elements in another variable. There are three main types of maps that the map tool uses: full matrix, dimension and index. Examples and uses of these mapping types are explored below.
  
 ==== Full Matrix Mapping ==== ==== Full Matrix Mapping ====
Line 239: Line 239:
 ===== Mapcat Tool ===== ===== Mapcat Tool =====
  
-Categorizations are useful ​ways of grouping elements into meaningfull collections. By categorizing related elements together you can create elements that are more descriptive while also reducing the number of elements you are carrying through your model.+A //​category//​ is a useful ​way of grouping elements into meaningfull collections. By categorizing related elements together you can create elements that are more descriptive while also reducing the number of elements you are carrying through your model.
  
-The mapcat tool is used to map group and member element informants onto category and conversely it is also used to "​break" ​category apart into its compnent group and member informants using the mapcat tool.+The mapcat tool can also be used for aggregating elements into classes or groups. The example below uses the data found in the following table to use the categorization as map to transform the population data for each province ​to a region class while aggregating over each province to get the total population in each region.
  
-{{:​howtos:​toolcoding:​mapdata5.gif|}}+{{:​howtos:​toolcoding:​mapdata5_rev1.gif|}}
  
-The supporting tool script code for building the informants and importing data from the data source in the table above can be found [[howtos:​toolcoding:​mapEx5|here]].+The supporting tool script code for building the informants and importing data above can be found [[howtos:​toolcoding:​mapEx5|here]].
  
-The mapping template for a category is held in the category itself. As you can see in the code below the provinces is the group place holder and the location ​are members of the province and they are related to each based on a relationship provided by the modeler.+The mapping template for a category is held in the category itself. As you can see in the code below the provinces is the group place holder and the locations ​are members of the province and they are related to each based on a relationship provided by the modeler.
  
 <​code>​ <​code>​
  
-localinformant ​provLoc[p->l] = create (; object=category,​ groups=province, members=location, \ +localinformant ​locProv[l->p] = create (; object=category,​ groups=location, members=province, \ 
- "Alberta"​="​west", \ + "west"​="​Alberta", \ 
- "British Columbia"​="​west",\ + "west"​="​British Columbia",\ 
- "Newfoundland"​="​east",\ + "east"​="​Newfoundland",\ 
- "Nova Scotia"​="​east",\ + "east"​="​Nova Scotia",\ 
- "Ontario"​="​central",\ + "central"​="​Ontario",\ 
- "PEI"​="​east")+ "east"​="​PEI")
  
 </​code>​ </​code>​
  
-This categorization or map can then be applied using the mapcat tool below to either ​bring the elements together in the category ​or split the category apart+This categorization or map can then be applied using the mapcat tool below to bring the elements together in the category.
  
 <​code>​ <​code>​
  
-local regionsCat[p->l] = mapcat (regionData[p,l]; category=provLoc)+local provLoc_Cat[l->p] = mapcat (provinceData[p]; category=locProv)
  
-table (regionsCat[p->l])+table (provLoc_Cat[l->p])
  
 </​code>​ </​code>​
  
-The table below displays ​how the province and location informants have been categorized into the provLoc category.+See how the province and location informants have been categorized into the provLoc category.
  
-{{:​howtos:​toolcoding:​mapresults5a.gif|image}}+{{:​howtos:​toolcoding:​mapresults5a_rev1.gif|}} 
 + 
 +Now we can use the mapcat tool again, but this time we will be splitting the category back up into the respective group and members.
  
 <​code>​ <​code>​
  
-local regionsSplit[p,l] = mapcat (regionsCat[p->l])+local regions[l,p] = mapcat (provLoc_Cat[l->p])
  
-table (regionsSplit[p,l])+table (regions[l,p])
  
 </​code>​ </​code>​
  
-Inversely the table below displays ​how we can split the category onto its component group and member informants+See how we have now created a two dimensional array from a data set that only had one dimension.
  
-{{:​howtos:​toolcoding:​mapresults5b.gif|image}}+{{:​howtos:​toolcoding:​mapresults5c.gif|}}
  
 +We can now sum up the provinces dimension to get the total population for each region as seen in the table below.
 +
 +<​code>​
 +
 +local regions_sum[l] = sum (regions[l,​p];​ \
 + dim=province)
 +
 +table (regions_sum[l])
 +
 +</​code>​
 +
 +{{:​howtos:​toolcoding:​mapresults5b_rev1.gif|}}
 +
 +This process has been broken down inorder to see how the transformation occurs, however there is no need to take this many steps. This process can be done on one line by combining the two mapcat and sum tool commands as follows:
 +
 +<​code>​
 +
 +local regions[l] = sum (mapcat (mapcat (provinceData[p];​ \
 + category=provLoc);​ \
 + dim=provLoc);​ \ 
 + dim=province)
 +
 +</​code>​
howtos/toolcoding/using_maps.1308074920.txt.gz · Last modified: 2011/06/14 18:08 by chris.strashok