MCPcopy Create free account
hub / github.com/PolymathicAI/AstroCLIP / _generate_examples

Method _generate_examples

astroclip/data/dataset.py:95–118  ·  view source on GitHub ↗

Yields examples.

(self, filepath, split)

Source from the content-addressed store, hash-verified

93 ]
94
95 def _generate_examples(self, filepath, split):
96 """Yields examples."""
97 with h5py.File(filepath) as d:
98 for i in range(10):
99 # Access the data
100 images = d[str(i)]["images"]
101 spectra = d[str(i)]["spectra"]
102 redshifts = d[str(i)]["redshifts"]
103 targetids = d[str(i)]["targetids"]
104
105 dset_size = len(targetids)
106
107 if split == "train":
108 dset_range = (0, int(0.8 * dset_size))
109 else:
110 dset_range = (int(0.8 * dset_size), dset_size)
111
112 for j in range(dset_range[0], dset_range[1]):
113 yield str(targetids[j]), {
114 "image": np.array(images[j]).astype("float32"),
115 "spectrum": np.reshape(spectra[j], [-1, 1]).astype("float32"),
116 "redshift": redshifts[j],
117 "targetid": targetids[j],
118 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected