Skip to main content

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

 

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=dasset_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=tasset_xid])
tss.to_pandas().to_csv(f"Timeseries for {asset_xid}.csv")

 


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!


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


@roman.chesnokov, apologies. I am running either this

from cognite.client import CogniteClient 
client = CogniteClient()
asset_xid = "houston.11. QHP" # ... for this asset
tss = client.time_series.list(asset_external_ids=[asset_xid])
tss.to_pandas().to_csv(f"Timeseries for {asset_xid}.csv")

or this

from cognite.client import CogniteClient 
client = CogniteClient()
asset_xid = "houston.11. QHP" # ... for this asset
asset_tree = client.assets.retrieve_subtree(external_id=asset_xid)
asset_tree.time_series().to_pandas().to_csv(f"Timeseries for {asset_xid}.csv")

but always get this error message

---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[7], line 4
1 # this gets the linked time series only ...
3 from cognite.client import CogniteClient
----> 4 client = CogniteClient()
5 asset_xid = "houston.11. QHP" # ... for this asset
6 asset_tree = client.assets.retrieve_subtree(external_id=asset_xid)

File ~\AppData\Roaming\Python\Python311\site-packages\cognite\client\_cognite_client.py:50, in CogniteClient.__init__(self, config)
48 def __init__(self, config: ClientConfig | None = None) -> None:
49 if (client_config := config or global_config.default_client_config) is None:
---> 50 raise ValueError(
51 "No ClientConfig has been provided, either pass it directly to CogniteClient "
52 "or set global_config.default_client_config."
53 )
54 else:
55 self._config = client_config

ValueError: No ClientConfig has been provided, either pass it directly to CogniteClient or set global_config.default_client_config.

What am I doing wrong?


Hey @Patrick Galler , are you running this code snippet in the CDF Jupyter notebook?


@roman.chesnokov, no. I ran it from miniconda on my laptop. Also, I tried finding the CDF Jupyter notebook. My impression was that it was in a really obvious location. Today, I browsed through CDF a couple of times without succes, so gave up. Here I am ...


@roman.chesnokov, by the way, this used to work from a Jupyter notebook on my miniconda installation earlier. 


@Patrick Galler if you run it locally, you need to follow the auth flow to instantiate the client. In the Jupyter Notebook in CDF, you’re getting the client authenticated automatically with your credentials. 

The Notebook is in the Data management workspace under the Build solutions menu:

 


@roman.chesnokov, thanks! Again, very useful. It’s weird. I am almost definitely certain I used to run this code locally as I’ve pasted it in above without problems. I’ve never as much as touched the Notebooks in CDF. Alas, it works in the CDF notebook now. 

 

FYI, locally, before every CDF “session” I run the below. 

 

I can still download timeseries using a local Notebook:

 

As a result, it was both surprising and frustrating to note that I can’t download metadata in the same notebook.


Ah, I see! then you just reinstantiate the client with an empty config. Just remove those 2 lines, it should work then. 

 


@roman.chesnokov, wow, it works now. That’s cool. Thanks for resolving yet another issue! I’m relieved. Have a great day!


Reply