Working with Files¶
To demonstrate working with files, we notice that DataSheet is an extension of CogniteFile in the WindTurbine model
In [2]:
Copied!
from wind_turbine import WindTurbineClient
from wind_turbine import WindTurbineClient
In [3]:
Copied!
pygen = WindTurbineClient.from_toml("config.toml")
pygen = WindTurbineClient.from_toml("config.toml")
Listing file metadata¶
We can list the filemetadata directly with the data_sheet attribute
In [5]:
Copied!
files = pygen.data_sheet.list(limit=5)
files
files = pygen.data_sheet.list(limit=5)
files
Out[5]:
| space | external_id | is_uploaded | name | uploaded_time | data_record | |
|---|---|---|---|---|---|---|
| 0 | files_metadata_instances | PH-25578-P-4110119-001.pdf | True | PH-25578-P-4110119-001.pdf | 2024-10-20 15:00:15.655000+00:00 | {'version': 4, 'last_updated_time': 2024-10-20... |
| 1 | files_metadata_instances | PH-ME-P-0153-001.pdf | True | PH-ME-P-0153-001.pdf | 2024-10-20 15:00:17.037000+00:00 | {'version': 6, 'last_updated_time': 2024-10-20... |
| 2 | files_metadata_instances | PH-ME-P-0152-001.pdf | True | PH-ME-P-0152-001.pdf | 2024-10-20 15:00:16.770000+00:00 | {'version': 6, 'last_updated_time': 2024-10-20... |
| 3 | files_metadata_instances | PH-ME-P-0160-001.pdf | True | PH-ME-P-0160-001.pdf | 2024-10-20 15:00:17.793000+00:00 | {'version': 6, 'last_updated_time': 2024-10-20... |
| 4 | files_metadata_instances | PH-ME-P-0156-002.pdf | True | PH-ME-P-0156-002.pdf | 2024-10-20 15:00:17.530000+00:00 | {'version': 6, 'last_updated_time': 2024-10-20... |
Retriving File Content¶
To retrieve data points we use the .select() method in the same way as when we do regular queries.
For example, if we want to view the data_sheet for the hornsea_1_mill_1 turbine:
In [6]:
Copied!
from pathlib import Path
from pathlib import Path
In [9]:
Copied!
my_dir = Path("my_dir")
my_dir.mkdir()
my_dir = Path("my_dir")
my_dir.mkdir()
In [10]:
Copied!
(pygen.wind_turbine.select().name.equals("hornsea_1_mill_1").datasheets.content.download(my_dir))
(pygen.wind_turbine.select().name.equals("hornsea_1_mill_1").datasheets.content.download(my_dir))
In [11]:
Copied!
list(my_dir.iterdir())
list(my_dir.iterdir())
Out[11]:
[WindowsPath('my_dir/windmill_schematics.pdf')]
In [13]:
Copied!
# cleanup
import shutil
shutil.rmtree(my_dir)
# cleanup
import shutil
shutil.rmtree(my_dir)
In [ ]:
Copied!