How can I place points on a grid in a specific location?

Hi Joseph,

I want the circles to remain as they are, I don’t want to flatten them. I know the previously attached image only shows one highlighted column but I wanted to see if there is an overlap between country and year for the highest level of pollution. Is there a way for grasshopper to do this?

Here is a simple color gradient applied to the circles (deep purple group), using the same source domain as the ReMap that sets circle radius. As before, when you flatten the input to Bnd (Bounds) input, the circles become globally relative in size.

Thank you so much!

Can that be applied to only one column? The column with the highest values?

Well yeah, but… the range of values even in one column is so extreme that the result is meaningless. It may help some if you leave out the aggregate regions. More importantly though, if you don’t know how the code works up to this point (?), this might be a bridge too far. Too complex?

GRID_2020Dec29c.gh (27.6 KB)

This is the simpler (and prettier) gradient by row from previous post.

GRID_2020Dec29b.gh (21.1 KB)

There is a data tree mismatch in this code. :frowning: An off-by-one error, for one thing. It’s been there all along, Zimbabwe appears twice. :man_facepalming: And something else is wrong too… possibly limited to the version ‘c’ highlighting code. Oh dear…

P.S. OK, maybe not as bad as I feared. The off-by-one error is simple to fix; add the expression “x-1” to the ‘Extent Y’ input of Rectangular. The ‘Extent X’ input doesn’t need it because the first point in each row is used by the country/region labels and then disappears thanks to the Shift List with ‘W’ (Wrap) input inverted (False).

The problem with column highlighting goes away when you flatten the input to Bnd (Bounds), as recommended all along. Without flattening, every row has a maximum radius circle which isn’t appropriate for the color coding being applied by column, which is based on data values.

GRID_2020Dec29b2.gh (29.0 KB)
GRID_2020Dec29c2.gh (37.0 KB)

Hi Joseph,

Thank you for all of your help! I’ll leave it as it is, my knowledge of grasshopper is very limited, I’m still trying to understand the script as I need to explain it to my tutors so I agree, it’s best not to complicate it any further.

Again, thank you so much!

Would it be possible for you to help me with another script?

What is it about this model you don’t understand? Domain bounds and remap? Member index? Ask questions please before moving on to another one.

  1. What does the shift list do? And why did you need to invert the wrap? The Addition component?

  2. What does the tree branch component do? And why did you simplify it?

  3. For the grid, I don’t understand the different expressions for “sixe x” and “extent y” and also why did you reverse the points? and what does the flip matrix do? and the create set component?

  4. And I dont understand the member index? I kind of understand remap but not completely.

Thank you for your questions.

Shift List works with any list (numbers, points, curves, whatever) to rearrange the list by moving its start point to a different element inb the list, shifting all elements either “left” (when ‘S’ is positive) or “right” (when ‘S’ is negative). Wrap (‘W’) defaults to True, meaning no list elements are lost; instead, they are “rotated” to the beginning or end of the list. Inverting ‘W’ (Wrap) is a shortcut way of changing it to False, which causes shifted elements to be discarded.

shift_list_2020Dec30a
shift_list_2020Dec30a.gh (9.9 KB)

In the grid model, I am using a value of 3 for ‘S’ (Shift offset) with wrap = False to eliminate the first three ‘Data Columns’: Entity, Code and Year. This leaves only the 17 columns offered as choices:

The Addition component adds the same shift offset value (3) to the slider value (0 to 16) to give the correct index value (19 in this case) for accessing the data, which wasn’t affected by Shift List.

1 Like

The expression “x*2” on the ‘Size X’ input to Rectangular is because the ‘R_max’ slider value is the maximum radius of the circles, so the grid cells have to be twice as wide to keep them from overlapping.

The expression “x-1” on the ‘Extent Y’ input to Rectangular is because that component returns one more column and one more row of points than the ‘Extent X’ and ‘Extent Y’ values it receives. The extra column of points is used for the country/region labels. Then Shift List after Flip Matrix eliminates that first point in each row for the column labels (years). The “x-1” expression on the ‘Extent Y’ input is to avoid the off-by-one row issue that caused Zimbabwe to appear twice.

The ‘Points’ output of Rectangular is reversed because the list of countries is reversed if I didn’t. The grid rows are numbered from bottom to top and we want countries listed top to bottom.

PAUSE: This is turning into an exhaustive explanation of data trees so let me explain how to fish for answers yourself…

  • Connect text panels to see data trees before and after any component or set of components. There is a pattern to be recognized and matched, even without full understanding. Only wire text panels so they can be removed without affecting anything else.

  • Search the forum for examples of specific components like Flip Matrix and Create Set.

  • Try stuff and see what happens! Like undo that Reverse on the ‘Points’ output, remove or change an expression or invert wrap on Shift List. A little crude but be bold, the worst that can happen is freezing Grasshopper/Rhino because a data tree mismatch turns a few hundred items into hundreds of thousands (or worse).

  • Use this ‘Tree/List Viewer’ tool to examine data trees of geometry (points, circles, etc.):

Try the recommended text panel method to see what Tree Branch does:

BEFORE shows a data tree with 231 branches (one per country/region).
AFTER shows only one branch of that tree, specified by the ‘P’ (Path) input, which in this case is “hard-coded” to “{0}” in both copies of Tree Branch.

Simplify is used to make sure the path value (“{0}”) is valid, regardless of how many extraneous leading or trailing zeros each tree might contain. So it works with both of these trees:

{0;0;0;0}
{0;0;1;0}
{0;0;2;0}
{0;0;3;0}
{0;0;4;0}
etc.

and:

{0;0}
{0;1}
{0;2}
{0;3}
{0;4}
etc.

When simplified, they both look the same:

{0}
{1}
{2}
{3}
{4}
etc.

It’s a confusing and controversial subject because Simply is not needed in most cases for data trees to match and work correctly. But in some cases like this when a path value is used, it can be required.

Who boy, I asked for it, didn’t I. Critical questions for sure, but I’m running out of steam…

I can’t do justice to Member Index (MIndex) because there are multiple ways of using it, all dependent on some understanding of sets. The particular pattern I’m using here with two copies of Create Set (CSet) is one I always have to copy from that thread I referred you to:

In the grid model, the vast data tree (in the first highlighted text panel below) of redundant country/region labels (column zero in the CSV data) becomes a set (when flattened!) of 231 unique countries/regions (shown in the second highlighted text panel).

The MIndex ‘I’ (Indices) is a data tree of index values with 231 branches, each with 28 index values (one per year) that is used in two different ways:

  1. to get a data tree of years (the third column of data where all branches are the same for each country) and
  2. to get a data tree of the death counts (one of the 17 data columns selected earlier)

MIndex_2020Dec30a2

This MIndex pattern is useful for many things. I haven’t explained how it works so much as how it is used.

Pau for now. (Hawaiian for “done”)

1 Like

Hi Jospeh,

Thank you for the explanation. It’s really helpful, I’ve been using the panels to better understand the changes, however, I can see that the create set component reduced the original list length from 6160 to 220 (dividing it by 28 the number of years) but did you have to input a value somewhere for it to do that or does the component just know’s to do that?

This is all very helpful and useful. Thank you!

Sounds like you have modified your data set so my numbers are different than yours.

Of the 6160 values in the original list, Create Set finds 220 that are unique, all the rest are duplicates. That’s the whole point of a set.

Ohhhhh… I understand! Thank you!

And yes, I removed some of the “entity” data like world, High SDI, High-income etc…I didn’t think they were necessary.

Take a look at the ‘M’ (Map) output of CSet used by MIndex. You will see that the first 28 values are zero, meaning they are all mapped to set element 0 (Afghanistan). The next 28 values are ‘1’, mapped to set element 1 *(Albania). And so on.

The beauty of it is that it works regardless of the order of the original list, which in this case is sorted by the set values, but it doesn’t have to be.

Thanks a lot!

For the next script, I have a 2D map (a shapefile), which I have plotted some points on using the countries Latitude and Longitude but I want to make it 3D on a globe/sphere…How might I do that?

World Air Pollution Map.gh (15.0 KB) List of Countries 301220cb.csv (28.2 KB)

Start a new thread and be sure to post your ne_10m_admin_0_countries.shp file.

P.S. Two of the countries in your list have a quote in them:

  • "Hong Kong SAR
  • "Yemen

The first one is where that large value is coming from.

It’s not allowing me to upload a shapefile.