From 89aab509ccb0a30aa7f02c154a2a91506db7ba6d Mon Sep 17 00:00:00 2001 From: Sam Scholten Date: Fri, 24 Oct 2025 11:16:31 +1000 Subject: Fix: Ensure data_path is correctly passed to get_waveform_params() in rd() When rd() is called with a data_path, it needs to pass this through to get_waveform_params() so the XML sidecar file can be found. Previously, if the filename was already an absolute path, data_path would be ignored, causing FileNotFoundError when XML sidecar was in a different directory. This fix ensures that: - If data_path is provided, it's always used with the basename - If data_path is None, the file's directory is used as data_path - This maintains backward compatibility while fixing the path resolution --- src/transivent/io.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/transivent/io.py b/src/transivent/io.py index b7ad1c5..07484e6 100644 --- a/src/transivent/io.py +++ b/src/transivent/io.py @@ -255,9 +255,19 @@ def rd( fp = os.path.join(data_path, filename) else: fp = filename - params = get_waveform_params( - os.path.basename(fp), data_path, sidecar=sidecar - ) + + # If we have a data_path, use it with just the basename + # Otherwise use the directory of the file + if data_path is not None: + params = get_waveform_params( + os.path.basename(fp), data_path, sidecar=sidecar + ) + else: + # Use the directory containing the file as data_path + file_dir = os.path.dirname(fp) or "." + params = get_waveform_params( + os.path.basename(fp), file_dir, sidecar=sidecar + ) # Use sampling_interval from XML if available, else argument, else raise error si = params["sampling_interval"] if si is None: -- cgit v1.2.3