07. Analyse Trial Results
Retrieve Output IDs
To access trial results, first retrieve the available output IDs.
from jinko import JinkoClient
client = JinkoClient()
trial = client.get_trial("tr-abc123def456")
# Retrieving the output IDs
output_ids = trial.output_ids()
print("Available time series:", output_ids)
The response provides a list of available time series data points.
Retrieve Time Series Data
Once you have identified the output IDs, you can request time series data.
trial.results.timeseries(...) handles the download and decompression for you and returns a TabularDownload, which can be converted to a pandas dataframe with .to_dataframe() (requires pandas to be installed — it's an optional dependency of jinko-sdk).
TIME_SERIES_IDS = ["x"]
summary = trial.results.summary()
arms = summary["arms"]
timeseries_download = trial.results.timeseries(
{timeseries_id: arms for timeseries_id in TIME_SERIES_IDS}
)
df_time_series = timeseries_download.to_dataframe()
Visualizing Time Series Data
The resulting dataframe can be used directly for analysis and visualization.
import matplotlib.pyplot as plt
# Filter data for a single patient
unique_patient_ids = df_time_series["Patient Id"].unique()
patient_data = df_time_series[df_time_series["Patient Id"] == unique_patient_ids[0]]
# Plot each arm separately
for arm, group in patient_data.groupby("Arm"):
plt.plot(group["Time"], group["Value"], marker="o", linestyle="-", label=arm)
# Customize the plot
plt.title("Time Series of Selected Output")
plt.xlabel("Time (seconds)")
plt.ylabel("Value")
plt.legend(title="Arm")
plt.show()
Summary
In this module, you:
- Retrieved the available output IDs for a trial.
- Requested time series data as a pandas dataframe via
trial.results.timeseries(...).to_dataframe(). - Processed and visualized the results using Python and Matplotlib.
Next, you can explore more advanced analyses, such as aggregating results across patients with trial.results.scalars(...) and trial.results.scalars_per_population(...), or applying statistical models to the data.