1use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
12#[serde(rename_all = "PascalCase")]
13pub struct CoordinateSystem {
14 #[serde(rename = "EEGCoordinateSystem")]
16 pub eeg_coordinate_system: String,
17
18 #[serde(rename = "EEGCoordinateUnits")]
20 pub eeg_coordinate_units: String,
21
22 #[serde(rename = "EEGCoordinateSystemDescription", default)]
24 pub eeg_coordinate_system_description: Option<String>,
25
26 #[serde(rename = "EEGCoordinateProcessingDescription", default)]
28 pub eeg_coordinate_processing_description: Option<String>,
29
30 #[serde(rename = "iEEGCoordinateSystem", default)]
32 pub ieeg_coordinate_system: Option<String>,
33
34 #[serde(rename = "iEEGCoordinateUnits", default)]
36 pub ieeg_coordinate_units: Option<String>,
37
38 #[serde(rename = "iEEGCoordinateSystemDescription", default)]
40 pub ieeg_coordinate_system_description: Option<String>,
41
42 #[serde(rename = "iEEGCoordinateProcessingDescription", default)]
44 pub ieeg_coordinate_processing_description: Option<String>,
45
46 #[serde(default)]
48 pub fiducials: Option<serde_json::Value>,
49
50 #[serde(rename = "AnatomicalLandmarkCoordinates", default)]
52 pub anatomical_landmark_coordinates: Option<serde_json::Value>,
53
54 #[serde(rename = "AnatomicalLandmarkCoordinateSystem", default)]
56 pub anatomical_landmark_coordinate_system: Option<String>,
57
58 #[serde(rename = "AnatomicalLandmarkCoordinateUnits", default)]
60 pub anatomical_landmark_coordinate_units: Option<String>,
61
62 #[serde(rename = "IntendedFor", default)]
64 pub intended_for: Option<serde_json::Value>,
65}
66
67impl CoordinateSystem {
68 pub fn from_file(path: &std::path::Path) -> bids_core::error::Result<Self> {
70 let contents = std::fs::read_to_string(path)?;
71 let cs: Self = serde_json::from_str(&contents)?;
72 Ok(cs)
73 }
74}
75
76#[cfg(test)]
77mod tests {
78 use super::*;
79
80 #[test]
81 fn test_coordsystem_parse() {
82 let json = r#"{
83 "EEGCoordinateSystem": "CapTrak",
84 "EEGCoordinateUnits": "mm",
85 "EEGCoordinateSystemDescription": "RAS orientation"
86 }"#;
87
88 let cs: CoordinateSystem = serde_json::from_str(json).unwrap();
89 assert_eq!(cs.eeg_coordinate_system, "CapTrak");
90 assert_eq!(cs.eeg_coordinate_units, "mm");
91 }
92}