Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New datasets #54

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions autometacal/python/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""gal_gen dataset."""
"""galaxy datasets"""

from .gal_gen import GalGen
from .CFIS import CFIS
from .galgen import GalGen
from .cfis import CFIS
from .simple import Simple
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import numpy as np
import galsim as gs

_CITATION = """
"""

_DESCRIPTION = """
"""
_CITATION = """{NEEDED}"""
_URL = "https://github.com/CosmoStat/autometacal"
_DESCRIPTION = """Noiseless CFHT-pixel galaxies with shapes from COSMOS"""

class CFISConfig(tfds.core.BuilderConfig):
"""BuilderConfig for CFIS Galaxies."""
Expand Down Expand Up @@ -49,11 +47,20 @@ class CFIS(tfds.core.GeneratorBasedBuilder):

VERSION = tfds.core.Version('0.0.1')
RELEASE_NOTES = {
'0.0.1': 'Initial release.',
'0.0.1': 'pre alpha release.',
}

BUILDER_CONFIGS = [CFISConfig(name="parametric_1k", galaxy_type="parametric", data_set_size=1000),
CFISConfig(name="parametric_shear_1k", galaxy_type="parametric", data_set_size=1000, shear_g1=0.02)]
BUILDER_CONFIGS = [
CFISConfig(
name="parametric_1k",
galaxy_type="parametric",
data_set_size=81499),
CFISConfig(
name="parametric_shear_1k",
galaxy_type="parametric",
data_set_size=81499,
shear_g1=0.02)
]

def _info(self) -> tfds.core.DatasetInfo:
"""Returns the dataset metadata."""
Expand All @@ -62,26 +69,18 @@ def _info(self) -> tfds.core.DatasetInfo:
builder=self,
description=_DESCRIPTION,
features=tfds.features.FeaturesDict({
'obs': tfds.features.Tensor(shape=[self.builder_config.stamp_size,
self.builder_config.stamp_size],
dtype=tf.float32),
'psf': tfds.features.Tensor(shape=[self.builder_config.stamp_size,
self.builder_config.stamp_size],
dtype=tf.float32),
# 'gal_kimage': tfds.features.Tensor(shape=[2, self.builder_config.kstamp_size,
# self.builder_config.kstamp_size],
# dtype=tf.float32),
# 'psf_kimage': tfds.features.Tensor(shape=[2, self.builder_config.kstamp_size,
# self.builder_config.kstamp_size],
# dtype=tf.float32),
'gal_image': tfds.features.Tensor(
shape=[self.builder_config.stamp_size, self.builder_config.stamp_size],
dtype=tf.float32
),
'psf_image': tfds.features.Tensor(
shape=[self.builder_config.stamp_size, self.builder_config.stamp_size],
dtype=tf.float32),
"noise_std": tfds.features.Tensor(shape=[1], dtype=tf.float32),
"mag": tfds.features.Tensor(shape=[1], dtype=tf.float32),
}),
# If there's a common (input, target) tuple from the
# features, specify them here. They'll be used if
# `as_supervised=True` in `builder.as_dataset`.
supervised_keys=("obs", "obs"),
homepage='https://dataset-homepage/',
homepage=_URL,
citation=_CITATION,
)

Expand All @@ -104,47 +103,35 @@ def _generate_examples(self, size):
"""Yields examples."""
# Loads the galsim COSMOS catalog
cat = gs.COSMOSCatalog(sample="25.2")
mag_zp = 32
sky_level = 400 # ADU (~variance)
psf = gs.Kolmogorov(fwhm=self.builder_config.psf_fwhm, flux=1.0)
psf = psf.shear(g1=self.builder_config.psf_e1, g2=self.builder_config.psf_e2)

# Prepare borders for kimage
Nk = self.builder_config.kstamp_size
bounds = gs._BoundsI(-Nk//2, Nk//2-1, -Nk//2, Nk//2-1)

for i in range(size):
# retrieving galaxy and magnitude
gal = cat.makeGalaxy(i, gal_type='parametric')
gal_mag = cat.param_cat['mag_auto'][cat.orig_index[i]]
sky_level = 400
mag_zp = 32.
gal_flux = 10**(-(gal_mag-mag_zp)/2.5)

gal = gal.withFlux(gal_flux)
gal = gal.shear(g1=self.builder_config.shear_g1, g2=self.builder_config.shear_g2)

gal_conv = gs.Convolve(gal, psf)

method="auto"
gal_stamp = gal_conv.drawImage(nx=self.builder_config.stamp_size,
ny=self.builder_config.stamp_size,
scale=self.builder_config.pixel_scale
scale=self.builder_config.pixel_scale,
method=method
).array.astype('float32')

psf_stamp = psf.drawImage(nx=self.builder_config.stamp_size,
ny=self.builder_config.stamp_size,
scale=self.builder_config.pixel_scale
scale=self.builder_config.pixel_scale,
method=method
).array.astype('float32')

# gal_kimage = gal.drawKImage(bounds=bounds,
# scale=2.*np.pi/(self.builder_config.stamp_size*self.builder_config.pixel_scale),
# recenter=False).array.astype('complex64')

# psf_kimage = psf.drawKImage(bounds=bounds,
# scale=2.*np.pi/(self.builder_config.stamp_size*self.builder_config.pixel_scale),
# recenter=False).array.astype('complex64')

yield '%d'%i, {"obs": gal_stamp,
"psf": psf_stamp,
# "gal_kimage": np.stack([gal_kimage.real, gal_kimage.imag]),
# "psf_kimage": np.stack([psf_kimage.real, psf_kimage.imag]),
yield '%d'%i, {"gal_image": gal_stamp,
"psf_image": psf_stamp,
"noise_std": np.array([np.sqrt(sky_level)]).astype('float32'),
"mag": np.array([gal_mag]).astype('float32')}
131 changes: 0 additions & 131 deletions autometacal/python/datasets/gal_gen.py

This file was deleted.

Loading