Extract indices as a list

I am trying to create two lists from a dataset that I have. I’d like some help with the correct approach please.

the dataset consists of 8760 values which represent the hours of the year, I want to extract the sunrise and sunset hours, so the indices are important. For sunrise, I am looking to extract the position of the first value that appears after the zero. For sunset, it’s the position of the last value that appears before the zero. In the end, I should have two lists each with 365 values.

What I’ve tried so far is to organise the list into 365 branches, so that each branch has 0-23 indices (hours). I then tried to create a set to simplify the values without altering the structure. The idea was to use the index map to extract the position of when the value=1 for sunrise and then extract the position of the highest value for sunset. I am now stuck because I am finding that I am not able to use the index map in the way that I intended.

How can I extract the indices from the index map? Is there a better approach than what I’ve suggested?

sunrise_sunset.gh (49.0 KB)

It’s my first time sharing a file, I’ve internalised the data, but if there are any issues with the file please let me know.

Thanks :slight_smile:

you can use List Item with index 1 (gets the second item) for sunrise (i guess) and -1 for sunset, then merge

EDIT:
This post assumes the indices 0…8759 are searched based on all hours of the year are counted.

The accepted solutions shows that the indices 0…23 are needed based on a daily count of the hoursresulting

sunrise_sunset_tp.gh (53.0 KB)

my (vanilla gh) approach (without c#) would be:

use shift list to get the position before (-1) and after (+1) index.
(as the year starts and ends with “0”) we do not care about wrapping the list)
then compare the items to get a “cull pattern”
generate a series of indices and cull them for sunrise and sunset …

2 Likes

Sorry I’ve misread your request.
you can use List Item with index 1 (gets the second item) for sunrise (i guess) and -1 for sunset, then flatten the output (rightclick next to the connection, and choose flatten)
that should give you the two lists. cheers


sunrise_sunset_re.gh (50.6 KB)

1 Like

:roll_eyes:

Hi,

My (very similar) solution would probably be :

1 Like

This is it, thank you!

HI, Thank you! I was looking for the indices, not the values/items :slight_smile:

I would suggest another Partition List as an alternative to the expressions

sorry i am a big fan of expressions.
especially in combination with Cull-Patterns.
I think it s very readable, if the condition for culling is in a single line.
(but maybe this is more a text-based programming - thinking…)

2 Likes

Oh. I guess i’ve missread you twice XD

I realize this is solved, but for academic purposes, here’s an alternative
After you parsed the lists to the set, you know your two values have indices of 1 and -1 ( -1 here means the last item of the list, -2 the one before that, etc). With those you can extract the two values, and then use them to find the indices where they are in the original lists

1 Like