From 0cbb4f345a157a2df37d1cb7600bca0dbc103ef7 Mon Sep 17 00:00:00 2001 From: "Marco A. Lopez-Sanchez" Date: Tue, 21 May 2024 11:59:06 +0200 Subject: [PATCH] new implementation --- grain_size_tools/new_piezometers.py | 84 +++++++++++++++++++++++++++++ grain_size_tools/piezometers.yaml | 41 ++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 grain_size_tools/new_piezometers.py create mode 100644 grain_size_tools/piezometers.yaml diff --git a/grain_size_tools/new_piezometers.py b/grain_size_tools/new_piezometers.py new file mode 100644 index 0000000..7bb9c96 --- /dev/null +++ b/grain_size_tools/new_piezometers.py @@ -0,0 +1,84 @@ +from dataclasses import dataclass +from typing import Dict, ClassVar, Any +import yaml + +@dataclass +class Piezometer: + name: str + year: int + reference: str + B: float + m: float + warn: str + linear_intercepts: bool + correction_factor: Any + notes: str + + def summary(self): + print( + f"Piezometer: {self.name}\n" + f"Year: {self.year}\n" + f"Reference: {self.reference}\n" + f"B: {self.B}\n" + f"m: {self.m}\n" + f"Warning: {self.warn}\n" + f"Linear Intercepts: {self.linear_intercepts}\n" + f"Correction Factor: {self.correction_factor}\n" + f"Notes: {self.notes}\n" + ) + + return None + + +@dataclass +class quartz(Piezometer): + piezometers: ClassVar[Dict[str, "Quartz"]] = {} + + +@dataclass +class olivine(Piezometer): + piezometers: ClassVar[Dict[str, "Olivine"]] = {} + + +@dataclass +class calcite(Piezometer): + piezometers: ClassVar[Dict[str, "Calcite"]] = {} + + +@dataclass +class feldspar(Piezometer): + piezometers: ClassVar[Dict[str, "Feldspar"]] = {} + + +def load_piezometers_from_yaml(filepath): + with open(filepath, "r") as file: + data = yaml.safe_load(file) + + for mineral, piezos in data.items(): + for piezo_data in piezos: + name = piezo_data.pop("piezometer") + + if mineral == "quartz": + piezo = quartz(name=name, **piezo_data) + quartz.piezometers[name] = piezo + setattr(quartz, name, piezo) + + elif mineral == "olivine": + piezo = olivine(name=name, **piezo_data) + olivine.piezometers[name] = piezo + setattr(olivine, name, piezo) + + elif mineral == "calcite": + piezo = calcite(name=name, **piezo_data) + calcite.piezometers[name] = piezo + setattr(calcite, name, piezo) + + elif mineral == "feldspar": + piezo = feldspar(name=name, **piezo_data) + feldspar.piezometers[name] = piezo + setattr(feldspar, name, piezo) + + +if __name__ == "__main__": + load_piezometers_from_yaml("piezometers.yaml") + print("database loaded") diff --git a/grain_size_tools/piezometers.yaml b/grain_size_tools/piezometers.yaml new file mode 100644 index 0000000..1798173 --- /dev/null +++ b/grain_size_tools/piezometers.yaml @@ -0,0 +1,41 @@ +quartz: + - piezometer: Stipp_Tullis + year: 2003 + reference: https://doi.org/10.1029/2003GL018444 + B: 669.0 + m: 0.79 + warn: Ensure that you entered the apparent grain size as the root mean square (RMS) + linear_intercepts: false + correction_factor: false + notes: Only applies to recrystallization regimes 2 and 3 (SGR, GBM) + + - piezometer: Holyoke + year: 2010 + reference: https://doi.org/10.1016/j.tecto.2010.08.001 + B: 490.3 + m: 0.79 + warn: Ensure that you entered the apparent grain size as the root mean square (RMS) + linear_intercepts: true + correction_factor: true + notes: None + +olivine: + - piezometer: VanderWal_wet + year: 1993 + reference: https://doi.org/10.1029/93GL01382 + B: 1355.4 + m: 0.75 + warn: Ensure that you entered the apparent grain size as the root mean square (RMS) + linear_intercepts: true + correction_factor: 1.5 + notes: The Van de Wal (1993) piezometer was calibrated using the linear intercept (LI) grain size multiplied by 1.5 (correction factor). ECDs without stereological correction are converted to LIs using the empirical equation of De Hoff and Rhines (1968) LI = (1.5 / sqrt(4/pi)) * ECD + + - piezometer: Jung_Karato + year: 2001 + reference: https://doi.org/10.1016/S0191-8141(01)00005-0 + B: 5461.03 + m: 0.85 + warn: Ensure that you entered the apparent grain size as the root mean square (RMS) + linear_intercepts: true + correction_factor: 1.5 + notes: The Jung & Karato (2001) piezometer was calibrated using the linear intercept (LI) grain size multiplied by 1.5 (correction factor). If equivalent circular diameters (ECD) without stereological correction are used, they must be converted to LIs using the empirical equation of De Hoff and Rhines (1968) as follows LI = (1.5 / sqrt(4/pi)) * ECD \ No newline at end of file