diff options
| author | Sam Scholten | 2025-10-24 11:16:31 +1000 |
|---|---|---|
| committer | Sam Scholten | 2025-10-24 11:16:31 +1000 |
| commit | 89aab509ccb0a30aa7f02c154a2a91506db7ba6d (patch) | |
| tree | 1dff9cfc5c6b58a1adedb1c3a80e1edbad19a2ce | |
| parent | a74c1249a18dbb4d6a69f52ac88a7bb8f6ac0eb7 (diff) | |
| download | transivent-89aab509ccb0a30aa7f02c154a2a91506db7ba6d.tar.gz transivent-89aab509ccb0a30aa7f02c154a2a91506db7ba6d.zip | |
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
| -rw-r--r-- | src/transivent/io.py | 16 |
1 files changed, 13 insertions, 3 deletions
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: |
