Updated loading logic
Browse files- AstroM3Dataset.py +6 -12
AstroM3Dataset.py
CHANGED
|
@@ -124,7 +124,7 @@ class AstroM3Dataset(datasets.GeneratorBasedBuilder):
|
|
| 124 |
spectra_urls = {}
|
| 125 |
for _, row in df_combined.iterrows():
|
| 126 |
spectra_urls[row["spec_filename"]] = f"{_URL}/spectra/{row['target']}/{row['spec_filename']}"
|
| 127 |
-
|
| 128 |
|
| 129 |
# Load photometry and init reader
|
| 130 |
photometry_path = dl_manager.download(f"{_URL}/photometry.zip")
|
|
@@ -134,32 +134,26 @@ class AstroM3Dataset(datasets.GeneratorBasedBuilder):
|
|
| 134 |
datasets.SplitGenerator(
|
| 135 |
name=datasets.Split.TRAIN, gen_kwargs={"csv_path": extracted_path["train"],
|
| 136 |
"info_path": extracted_path["info"],
|
| 137 |
-
"
|
| 138 |
"split": "train"}
|
| 139 |
),
|
| 140 |
datasets.SplitGenerator(
|
| 141 |
name=datasets.Split.VALIDATION, gen_kwargs={"csv_path": extracted_path["val"],
|
| 142 |
"info_path": extracted_path["info"],
|
| 143 |
-
"
|
| 144 |
"split": "val"}
|
| 145 |
),
|
| 146 |
datasets.SplitGenerator(
|
| 147 |
name=datasets.Split.TEST, gen_kwargs={"csv_path": extracted_path["test"],
|
| 148 |
"info_path": extracted_path["info"],
|
| 149 |
-
"
|
| 150 |
"split": "test"}
|
| 151 |
),
|
| 152 |
]
|
| 153 |
|
| 154 |
-
def _generate_examples(self, csv_path, info_path,
|
| 155 |
"""Yields examples from a CSV file containing photometry, spectra, metadata, and labels."""
|
| 156 |
|
| 157 |
-
if not os.path.exists(csv_path):
|
| 158 |
-
raise FileNotFoundError(f"Missing dataset file: {csv_path}")
|
| 159 |
-
|
| 160 |
-
if not os.path.exists(info_path):
|
| 161 |
-
raise FileNotFoundError(f"Missing info file: {info_path}")
|
| 162 |
-
|
| 163 |
df = pd.read_csv(csv_path)
|
| 164 |
|
| 165 |
with open(info_path) as f:
|
|
@@ -167,7 +161,7 @@ class AstroM3Dataset(datasets.GeneratorBasedBuilder):
|
|
| 167 |
|
| 168 |
for idx, row in df.iterrows():
|
| 169 |
photometry = self._get_photometry(row["name"])
|
| 170 |
-
spectra = self._get_spectra(
|
| 171 |
|
| 172 |
yield idx, {
|
| 173 |
"photometry": photometry,
|
|
|
|
| 124 |
spectra_urls = {}
|
| 125 |
for _, row in df_combined.iterrows():
|
| 126 |
spectra_urls[row["spec_filename"]] = f"{_URL}/spectra/{row['target']}/{row['spec_filename']}"
|
| 127 |
+
spectra_files = dl_manager.download(spectra_urls)
|
| 128 |
|
| 129 |
# Load photometry and init reader
|
| 130 |
photometry_path = dl_manager.download(f"{_URL}/photometry.zip")
|
|
|
|
| 134 |
datasets.SplitGenerator(
|
| 135 |
name=datasets.Split.TRAIN, gen_kwargs={"csv_path": extracted_path["train"],
|
| 136 |
"info_path": extracted_path["info"],
|
| 137 |
+
"spectra_files": spectra_files,
|
| 138 |
"split": "train"}
|
| 139 |
),
|
| 140 |
datasets.SplitGenerator(
|
| 141 |
name=datasets.Split.VALIDATION, gen_kwargs={"csv_path": extracted_path["val"],
|
| 142 |
"info_path": extracted_path["info"],
|
| 143 |
+
"spectra_files": spectra_files,
|
| 144 |
"split": "val"}
|
| 145 |
),
|
| 146 |
datasets.SplitGenerator(
|
| 147 |
name=datasets.Split.TEST, gen_kwargs={"csv_path": extracted_path["test"],
|
| 148 |
"info_path": extracted_path["info"],
|
| 149 |
+
"spectra_files": spectra_files,
|
| 150 |
"split": "test"}
|
| 151 |
),
|
| 152 |
]
|
| 153 |
|
| 154 |
+
def _generate_examples(self, csv_path, info_path, spectra_files, split):
|
| 155 |
"""Yields examples from a CSV file containing photometry, spectra, metadata, and labels."""
|
| 156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
df = pd.read_csv(csv_path)
|
| 158 |
|
| 159 |
with open(info_path) as f:
|
|
|
|
| 161 |
|
| 162 |
for idx, row in df.iterrows():
|
| 163 |
photometry = self._get_photometry(row["name"])
|
| 164 |
+
spectra = self._get_spectra(spectra_files[row["spec_filename"]])
|
| 165 |
|
| 166 |
yield idx, {
|
| 167 |
"photometry": photometry,
|