Christoph Lange commited on
Commit
137ce1b
·
1 Parent(s): bca6356

update loading script

Browse files
Files changed (1) hide show
  1. substrate_mix_raman.py +18 -8
substrate_mix_raman.py CHANGED
@@ -74,24 +74,34 @@ class SubstrateMixRaman(datasets.GeneratorBasedBuilder):
74
  """Yields examples as (key, example) tuples for a given split file."""
75
  df = pd.read_csv(filepath)
76
 
77
- # Assuming the actual column names in your CSV are the Raman shifts as strings
78
- # and then the specified label names.
79
- # Let's verify the number of spectrum columns based on your description.
80
- # 1561 columns for spectrum and 8 for labels = 1569 columns total.
81
- num_spectrum_cols = 1561
82
- raman_shift_columns = [str(col) for col in df.columns[:num_spectrum_cols]]
83
-
84
  label_columns = [
85
  "Glucose", "Glycerol", "Acetate", "EnPump", "Nitrate",
86
  "Yeast_Extract", "total_phosphate", "total_sulfate"
87
  ]
88
 
 
 
 
 
 
 
 
 
 
 
89
  # Ensure all expected label columns are actually present in the DataFrame
90
- # This can help debug if there's a mismatch between the script and the CSV.
91
  for col in label_columns:
92
  if col not in df.columns:
93
  raise ValueError(f"Label column '{col}' not found in CSV file: {filepath}")
94
 
 
 
 
 
 
95
  for id_, row in enumerate(df.iterrows()):
96
  data = row[1] # row[0] is the index, row[1] is the Series/array of data
97
 
 
74
  """Yields examples as (key, example) tuples for a given split file."""
75
  df = pd.read_csv(filepath)
76
 
77
+ # Dynamically determine Raman shift columns and label columns
78
+ # Raman shift columns are those that can be converted to float (numbers)
79
+ # Label columns are the known metabolite names
 
 
 
 
80
  label_columns = [
81
  "Glucose", "Glycerol", "Acetate", "EnPump", "Nitrate",
82
  "Yeast_Extract", "total_phosphate", "total_sulfate"
83
  ]
84
 
85
+ raman_shift_columns = []
86
+ for col in df.columns:
87
+ try:
88
+ float(col) # Check if column name can be converted to a float
89
+ raman_shift_columns.append(col)
90
+ except ValueError:
91
+ # If it's not a float, check if it's one of our expected label columns
92
+ if col not in label_columns:
93
+ print(f"Warning: Unexpected column '{col}' found in CSV. It's neither a Raman shift nor a defined label.")
94
+
95
  # Ensure all expected label columns are actually present in the DataFrame
 
96
  for col in label_columns:
97
  if col not in df.columns:
98
  raise ValueError(f"Label column '{col}' not found in CSV file: {filepath}")
99
 
100
+ # Ensure we have at least some Raman shift columns
101
+ if not raman_shift_columns:
102
+ raise ValueError(f"No Raman shift columns found in CSV file: {filepath}. Expected column names to be numerical strings.")
103
+
104
+
105
  for id_, row in enumerate(df.iterrows()):
106
  data = row[1] # row[0] is the index, row[1] is the Series/array of data
107