Skip to content

Commit

Permalink
storage options in ffsrunconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
cgevans committed Jun 28, 2024
1 parent 7ca77d7 commit e50b513
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions rgrow/src/ffs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ pub struct FFSRunConfig {
pub canvas_type: CanvasType,
pub tracking: TrackingType,
pub target_size: NumTiles,
pub store_ffs_config: bool,
pub store_system: bool,
}

impl Default for FFSRunConfig {
Expand All @@ -107,6 +109,8 @@ impl Default for FFSRunConfig {
canvas_type: CanvasType::Periodic,
tracking: TrackingType::None,
target_size: 100,
store_ffs_config: true,
store_system: false,
}
}
}
Expand All @@ -131,6 +135,8 @@ impl FFSRunConfig {
"min_nuc_rate" => self.min_nuc_rate = v.extract()?,
"canvas_size" => self.canvas_size = v.extract()?,
"target_size" => self.target_size = v.extract()?,
"store_ffs_config" => self.store_ffs_config = v.extract()?,
"store_system" => self.store_system = v.extract()?,
_ => {
return Err(PyTypeError::new_err(format!(
"Unknown FFSRunConfig setting: {k}"
Expand Down Expand Up @@ -162,6 +168,8 @@ impl FFSRunConfig {
min_nuc_rate: Option<Rate>,
canvas_size: Option<(usize, usize)>,
target_size: Option<NumTiles>,
store_ffs_config: Option<bool>,
store_system: Option<bool>,
) -> Self {
let mut rc = Self::default();

Expand Down Expand Up @@ -215,6 +223,12 @@ impl FFSRunConfig {
if let Some(x) = target_size {
rc.target_size = x;
}
if let Some(x) = store_ffs_config {
rc.store_ffs_config = x;
}
if let Some(x) = store_system {
rc.store_system = x;
}
rc
}
}
Expand Down Expand Up @@ -643,7 +657,7 @@ pub struct FFSRunResult {
}

#[cfg_attr(feature = "python", pyclass)]
#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FFSRunResultDF {
#[serde(skip)]
pub surfaces_df: DataFrame,
Expand Down Expand Up @@ -675,7 +689,7 @@ impl FFSRunResultDF {
let file = std::fs::File::open(format!("{}.configurations.parquet", prefix))?;
let configs_df = ParquetReader::new(file).finish()?;
let file = std::fs::File::open(format!("{}.ffs_result.json", prefix))?;
let ffs_result: FFSRunResult = serde_json::from_reader(file).unwrap();
let ffs_result: FFSRunResultDF = serde_json::from_reader(file).unwrap();
Ok(Self {
surfaces_df,
configs_df,
Expand Down Expand Up @@ -1044,8 +1058,12 @@ impl FFSRunResult {
}
})?;

res.ffs_config = Some(config.clone());
res.system = Some(sys.clone().into());
if config.store_ffs_config {
res.ffs_config = Some(config.clone());
}
if config.store_system {
res.system = Some(sys.clone().into());
}

Ok(res)
}
Expand Down Expand Up @@ -1153,6 +1171,10 @@ impl FFSRunResult {
.map_err(|e| PyPolarsErr::from(e).into())
}

fn into_resdf(this: Bound<FFSRunResult>) -> FFSRunResultDF {
this.borrow_mut().clone().into()
}

// #[staticmethod]
// fn read_json(filename: &str) -> PyResult<Self> {
// let f = std::fs::File::open(filename)?;
Expand Down

0 comments on commit e50b513

Please sign in to comment.