YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

import os import re import csv

def extract_t1_t2_values(file_path): with open(file_path, 'r') as file: data = file.read()

# Define regular expressions to find the required values for Native T1
native_t1_global_pattern = r"Native T1[\s\S]*?Global Myo T1 Across Slices\s+(\d+\.?\d*)"
native_t1_slice1_pattern = r"Regional Native T1 Slice 1[\s\S]*?Myo\s+(\d+\.?\d*)"
native_t1_slice2_pattern = r"Regional Native T1 Slice 2[\s\S]*?Myo\s+(\d+\.?\d*)"

# Define regular expressions to find the required values for CA T1 (T2)
ca_t1_global_pattern = r"CA T1[\s\S]*?Global Myo T1 Across Slices\s+(\d+\.?\d*)"
ca_t1_slice1_pattern = r"Regional CA T1 Slice 1[\s\S]*?Myo\s+(\d+\.?\d*)"
ca_t1_slice2_pattern = r"Regional CA T1 Slice 2[\s\S]*?Myo\s+(\d+\.?\d*)"

# Search for the patterns in the data for Native T1
native_t1_global = re.search(native_t1_global_pattern, data)
native_t1_slice1 = re.search(native_t1_slice1_pattern, data)
native_t1_slice2 = re.search(native_t1_slice2_pattern, data)

# Search for the patterns in the data for CA T1 (T2)
ca_t1_global = re.search(ca_t1_global_pattern, data)
ca_t1_slice1 = re.search(ca_t1_slice1_pattern, data)
ca_t1_slice2 = re.search(ca_t1_slice2_pattern, data)

# Extract the values if the patterns were found for Native T1
native_t1_global_value = native_t1_global.group(1) if native_t1_global else None
native_t1_slice1_value = native_t1_slice1.group(1) if native_t1_slice1 else None
native_t1_slice2_value = native_t1_slice2.group(1) if native_t1_slice2 else None

# Extract the values if the patterns were found for CA T1 (T2)
ca_t1_global_value = ca_t1_global.group(1) if ca_t1_global else None
ca_t1_slice1_value = ca_t1_slice1.group(1) if ca_t1_slice1 else None
ca_t1_slice2_value = ca_t1_slice2.group(1) if ca_t1_slice2 else None

return {
    "Native Mean Global T1": native_t1_global_value,
    "Native Mean Basal T1": native_t1_slice1_value,
    "Native Mean Mid T1": native_t1_slice2_value,
    "CA Mean Global T2": ca_t1_global_value,
    "CA Mean Basal T2": ca_t1_slice1_value,
    "CA Mean Mid T2": ca_t1_slice2_value
}

def process_reports(folder_path): report_files = [f for f in os.listdir(folder_path) if f.endswith('.txt')] results = []

for report_file in report_files:
    file_path = os.path.join(folder_path, report_file)
    t1_t2_values = extract_t1_t2_values(file_path)
    results.append({
        "File": report_file,
        "Native Mean Global T1": t1_t2_values["Native Mean Global T1"],
        "Native Mean Basal T1": t1_t2_values["Native Mean Basal T1"],
        "Native Mean Mid T1": t1_t2_values["Native Mean Mid T1"],
        "CA Mean Global T2": t1_t2_values["CA Mean Global T2"],
        "CA Mean Basal T2": t1_t2_values["CA Mean Basal T2"],
        "CA Mean Mid T2": t1_t2_values["CA Mean Mid T2"]
    })

return results

Example usage

folder_path = 'report_files' # Replace with your actual folder path results = process_reports(folder_path)

for result in results: print(result)

Optionally, save the results to a CSV file

csv_file_path = 'extracted_t1_t2_values.csv' # Replace with desired CSV file path with open(csv_file_path, 'w', newline='') as csvfile: fieldnames = [ 'File', 'Native Mean Global T1', 'Native Mean Basal T1', 'Native Mean Mid T1', 'CA Mean Global T2', 'CA Mean Basal T2', 'CA Mean Mid T2' ] writer = csv.DictWriter(csvfile, fieldnames=fieldnames)

writer.writeheader()
for result in results:
    writer.writerow(result)
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support