Solved

Downloading list of timeseries with metadata?


I am looking at 127 time series linked to one asset and I want to download the list of these time series as shown in the screenshot below, but this doesn’t appear to be straight forward.

  1. The download button circled in blue saves a JSON file linked only to the asset “11. QHP”. Is there a way to spare the user the effort of manually selecting and downloading each of the 127 timeseries and later reassemble them into one table like the one shown in the browser? 
  2. It is not possible to select and display more than 20 columns in the browser … due to performance issues. This is not critical at this time, but still dissatisfying. I want to download everything wholesale and pick what I need from the list locally. Is there a way around this restriction? Solving issue #1 would remedy also #2, as I’d be able to join the tables locally again.

 

Thanks

icon

Best answer by roman.chesnokov 14 May 2024, 09:08

View original

5 replies

Userlevel 3

 

Hey @Patrick Galler , you can use Jupyter Notebook as a workaround, which is built into each CDF project.  

from cognite.client import CogniteClient
client = CogniteClient()

asset_xid = "PUT YOUR DATA HERE"
tss = client.time_series.list(asset_external_ids=[asset_xid])
tss.to_pandas().to_csv(f"Timeseries for {asset_xid}.csv")

Put the external id of your asset (you can also define the list of assets), then run this code snippet and then download the result CSV file.

@roman.chesnokov, that was surprisingly easy to follow for someone who only last week familiarized with Jupyter notebooks. Thank you.

However, with the code you provided I can only download the list of  “Directly linked timeseries (11)”. Is there a way to download the list of 127 linked timeseries highlighted below?

 

 

 

For completeness, here’s the code I used:

from cognite.client import CogniteClient
client = CogniteClient()

asset_xid = "houston.11. QHP" ## which is the external id of the asset in the screenshot
## there are 11 directly linked and 127 linked time series for this asset
## I want the list of the 127 linked time series.
tss = client.time_series.list(asset_external_ids=[asset_xid])
tss.to_pandas().to_csv(f"Timeseries for {asset_xid}.csv")

 

Userlevel 3

Yes, correct. Then, we should go from the asset subtree. There is a code snippet for you.

from cognite.client import CogniteClient
client = CogniteClient()

asset_xid = "houston.11. QHP"

asset_tree = client.assets.retrieve_subtree(external_id=asset_xid)
asset_tree.time_series().to_pandas().to_csv(f"Timeseries for {asset_xid}.csv")

Let me know if it fits your needs.

@roman.chesnokov, perfect!

Final question: is it OK to request/discuss solutions like yours for other issues as well in this forum? Suppose, when I am stuck with not knowing how to write a loop in Python or something. 

Totally fine if this is not the right place.

Thank you for your help with this issue!

Userlevel 3

@Patrick Galler it’s totally OK to ask and answer the questions, we appreciate our community for being helpful and engaged.

Reply