From 230f6484db35039aac4a9e6c63e6c5eb525424ec Mon Sep 17 00:00:00 2001 From: Radonirinaunimi Date: Tue, 26 Nov 2024 19:51:47 +0100 Subject: [PATCH] Exposes `key_values` and `set_key_values` for `PyFkTable` --- pineappl/src/fk_table.rs | 7 +++++++ pineappl_py/src/fk_table.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/pineappl/src/fk_table.rs b/pineappl/src/fk_table.rs index 9300b42d..4e81a2ba 100644 --- a/pineappl/src/fk_table.rs +++ b/pineappl/src/fk_table.rs @@ -219,6 +219,13 @@ impl FkTable { muf2 } + /// Set a metadata key-value pair for this FK table. + pub fn set_key_value(&mut self, key: &str, value: &str) { + self.grid + .metadata_mut() + .insert(key.to_owned(), value.to_owned()); + } + /// Returns the x grid that all subgrids for all hadronic initial states share. #[must_use] pub fn x_grid(&self) -> Vec { diff --git a/pineappl_py/src/fk_table.rs b/pineappl_py/src/fk_table.rs index 8286a7fb..a96e6f5f 100644 --- a/pineappl_py/src/fk_table.rs +++ b/pineappl_py/src/fk_table.rs @@ -7,6 +7,7 @@ use pineappl::convolutions::ConvolutionCache; use pineappl::fk_table::{FkAssumptions, FkTable}; use pineappl::grid::Grid; use pyo3::prelude::*; +use std::collections::BTreeMap; use std::fs::File; use std::io::BufReader; use std::path::PathBuf; @@ -251,6 +252,31 @@ impl PyFkTable { .unwrap(); } + /// Set a metadata key-value pair in the FK Table. + /// + /// Parameters + /// ---------- + /// key : str + /// key + /// value : str + /// value + pub fn set_key_value(&mut self, key: &str, value: &str) { + self.fk_table.set_key_value(key, value); + } + + /// Get metadata values stored in the grid. + /// + /// + /// Returns + /// ------- + /// dict : + /// key, value map + #[getter] + #[must_use] + pub fn key_values(&self) -> BTreeMap { + self.fk_table.grid().metadata().clone() + } + /// Convolve the FK table with as many distributions. /// /// # Panics