Can't read data in GH_Cpython

Hello everyone,

I am a Python beginner.
I would like to use the component GH_CPython to analyse my data, but I can’t get it to read the data by GH_CPython. The data consists of branches and represents values (based on penalty function) for four sensors, 8760 hours and four states (0, 45, 90, 135 degrees vertical blinds). So, (48760*4) 140.160 datapoints.

How is it possible to les GH_CPython read my data and approach it as an 3D-array (4,8760,4)?

I saw that it is also possible to make an CSV file, but I also can’t get it to read the csv-file with GH_Cpython. I prefer to use GH_Cpython in stead of the component python script, because I would like to use pandas and numpy. But if it is possible to use pandas and numpy in the component python script, I would like also like to know how I can read the data in this component.

I attach my script so you can see the structure of the data
Verticalblinds_GHCpython.gh (936.0 KB)

Thank you so much in advance!

Kind regards,
Kim

Hi,

Without knowing what you would like to achieve as the end goal, it’s hard to determine how the data should be read and stored within the python component for further post-processing.

Personally I like to store my data as a dictionary since it is somewhat similar to the way datatree works in grasshopper. Attached is an example of how to read the data and store it in a result dictionary with following logic: result = { point_id: {blindstate: data} }
Before read in the data I re-parameterize it a bit.

data_ghpy.gh (353.4 KB)

I’m not against CPython nor pandas, numpy, etc, however, as a beginner I think it is rather important to learn how data structure works in native python before taking shortcuts, just a thought.

vhoang,

Thank you so much for you help! I agree with you I need to learn more about data structures, but I assumed that using numpy and pandas would be the easiest way. But I will do it without them, but I don’t know how. My end goal is to make a schedule for the state of the vertical for each hour and the year for an office room.

I have four sensors in an office room. For each sensor, I have values (based on penalty function) for each hour of the year and for each state (I used for states: 0, 45, 90, 135). So, 487604 values. Here is an image of my results in grasshopper. {sensor;hour;state} So the value 1.7971 represents the value for sensor 0, hour 1, and state 2.
image

What I would do with the data is:

Step 1: I would like to summate the values for each of the four states from all the four sensors for all the 8760 hours. For example:

state_0_hour_1 = state_0 _hour_1_sensor_1 + state_0 _hour_1_sensor_2 + state_0 _hour_1_sensor_3 + state_0 _hour_1_sensor_4.
state_0_hour_2 = etc…

So this would give me a list of 4 columns and 8760 rows.
Step 2: Subsequently I would like to find the minimum for each hour. This will give me state with the lowest value for each hour.

For example:

Minimum(state_0 _hour_1, state_45 _hour_1, state_90 _hour_1, state_135 _hour_1)

Step 3: Finally, I would like to know from which of the four columns the minimum value is coming from.
For example I would give the columns a number:
1: state_0
2: state_45
3: state_90
4: state_135
This will give a list with 8760 rows and for each row a number (1,2,3 or 4) which represent the state of the blinds.

I hope that it is now a little more clear what my end goal is, but it not very easy to explain it clear.

Do you have advice for me about how I can achieve this with Python in Grasshopper. For example:
How can I select every hourly value for a certain state for all the four sensors and summate them? And how do I pick the minimum value? How do I subsequently track down the list and so the blinding state?

Kind regards,

Kim Bodde

Step 1: I entered my data into your file ‘data_ghpy.gh’:

data_ghpy.gh (369.9 KB)

Do you have any tips for me regarding informative website about GH python or examples?

Hi,

You can actually use directly the native grasshopper components to get what you want. Attached you can find the solution both in native grasshopper and ghpython. I made a mistake earlier trying to convert the input data tree but it seems maintaining the tree would make the post-process much easier.

data_ghpy_v2.gh (357.7 KB)

Regarding ghpython, you can find a lot of information on rhino & python under the guide by McNeel. However, when it comes to working with dataset in general, most of the stuffs I learned was from general python, which you can learn online easily with codademy, datacamp, etc. There they also teach you panda, numpy as well, depending on the course.

V

1 Like

Hi,

Thank you so much for your help! Unfortunately, I have no license for Rhino 6, so the component ‘treehelpers’ doesn’t work. Can I also replace this for another component?

Kind regards,

Kim Bodde

You can copy the list_to_tree function from piac’s github, he was the one who developed the function into Rhino6 ghpy standard library.

V

Thank you so much for your patience and help!
It works and that makes me very happy!