Updated loading logic
Browse files- AstroM3Dataset.py +47 -6
- utils/parallelzipfile.py → utils.py +0 -0
- utils/__init__.py +0 -0
AstroM3Dataset.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
import os
|
| 2 |
from io import BytesIO
|
| 3 |
import datasets
|
| 4 |
import pandas as pd
|
|
@@ -6,7 +5,7 @@ import numpy as np
|
|
| 6 |
import json
|
| 7 |
from astropy.io import fits
|
| 8 |
|
| 9 |
-
from utils
|
| 10 |
|
| 11 |
_DESCRIPTION = (
|
| 12 |
"AstroM3 is a time-series astronomy dataset containing photometry, spectra, "
|
|
@@ -49,8 +48,8 @@ class AstroM3Dataset(datasets.GeneratorBasedBuilder):
|
|
| 49 |
description=_DESCRIPTION,
|
| 50 |
features=datasets.Features(
|
| 51 |
{
|
| 52 |
-
"photometry": datasets.
|
| 53 |
-
"spectra": datasets.
|
| 54 |
"metadata": datasets.Sequence(datasets.Value("float32"), length=38),
|
| 55 |
"label": datasets.Value("string"),
|
| 56 |
}
|
|
@@ -100,6 +99,29 @@ class AstroM3Dataset(datasets.GeneratorBasedBuilder):
|
|
| 100 |
|
| 101 |
return np.vstack((wavelength, specflux, ivar)).T
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
def _split_generators(self, dl_manager):
|
| 104 |
"""Returns SplitGenerators for train, val, and test."""
|
| 105 |
|
|
@@ -128,7 +150,7 @@ class AstroM3Dataset(datasets.GeneratorBasedBuilder):
|
|
| 128 |
|
| 129 |
# Load photometry and init reader
|
| 130 |
photometry_path = dl_manager.download(f"{_URL}/photometry.zip")
|
| 131 |
-
self.reader_v =
|
| 132 |
|
| 133 |
return [
|
| 134 |
datasets.SplitGenerator(
|
|
@@ -159,10 +181,29 @@ class AstroM3Dataset(datasets.GeneratorBasedBuilder):
|
|
| 159 |
with open(info_path) as f:
|
| 160 |
info = json.loads(f.read())
|
| 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,
|
| 168 |
"spectra": spectra,
|
|
|
|
|
|
|
| 1 |
from io import BytesIO
|
| 2 |
import datasets
|
| 3 |
import pandas as pd
|
|
|
|
| 5 |
import json
|
| 6 |
from astropy.io import fits
|
| 7 |
|
| 8 |
+
from utils import ParallelZipFile
|
| 9 |
|
| 10 |
_DESCRIPTION = (
|
| 11 |
"AstroM3 is a time-series astronomy dataset containing photometry, spectra, "
|
|
|
|
| 48 |
description=_DESCRIPTION,
|
| 49 |
features=datasets.Features(
|
| 50 |
{
|
| 51 |
+
"photometry": datasets.Array2D(shape=(None, 3), dtype="float32"),
|
| 52 |
+
"spectra": datasets.Array2D(shape=(None, 3), dtype="float32"),
|
| 53 |
"metadata": datasets.Sequence(datasets.Value("float32"), length=38),
|
| 54 |
"label": datasets.Value("string"),
|
| 55 |
}
|
|
|
|
| 99 |
|
| 100 |
return np.vstack((wavelength, specflux, ivar)).T
|
| 101 |
|
| 102 |
+
@staticmethod
|
| 103 |
+
def _transform_metadata(row, info):
|
| 104 |
+
row_copy = row.copy(deep=True)
|
| 105 |
+
|
| 106 |
+
for transformation_type, value in info["metadata_func"].items():
|
| 107 |
+
if transformation_type == "abs":
|
| 108 |
+
for col in value:
|
| 109 |
+
row_copy[col] = (
|
| 110 |
+
row_copy[col] - 10 + 5 * np.log10(np.where(row_copy["parallax"] <= 0, 1, row_copy["parallax"]))
|
| 111 |
+
)
|
| 112 |
+
elif transformation_type == "cos":
|
| 113 |
+
for col in value:
|
| 114 |
+
row_copy[col] = np.cos(np.radians(row_copy[col]))
|
| 115 |
+
elif transformation_type == "sin":
|
| 116 |
+
for col in value:
|
| 117 |
+
row_copy[col] = np.sin(np.radians(row_copy[col]))
|
| 118 |
+
elif transformation_type == "log":
|
| 119 |
+
for col in value:
|
| 120 |
+
row_copy[col] = np.log10(row_copy[col])
|
| 121 |
+
|
| 122 |
+
row_copy = (row_copy - info["mean"]) / info["std"]
|
| 123 |
+
return row_copy
|
| 124 |
+
|
| 125 |
def _split_generators(self, dl_manager):
|
| 126 |
"""Returns SplitGenerators for train, val, and test."""
|
| 127 |
|
|
|
|
| 150 |
|
| 151 |
# Load photometry and init reader
|
| 152 |
photometry_path = dl_manager.download(f"{_URL}/photometry.zip")
|
| 153 |
+
self.reader_v = ParallelZipFile(photometry_path)
|
| 154 |
|
| 155 |
return [
|
| 156 |
datasets.SplitGenerator(
|
|
|
|
| 181 |
with open(info_path) as f:
|
| 182 |
info = json.loads(f.read())
|
| 183 |
|
| 184 |
+
for i, (idx, row) in enumerate(df.iterrows()):
|
| 185 |
photometry = self._get_photometry(row["name"])
|
| 186 |
spectra = self._get_spectra(spectra_files[row["spec_filename"]])
|
| 187 |
|
| 188 |
+
metadata = row[info["all_cols"]]
|
| 189 |
+
# metadata_norm = self._transform_metadata(metadata, info)
|
| 190 |
+
|
| 191 |
+
# yield idx, {
|
| 192 |
+
# "photometry": photometry,
|
| 193 |
+
# "spectra": spectra,
|
| 194 |
+
# "metadata": {
|
| 195 |
+
# "original": {
|
| 196 |
+
# "photometry": metadata[info["photo_cols"]].to_dict(),
|
| 197 |
+
# "metadata": metadata[info["meta_cols"]].to_dict()
|
| 198 |
+
# },
|
| 199 |
+
# "transformed": {
|
| 200 |
+
# "photometry": metadata_norm[info["photo_cols"]].to_dict(),
|
| 201 |
+
# "metadata": metadata_norm[info["meta_cols"]].to_dict()
|
| 202 |
+
# }
|
| 203 |
+
# },
|
| 204 |
+
# "label": row["target"],
|
| 205 |
+
# }
|
| 206 |
+
|
| 207 |
yield idx, {
|
| 208 |
"photometry": photometry,
|
| 209 |
"spectra": spectra,
|
utils/parallelzipfile.py → utils.py
RENAMED
|
File without changes
|
utils/__init__.py
DELETED
|
File without changes
|