DataPrepare/dataset_tools/resp_pair_copy.py
marques 8ee5980906 feat: Add utility functions for signal processing and event mapping
- Created a new module `utils/__init__.py` to consolidate utility imports.
- Added `event_map.py` for mapping apnea event types to numerical values and colors.
- Implemented various filtering functions in `filter_func.py`, including Butterworth, Bessel, downsampling, and notch filters.
- Developed `operation_tools.py` for dataset configuration loading, event mask generation, and signal processing utilities.
- Introduced `split_method.py` for segmenting data based on movement and amplitude criteria.
- Added `statistics_metrics.py` for calculating amplitude metrics and generating confusion matrices.
- Included a new Excel file for additional data storage.
2026-03-24 21:15:05 +08:00

67 lines
2.3 KiB
Python

from pathlib import Path
import sys
sys.path.append(str(Path(__file__).resolve().parent.parent))
project_root_path = Path(__file__).resolve().parent.parent
import utils
import shutil
def copy_one_resp_pair(one_id):
sync_type = "Sync"
org_bcg_file_path = sync_bcg_path / f"{one_id}"
dest_bcg_file_path = pair_file_path / f"{one_id}"
dest_bcg_file_path.mkdir(parents=True, exist_ok=True)
if not list(org_bcg_file_path.glob("OrgBCG_Sync_*.txt")):
if not list(org_bcg_file_path.glob("OrgBCG_RoughCut_*.txt")):
print(f"No OrgBCG files found for ID {one_id}.")
return
else:
sync_type = "RoughCut"
print(f"Using RoughCut files for ID {one_id}.")
for file in org_bcg_file_path.glob(f"OrgBCG_{sync_type}_*.txt"):
shutil.copyfile(file, dest_bcg_file_path / f"{one_id}_{file.name}".replace("_RoughCut", "").replace("_Sync", ""))
psg_file_path = sync_psg_path / f"{one_id}"
dest_psg_file_path = pair_file_path / f"{one_id}"
dest_psg_file_path.mkdir(parents=True, exist_ok=True)
# 检查上面的文件是否存在
psg_file_patterns = [
f"5_class_{sync_type}_*.txt",
f"Effort Abd_{sync_type}_*.txt",
f"Effort Tho_{sync_type}_*.txt",
f"Flow P_{sync_type}_*.txt",
f"Flow T_{sync_type}_*.txt",
f"SA Label_Sync.csv",
f"SpO2_{sync_type}_*.txt"
]
for pattern in psg_file_patterns:
if not list(psg_file_path.glob(pattern)):
print(f"No PSG files found for ID {one_id} with pattern {pattern}.")
return
for pattern in psg_file_patterns:
for file in psg_file_path.glob(pattern):
shutil.copyfile(file, dest_psg_file_path / f"{one_id}_{file.name.replace('_RoughCut', '').replace('_Sync', '')}")
if __name__ == '__main__':
yaml_path = project_root_path / "dataset_config/RESP_PAIR_ZD5Y_config.yaml"
conf = utils.load_dataset_conf(yaml_path)
select_ids = conf["select_ids"]
root_path = Path(conf["root_path"])
sync_bcg_path = root_path / "OrgBCG_Aligned"
sync_psg_path = root_path / "PSG_Aligned"
pair_file_path = Path(conf["pair_file_path"])
# copy_one_resp_pair(961)
for samp_id in select_ids:
print(f"Processing {samp_id}...")
copy_one_resp_pair(samp_id)