Dataset Report Notebook

With this notebook you can create a report on a data set as a pdf and html document.

The diagrams are displayed and the parameters of the data set. You can also display only a few parameters that you need. To do this, you can set them as parameter, as shown below.

If you choose to print the report, we recommend using Google Chrome for the best results.

To run this notebook you need a Jupyter kernel. A kernel is a Python environment that executes the code from your notebook. If no Jupyter kernel is set up yet, you can register one with the following command in the terminal:

python -m ipykernel install --user --name env_name --display-name "YourName"

Imports

Please import all necessary modules first by executing the following section

#!/usr/bin/env python3

import sys
sys.path.append("/home/zischka/Documents/logs-py-public-solutions/logs-py-solutions-public/pypi-package") # TODO: Remove after testing
from LOGS import LOGS
from LOGS_solutions.GenerateDatasetReport.DatasetReportGenerator import DatasetReportGenerator

Parameters

Please set the parameters as you like.

target_path: Path, where the dataset should be stored, if None the directory of the script will be used as target path.

dataset_id: The id of the dataset for which the report will be created.

param_category: Dictionary which includes all needed categories. Please use the following format for the param_category:
{“Category name”: [“parameter1”, “parameter2”, …]} The category name has to be the name of the first category not of the subcategory.
If you want all of the parameters of the given category please use the following format: {“Category name”: []}
If the param_category is not set, the all of the categories will be in the report.
Filtering parameters of subcategories or their nested subcategories is not supported.
excluded_tracks: List with the names of the tracks which should be excluded in the report, if empty all tracks will be included.
separate_complex_plots: If True, the complex plots will be separated into real and imaginary parts. Default: True


Important: This classes uses absolute paths. To obtain the correct absolute path, you must ensure that the relative path is correct in relation to the directory in which the script is executed. If you are not sure, use the absolute path for target_path. If you want to use the directory of the script as target_path, than you don't have to set one.

target_path = "reports"
dataset_id = 99 #TODO: change to 1 after testing, Testscript: 99
param_category = {"Unit parameter":["Parameter 1", "Periodic table", "SI voltage"], "Kingdom": []} # Optional
excluded_tracks = ["one", "two"] # Optional
separate_complex_plots = True # Optional

Create a report for a specific dataset by ID

If you want to generate a report only for the dataset with the ID you specified earlier, use the code below. To generate reports for all datasets, please use the alternative code provided further down.

logs = LOGS()    

datasets_report = DatasetReportGenerator(
    logs=logs,
    dataset_id=dataset_id,
    target_path=target_path,
    #param_category=param_category,
    #excluded_tracks=excluded_tracks,
    separate_complex_plots=separate_complex_plots,
)

datasets_report.create_datasets_report()
WARNING:LOGS_solutions.GenerateDatasetReport.DatasetReportGenerator:The param_category is not a dictionary or is not set. All categories will be included in the report.
Eule1.png
None
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[3], line 12
      1 logs = LOGS()    
      3 datasets_report = DatasetReportGenerator(
      4     logs=logs,
      5     dataset_id=dataset_id,
   (...)
      9     separate_complex_plots=separate_complex_plots,
     10 )
---> 12 datasets_report.create_datasets_report()

File ~/Documents/logs-py-public-solutions/logs-py-solutions-public/pypi-package/LOGS_solutions/GenerateDatasetReport/DatasetReportGenerator.py:937, in DatasetReportGenerator.create_datasets_report(self)
    934 track_number = len(self._dataset.tracks) if self._dataset.tracks else 0
    936 if track_number > 0:
--> 937     page["images"], track_types = self.get_graph(self._dataset)
    938 else:
    939     page["images"] = []

File ~/Documents/logs-py-public-solutions/logs-py-solutions-public/pypi-package/LOGS_solutions/GenerateDatasetReport/DatasetReportGenerator.py:766, in DatasetReportGenerator.get_graph(self, dataset)
    763     fig = self.plot_table(track)
    765 elif track.type == "image":
--> 766     fig = self.plot_image(track)
    768 else:
    769     logger.warning(
    770         "Track type %s is not supported for plotting. Skipping track %s.",
    771         track.type,
    772         track.name,
    773     )

File ~/Documents/logs-py-public-solutions/logs-py-solutions-public/pypi-package/LOGS_solutions/GenerateDatasetReport/DatasetReportGenerator.py:553, in DatasetReportGenerator.plot_image(self, track)
    551 track.fetchFull()
    552 print(track.datatracks)  # TODO: Remove debug print
--> 553 image_np = np.array(track.datatracks.image.data)
    554 fig, ax = plt.subplots()
    556 ax.imshow(image_np)

AttributeError: 'NoneType' object has no attribute 'image'

Create reports of all datasets

If the report is to be generated for all datasets, uncomment the entire cell below.

# logs = LOGS()   

# def process_dataset(dataset):
#     dataset_id = dataset.id
#     try:
#         datasets_report = DatasetReportGenerator(
#             logs=logs,
#             dataset_id=dataset_id,
#             target_path=target_path,
#             # excluded_tracks=excluded_tracks,
#             # param_category=param_category,
#             separate_complex_plots=separate_complex_plots,
#         )
#         datasets_report.create_datasets_report()
#     except Exception as e:
#         with open("failed_datasets_notebook.txt", "a") as f:
#             f.write(f"{dataset_id}: {e}\n")

# for dataset in logs.datasets():
#     process_dataset(dataset)