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

automatic download

Browse files
Files changed (1) hide show
  1. substrate_mix_raman.py +107 -0
substrate_mix_raman.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ import pandas as pd
3
+ import os
4
+
5
+ _DESCRIPTION = """
6
+ This dataset contains Raman spectra of various mixtures of 8 biotechnologically relevant substances, along with concentrations of mineral salt medium and antifoam.
7
+ The dataset is designed for calibration resources in high-throughput bioprocess development, featuring statistically independent substance concentrations.
8
+ """
9
+
10
+ _HOMEPAGE = "https://huggingface.co/datasets/chlange/SubstrateMixRaman" # Replace if you have an official project page
11
+ _LICENSE = "https://creativecommons.org/licenses/by/4.0/" # Make sure this matches your README.md license
12
+
13
+ # _URL is no longer needed because data_files in README.md handles split paths
14
+
15
+ class SubstrateMixRaman(datasets.GeneratorBasedBuilder):
16
+ VERSION = datasets.Version("1.0.0")
17
+
18
+ def _info(self):
19
+ # Define the features of your dataset
20
+ # The first 1561 columns are Raman intensities (spectra)
21
+ # We don't need to name them individually here for the 'spectrum' feature,
22
+ # as it's a sequence.
23
+ # If you wanted the actual Raman shift values as a feature, you'd add:
24
+ # "raman_shifts": datasets.Sequence(datasets.Value("float32")),
25
+
26
+ # The next 8 columns are concentrations (labels)
27
+ label_features = {
28
+ "Glucose": datasets.Value("float32"),
29
+ "Glycerol": datasets.Value("float32"),
30
+ "Acetate": datasets.Value("float32"),
31
+ "EnPump": datasets.Value("float32"),
32
+ "Nitrate": datasets.Value("float32"),
33
+ "Yeast_Extract": datasets.Value("float32"),
34
+ "total_phosphate": datasets.Value("float32"), # Renamed as per CSV header for clarity
35
+ "total_sulfate": datasets.Value("float32"), # Renamed as per CSV header for clarity
36
+ }
37
+
38
+ features = datasets.Features({
39
+ "spectrum": datasets.Sequence(datasets.Value("float32")), # A list of floats for the spectrum
40
+ "labels": datasets.Features(label_features) # Nested features for concentrations
41
+ })
42
+
43
+ return datasets.DatasetInfo(
44
+ description=_DESCRIPTION,
45
+ features=features,
46
+ homepage=_HOMEPAGE,
47
+ license=_LICENSE,
48
+ citation="""
49
+ @article{lange5239248deep,
50
+ title={Deep Learning for Raman Spectroscopy: Benchmarking Models for Upstream Bioprocess Monitoring},
51
+ author={Lange, Christoph and Altmann, Madeline and Stors, Daniel and Seidel, Simon and Moynahan, Kyle and Cai, Linda and Born, Stefan and Neubauer, Peter and Cruz Bournazou, Nicolas},
52
+ journal={Available at SSRN 5239248}
53
+ }
54
+ """
55
+ )
56
+
57
+ def _split_generators(self, dl_manager):
58
+ """Returns SplitGenerators."""
59
+ # dl_manager.download handles the data_files specification from README.md
60
+ # self.config.data_files will automatically be populated based on the YAML
61
+ downloaded_files = dl_manager.download_and_extract(self.config.data_files)
62
+
63
+ splits = []
64
+ for split_name, filepath in downloaded_files.items():
65
+ splits.append(
66
+ datasets.SplitGenerator(
67
+ name=split_name, # This will be 'train', 'validation', 'test'
68
+ gen_kwargs={"filepath": filepath},
69
+ )
70
+ )
71
+ return splits
72
+
73
+ def _generate_examples(self, filepath):
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
+
98
+ # Extract spectrum (Raman intensities)
99
+ spectrum = [float(data[col]) for col in raman_shift_columns]
100
+
101
+ # Extract labels (concentrations)
102
+ labels = {label_col: float(data[label_col]) for label_col in label_columns}
103
+
104
+ yield id_, {
105
+ "spectrum": spectrum,
106
+ "labels": labels,
107
+ }