Grow based on two lists

I wanna make Python program base on two lists.

This program has been created by Honeybee.

I would like to create a program to grow based on solar radiation analysis data.
Two Panel has Analysis point or Amount of solar radiation.

coz create a program that grows based on these two lists.

solar_tim.gh (424.9 KB)(made by @tim.stark )

This program is growing using one list index.
but this time I have to create it based on two lists(Analysis point or Amount of solar radiation). Right?

reference images


I want to grow this box based on Analysis point or Amount of solar radiation.

Thank you so much!

Hi I dont think I understand the question clearly : what aspect do you need help with?
You can input both lists into your Python component.
If the lists are the same length so point 10 in list1 corresponds to radiation value 10 in list2 then you can use combined = zip(list1, list2) to get a new list of tuples of (point, radiation)
Graham

1 Like

Thank you so much!!

I wanna know that how to use tuples.
Can you create it based on this code?
solar_tim ver1.gh (416.2 KB)

Hello,
Here is a quick introduction to tuples.
https://www.tutorialspoint.com/python/python_tuples.htm

Basically if you use
combined = zip(list1, list2)
to generate a list of tuples then you can iterate over them like this:

for tup in combined:
    MyPoint, PointRadiationResult = tup
    # do something

I’m afraid I cant help you with your specific script as I dont have grasshopper at the moment and have never used HoneyBee

1 Like

Thank you Graham!

Why use tuples instead of lists?

import Rhino.Geometry as rg
import random as rnd

class System():
    def __init__(self, startIndex, radiationResult):
        self.Indices = [startIndex]
        self.radiation = [radiationResult]
        print [radiationResult]
        
    def AddNeighbour(self, testPts): 
        biggestIndex = -1
        for index,Result in zip(self.Indices, self.radiation): 
            neighbourIndices = list(rg.RTree.Point3dClosestPoints(testPts, [testPts[index]], iGridSize + 0.1))
            for neighbour in neighbourIndices[0]:
                if neighbour > biggestIndex:
                    if neighbour not in self.Indices:
                        biggestIndex = neighbour
                       
        if biggestIndex > -1: 
                self.NewNeighbour = biggestIndex
            
            
    def Update(self):
        self.Indices.append(self.NewNeighbour)
       

###########################################

grid = testPts 
if iRun:
    if iReset or "system" not in globals():
        system = System(iStartIndex, radiationResult)
    else:
       system.AddNeighbour(grid)
       system.Update()
        
        
finalPts = []
if "system" in globals():
    for index in system.Indices:
        finalPts.append(grid[index])
oPts = finalPts

I use zip function!
but data have radiationResult list[0]
why?

You are very welcome :slight_smile:
Just because the zip function returns a list of tuples [(x0, y0), (x1,y1), …]

I dont understand :confused: ???

1 Like

This should do what you want. Just small modification:

  1. Add new Input called iValues (list, float)
    def AddNeighbour(self, pts):
        biggestValue = -1
        for index in self.Indices:
            neighbourIndices = list(rg.RTree.Point3dClosestPoints(pts, [pts[index]], iGridSize + 0.1))
            for neighbour in neighbourIndices[0]:
                if iValues[neighbour] > biggestValue:
                    if neighbour not in self.Indices:
                        biggestValue = iValues[neighbour]
                        newIndex = neighbour
        if newIndex > -1: 
                self.NewNeighbour = newIndex

forum_190207_02.gh (14.8 KB)

2 Likes

Hi, Tim!

Thank you so much!
I succeeded this problem.

but i wanna tell me about iValues.

Is iValues value method?
Did you make the dictionary date?

What do you mean?

I named the input iValues. It’s just a name for the list of floats containing your radiation data (second list)

Why can iValues get (list, float)?

It’s really great to get on with the new variables iValues and I just want to know more.

The question may be strange, but please let me know.

Thank you so much.

Why? Because you wanted to use your radiation result for the growing. That’s why I had to add another input.

If you want to understand the code I recommend you learning the Basics of python