Skip to content

Commit 3a48ab3

Browse files
authored
Merge pull request #25 from snu-hanaro/feat/sep-config-integration
feat(cli,post-process): support sep/header configuration
2 parents 46a58be + 1b1ce20 commit 3a48ab3

File tree

5 files changed

+52
-25
lines changed

5 files changed

+52
-25
lines changed

examples/global_config.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
# ---------- Do not change ----------
1+
thrust_sep = "[,\t]" # separator for thrust data, character or Regex
2+
thrust_header = None # header for thrust data (row number or None)
3+
pressure_sep = ";" # separator for pressure data, character or Regex
4+
pressure_header = 0 # header for pressure data (row number or None)
25
g = 9.80665 # gravitational acceleration, m/s^2
36
rated_load = 500 # rated load of load cell, kgf
47
rated_output = 3 # rated output of load cell, V
5-
frequency = 100 # Sampling rate
8+
frequency = 100 # Sampling rate, Hz
69
cutoff_frequency = 30 # LPF, Hz
7-
gaussian_strong_sigma = 10
8-
start_criteria = 0.2
9-
end_criteria = 0.1
10-
lowpass_order = 5
11-
gaussian_weak_sigma = 1.5
10+
gaussian_strong_sigma = 10 # sigma for strong gaussian filter
11+
start_criteria = 0.2 # Criteria for the starting point of a meaningful interval in thrust data processing
12+
end_criteria = 0.1 # Criteria for the ending point of a meaningful interval in thrust data processing
13+
lowpass_order = 5 # order for lowpass filter
14+
gaussian_weak_sigma = 1.5 # sigma for weak gaussian filter

src/static_fire_toolkit/cli.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import platform
1515

1616
from static_fire_toolkit import __version__
17+
from static_fire_toolkit.config_loader import load_global_config
1718

1819
if TYPE_CHECKING: # Only for type checkers; avoids importing pandas at runtime here
1920
from pandas import DataFrame
@@ -90,7 +91,10 @@ def _read_thrust_raw(execution_root: Path, expt_file_name: str) -> DataFrame:
9091
)
9192
import pandas as pd
9293

93-
return pd.read_csv(data_file, sep="[,\t]", header=None, engine="python")
94+
cfg = load_global_config(execution_root)
95+
sep = str(getattr(cfg, "thrust_sep", ","))
96+
header = getattr(cfg, "thrust_header", 0)
97+
return pd.read_csv(data_file, sep=sep, header=header, engine="python")
9498

9599

96100
def _read_pressure_raw(execution_root: Path, expt_file_name: str) -> DataFrame:
@@ -106,11 +110,12 @@ def _read_pressure_raw(execution_root: Path, expt_file_name: str) -> DataFrame:
106110
raise FileNotFoundError(
107111
f"No pressure data file found for {expt_file_name}: {csv_path} or {txt_path}"
108112
)
109-
# Pressure raw csv typically uses ';'
110-
sep = ";" if str(data_file).endswith(".csv") else ","
111113
import pandas as pd
112114

113-
return pd.read_csv(data_file, sep=sep, header=0)
115+
cfg = load_global_config(execution_root)
116+
sep = str(getattr(cfg, "pressure_sep", ","))
117+
header = getattr(cfg, "pressure_header", 0)
118+
return pd.read_csv(data_file, sep=sep, header=header, engine="python")
114119

115120

116121
def cmd_thrust(args: argparse.Namespace) -> None:

src/static_fire_toolkit/config_loader.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,20 @@
2424
class Config:
2525
"""Runtime configuration values used by processing modules."""
2626

27-
rated_output: float = 2.0 # mV/V or sensor unit (example default)
28-
rated_load: float = 100.0 # kg or sensor unit (example default)
29-
g: float = 9.80665
30-
frequency: float = 100.0 # Hz (Δt = 0.01 s)
27+
rated_output: float = 3.0 # rated output of load cell, V
28+
rated_load: float = 500.0 # rated load of load cell, kgf
29+
g: float = 9.80665 # gravitational acceleration, m/s^2
30+
frequency: float = 100.0 # Sampling rate, Hz (Δt = 0.01 s)
3131
cutoff_frequency: float = 10.0 # Hz for LPF
32-
lowpass_order: int = 2
33-
gaussian_weak_sigma: float = 2.0
34-
gaussian_strong_sigma: float = 8.0
35-
start_criteria: float = 0.15
36-
end_criteria: float = 0.15
32+
lowpass_order: int = 5 # order for lowpass filter
33+
gaussian_weak_sigma: float = 2.0 # sigma for weak gaussian filter
34+
gaussian_strong_sigma: float = 8.0 # sigma for strong gaussian filter
35+
start_criteria: float = 0.15 # Criteria for the starting point of a meaningful interval in thrust data processing
36+
end_criteria: float = 0.15 # Criteria for the ending point of a meaningful interval in thrust data processing
37+
thrust_sep: str = "," # separator for thrust data, character or Regex
38+
thrust_header: int | None = 0 # header for thrust data (row number or None)
39+
pressure_sep: str = "," # separator for pressure data, character or Regex
40+
pressure_header: int | None = 0 # header for pressure data (row number or None)
3741

3842

3943
def _read_attr(cfg: Any, name: str, default: Any) -> Any:
@@ -70,6 +74,10 @@ def _load_from_python(path: Path, base: Config) -> Config:
7074
_read_attr(mod, "start_criteria", base.start_criteria)
7175
),
7276
end_criteria=float(_read_attr(mod, "end_criteria", base.end_criteria)),
77+
thrust_sep=str(_read_attr(mod, "thrust_sep", base.thrust_sep)),
78+
thrust_header=_read_attr(mod, "thrust_header", base.thrust_header),
79+
pressure_sep=str(_read_attr(mod, "pressure_sep", base.pressure_sep)),
80+
pressure_header=_read_attr(mod, "pressure_header", base.pressure_header),
7381
)
7482
return base
7583

src/static_fire_toolkit/post_process/pressure_post_processing.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,16 @@ def run(self) -> pd.DataFrame:
605605
raise FileNotFoundError(error_msg)
606606

607607
# Read and process data
608-
pressure_data = pd.read_csv(pressure_data_file, sep=";", header=0)
609-
thrust_data = pd.read_csv(thrust_data_file, sep="[, ]", header=0, engine="python")
608+
from static_fire_toolkit.config_loader import load_global_config
609+
610+
cfg = load_global_config()
611+
pressure_sep = str(getattr(cfg, "pressure_sep", ","))
612+
pressure_header = getattr(cfg, "pressure_header", 0)
613+
pressure_data = pd.read_csv(
614+
pressure_data_file, sep=pressure_sep, header=pressure_header, engine="python"
615+
)
616+
# Processed thrust CSV is always saved with comma separator by toolkit
617+
thrust_data = pd.read_csv(thrust_data_file)
610618
print("Successfully loaded input data files.")
611619

612620
# Initialize processor and run processing steps

src/static_fire_toolkit/post_process/thrust_post_processing.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,12 @@ def run(self) -> pd.DataFrame:
707707
print(error_msg)
708708
raise FileNotFoundError(error_msg)
709709

710-
thrust_data = pd.read_csv(
711-
data_file, sep="[,\t]", header=None, engine="python"
712-
) # 기존 데이터 형식과도 호환되도록 구분자로 쉼표(,) 및 탭(\t) 사용
710+
from static_fire_toolkit.config_loader import load_global_config
711+
712+
cfg = load_global_config()
713+
thrust_sep = str(getattr(cfg, "thrust_sep", ","))
714+
thrust_header = getattr(cfg, "thrust_header", 0)
715+
thrust_data = pd.read_csv(data_file, sep=thrust_sep, header=thrust_header)
713716
print("Successfully loaded input data file.")
714717

715718
process = ThrustPostProcess(

0 commit comments

Comments
 (0)