Cut *.sdatb files at a certain frequency

32 views
Skip to first unread message

wickli...@gmail.com

unread,
Oct 7, 2025, 11:11:58 AM (13 days ago) Oct 7
to VNA Tools
Hey guys

We sometimes face the situation, where we have to measure two more or less identical elements where the only notable difference is the frequency range.

It is way more efficient to just make one Cal and measure both elements in one go with an extended frequency range covering both elements.

However, this leaves us with two *.sdat files, both of which do have frequency points we don't actually need in our output file.

Is there a way to shorten these files so only the relevant frequency range is in the final output file?

Thanks
Patric

wickli...@gmail.com

unread,
Oct 8, 2025, 4:23:34 AM (12 days ago) Oct 8
to VNA Tools
Just fyi, I made a script doing what I need.
It may need some polishing and I may add a "min_frequency" as well, but that's the basic script:

import clr
clr.AddReference('Metas.UncLib.Core')
clr.AddReference('Metas.UncLib.linProp')
clr.AddReference('Metas.Vna.Tools')
from Metas.Vna.Tools import Script

input_file  = r"example_9GHz.sdatb"
output_file = r"example_3GHz.sdatb"
max_freq_Hz = 3e9

s = Script(RootPath)
m = s.LoadSParamData(input_file)

# Determine cutoff index
limit_index = -1
for i in range(m.NFreq):
    if m.Frequency[i] <= max_freq_Hz:
        limit_index = i
    else:
        break

if limit_index < 0:
    raise Exception("No frequencies below 3 GHz found.")

print("Cutoff index =", limit_index, "frequency =", m.Frequency[limit_index], "Hz")

# Clone the original dataset by loading a second reference
trunc = s.LoadSParamData(input_file)

# Overwrite S-parameter data for frequencies up to the cutoff
for i in range(limit_index + 1):
    for r in range(m.NPorts):
        for c in range(m.NPorts):
            trunc[i, r, c] = m[i, r, c]

# Truncate the frequency vector
trunc.Frequency = m.Frequency[0:limit_index + 1]

# Save truncated dataset
s.SaveSParamData(output_file, trunc)
print("Saved truncated dataset up to 3 GHz:", output_file)

wickli...@gmail.com

unread,
Oct 8, 2025, 11:08:06 AM (12 days ago) Oct 8
to VNA Tools
I did some polishing and made it so one can truncate a whole folder instead of just one file. I'll leave it at that.


import clr
clr.AddReference('Metas.UncLib.Core')
clr.AddReference('Metas.UncLib.linProp')
clr.AddReference('Metas.Vna.Tools')
from System.IO import DirectoryInfo, Directory, Path, FileInfo, SearchOption
from Metas.Vna.Tools import Script

# ================= CONFIGURATION =================
input_folder  = r"C:\path\to\input_folder"     # folder containing .sdatb files
output_folder = r"C:\path\to\output_folder"  # folder to save truncated files
min_freq_Hz   = 1e9                 # Min Frequency
max_freq_Hz   = 3e9                 # Max Frequency

# ================= INITIALIZATION =================
s = Script(RootPath)
di = DirectoryInfo(input_folder)
fis = di.GetFiles('*.sdatb', SearchOption.AllDirectories)

for fi in fis:
    print("Processing:", fi.FullName)

    # --- Load original dataset ---
    d = s.LoadSParamData(fi.FullName)

    # --- Determine frequency range indices ---
    start_index = None
    end_index = None
    for i in range(d.NFreq):
        f = d.Frequency[i]
        if start_index is None and f >= min_freq_Hz:
            start_index = i
        if f <= max_freq_Hz:
            end_index = i

    if start_index is None or end_index is None or start_index > end_index:
        print("  Skipped (no data in selected range)")
        continue

    print("  Truncating from %.3f GHz to %.3f GHz" %
          (d.Frequency[start_index]/1e9, d.Frequency[end_index]/1e9))

    # --- Clone dataset and overwrite truncated values ---
    trunc = s.LoadSParamData(fi.FullName)
    for i_new, i_orig in enumerate(range(start_index, end_index + 1)):
        for r in range(d.NPorts):
            for c in range(d.NPorts):
                trunc[i_new, r, c] = d[i_orig, r, c]

    # --- Truncate frequency vector ---
    trunc.Frequency = d.Frequency[start_index:end_index + 1]

    # --- Compute relative path for output ---
    rel_path = fi.FullName[len(input_folder):].lstrip('\\')
    output_path = Path.Combine(output_folder, rel_path)
    output_dir  = Path.GetDirectoryName(output_path)
    if not Directory.Exists(output_dir):
        Directory.CreateDirectory(output_dir)

    # --- Save truncated dataset ---
    output_file = Path.Combine(output_dir, Path.GetFileNameWithoutExtension(fi.Name) + '_trunc.sdatb')
    s.SaveSParamData(output_file, trunc)
    print("  Saved truncated file:", output_file)

print("Batch truncation completed for folder:", input_folder)

Juerg Ruefenacht

unread,
Oct 14, 2025, 4:36:18 AM (6 days ago) Oct 14
to VNA Tools
Hello Patric,
you can select in the File Explorer a frequency list file for this purpose (see User Manual, section 3.2).

Best Regards
Juerg

wickli...@gmail.com schrieb am Dienstag, 7. Oktober 2025 um 17:11:58 UTC+2:

wickli...@gmail.com

unread,
Oct 16, 2025, 3:46:31 AM (4 days ago) Oct 16
to VNA Tools
Hello Juerg

Oh, that would have made things quite a lot easier. Thank's for your feedback!

Greetings
Patric

Reply all
Reply to author
Forward
0 new messages