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

OM10-cosmoDC2 lensed AGN systems #75

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ How to contribute to the repository?
Check out our step-by-step instructions how you can contribute code to this project Contributing_ Guidelines.
Are you new to coding and contributing to a software development project? No worries! We help you out! Write us on the LSST Slack channel #sl-pipeline.

Note: `sim-pipeline` is written in object-oriented python. What fun!

How can I participate in LSST strong lensing projects?
------------------------------------------------------
Expand Down
1,558 changes: 1,558 additions & 0 deletions data/OM10/deflectors3.csv

Large diffs are not rendered by default.

1,558 changes: 1,558 additions & 0 deletions data/OM10/deflectors_no_gamma.csv

Large diffs are not rendered by default.

1,558 changes: 1,558 additions & 0 deletions data/OM10/sources3.csv

Large diffs are not rendered by default.

1,558 changes: 1,558 additions & 0 deletions data/OM10/sources_no_gamma.csv

Large diffs are not rendered by default.

15 changes: 4 additions & 11 deletions notebooks/galaxy_galaxy_lensing_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -192,7 +192,7 @@
"\n",
"# generate montage indicating which bands are used for the rgb color image\n",
"fig, axes = gg_plot.plot_montage(\n",
" rgb_band_list=[\"i\", \"r\", \"g\"],\n",
" rgb_band_list=[\"i\"],\n",
" add_noise=True,\n",
" n_horizont=5,\n",
" n_vertical=2,\n",
Expand All @@ -211,7 +211,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {
"execution": {
"iopub.execute_input": "2023-07-10T22:03:19.932376Z",
Expand Down Expand Up @@ -307,13 +307,6 @@
"corner.corner(np.array(lens_samples), labels=labels, **hist2dkwargs)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -332,7 +325,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.11.4"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion slsim/Deflectors/deflectors_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DeflectorsBase(ABC):
def __init__(self, deflector_table, kwargs_cut, cosmo, sky_area):
"""

:param deflector_table: table with lens parameters
:param deflector_table: file or table with lens parameters
:param kwargs_cut: cuts in parameters: band, band_mag, z_min, z_max
:type kwargs_cut: dict
:param cosmo: astropy.cosmology instance
Expand Down
31 changes: 31 additions & 0 deletions slsim/Deflectors/om10_lens_galaxies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from slsim.Deflectors.deflector_base import DeflectorBase

Check warning on line 1 in slsim/Deflectors/om10_lens_galaxies.py

View check run for this annotation

Codecov / codecov/patch

slsim/Deflectors/om10_lens_galaxies.py#L1

Added line #L1 was not covered by tests


class OM10Lens(DeflectorBase):
def __init__(self, deflector_table, kwargs_cut, cosmo, sky_area):

Check warning on line 5 in slsim/Deflectors/om10_lens_galaxies.py

View check run for this annotation

Codecov / codecov/patch

slsim/Deflectors/om10_lens_galaxies.py#L4-L5

Added lines #L4 - L5 were not covered by tests
"""
:param deflector_table: dict-like containing lens properties
:param kwargs_cut: cuts to impose on lens properties
:param cosmo: cosmology used
:param sky_area: area of sky used

"""
super().__init__(deflector_table, kwargs_cut, cosmo, sky_area)
self.deflector_table = deflector_table

Check warning on line 14 in slsim/Deflectors/om10_lens_galaxies.py

View check run for this annotation

Codecov / codecov/patch

slsim/Deflectors/om10_lens_galaxies.py#L13-L14

Added lines #L13 - L14 were not covered by tests

@property
def deflector_number(self):

Check warning on line 17 in slsim/Deflectors/om10_lens_galaxies.py

View check run for this annotation

Codecov / codecov/patch

slsim/Deflectors/om10_lens_galaxies.py#L16-L17

Added lines #L16 - L17 were not covered by tests
"""

:return: number of deflectors after applied cuts
"""
return len(self.deflector_table)

Check warning on line 22 in slsim/Deflectors/om10_lens_galaxies.py

View check run for this annotation

Codecov / codecov/patch

slsim/Deflectors/om10_lens_galaxies.py#L22

Added line #L22 was not covered by tests

def draw_deflector(self, index):

Check warning on line 24 in slsim/Deflectors/om10_lens_galaxies.py

View check run for this annotation

Codecov / codecov/patch

slsim/Deflectors/om10_lens_galaxies.py#L24

Added line #L24 was not covered by tests
"""
:param index: id number of lens and source

:return: dictionary of complete parameterization of deflector
"""
self._chosen_deflector = dict(self.deflector_table.loc[index])
return self._chosen_deflector

Check warning on line 31 in slsim/Deflectors/om10_lens_galaxies.py

View check run for this annotation

Codecov / codecov/patch

slsim/Deflectors/om10_lens_galaxies.py#L30-L31

Added lines #L30 - L31 were not covered by tests
38 changes: 38 additions & 0 deletions slsim/Pipelines/catalog_pipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os
import slsim
import pandas as pd

Check warning on line 3 in slsim/Pipelines/catalog_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/Pipelines/catalog_pipeline.py#L1-L3

Added lines #L1 - L3 were not covered by tests


class catalogPipeline:

Check warning on line 6 in slsim/Pipelines/catalog_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/Pipelines/catalog_pipeline.py#L6

Added line #L6 was not covered by tests
"""Class for skypy configuration."""

def __init__(self, catalog_config=None):

Check warning on line 9 in slsim/Pipelines/catalog_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/Pipelines/catalog_pipeline.py#L9

Added line #L9 was not covered by tests
"""
:param catalog_config: path to configuration file.
:type catalog_config: string
"""
path = os.path.dirname(slsim.__file__)
module_path, _ = os.path.split(path)
folder = os.path.join(module_path, catalog_config)
self._sources = pd.read_csv(os.path.join(folder, "sources.csv"), index_col=0)
self._deflectors = pd.read_csv(

Check warning on line 18 in slsim/Pipelines/catalog_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/Pipelines/catalog_pipeline.py#L14-L18

Added lines #L14 - L18 were not covered by tests
os.path.join(folder, "deflectors.csv"), index_col=0
)

@property
def sources(self):

Check warning on line 23 in slsim/Pipelines/catalog_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/Pipelines/catalog_pipeline.py#L22-L23

Added lines #L22 - L23 were not covered by tests
"""Source properties.

:return: list of COSMODC2 Quasars
:rtype: list of dict
"""
return self._sources

Check warning on line 29 in slsim/Pipelines/catalog_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/Pipelines/catalog_pipeline.py#L29

Added line #L29 was not covered by tests

@property
def deflectors(self):

Check warning on line 32 in slsim/Pipelines/catalog_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/Pipelines/catalog_pipeline.py#L31-L32

Added lines #L31 - L32 were not covered by tests
"""Deflector properties.

:return: list of OM10 galaxies
:rtype: list of dict
"""
return self._deflectors

Check warning on line 38 in slsim/Pipelines/catalog_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/Pipelines/catalog_pipeline.py#L38

Added line #L38 was not covered by tests
29 changes: 29 additions & 0 deletions slsim/Sources/cosmoDC2AGN.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from slsim.Sources.source_pop_base import SourcePopBase

Check warning on line 1 in slsim/Sources/cosmoDC2AGN.py

View check run for this annotation

Codecov / codecov/patch

slsim/Sources/cosmoDC2AGN.py#L1

Added line #L1 was not covered by tests


class cosmoDC2AGN(SourcePopBase):
def __init__(self, source_input, cosmo, sky_area):

Check warning on line 5 in slsim/Sources/cosmoDC2AGN.py

View check run for this annotation

Codecov / codecov/patch

slsim/Sources/cosmoDC2AGN.py#L4-L5

Added lines #L4 - L5 were not covered by tests
"""
:param source_input: dict-like containing source properties
:param cosmo: cosmology used
:param sky_area:
"""
self.source_table = source_input
super().__init__(cosmo, sky_area)

Check warning on line 12 in slsim/Sources/cosmoDC2AGN.py

View check run for this annotation

Codecov / codecov/patch

slsim/Sources/cosmoDC2AGN.py#L11-L12

Added lines #L11 - L12 were not covered by tests

@property
def source_number(self):

Check warning on line 15 in slsim/Sources/cosmoDC2AGN.py

View check run for this annotation

Codecov / codecov/patch

slsim/Sources/cosmoDC2AGN.py#L14-L15

Added lines #L14 - L15 were not covered by tests
"""Number of sources registered (within given area on the sky)

:return: number of sources
"""
return len(self.source_table)

Check warning on line 20 in slsim/Sources/cosmoDC2AGN.py

View check run for this annotation

Codecov / codecov/patch

slsim/Sources/cosmoDC2AGN.py#L20

Added line #L20 was not covered by tests

def draw_source(self, index):

Check warning on line 22 in slsim/Sources/cosmoDC2AGN.py

View check run for this annotation

Codecov / codecov/patch

slsim/Sources/cosmoDC2AGN.py#L22

Added line #L22 was not covered by tests
"""Choose source at random.

:param index: id number of lens and source
:return: dictionary of source
"""
self._chosen_source = dict(self.source_table.loc[index])
return self._chosen_source

Check warning on line 29 in slsim/Sources/cosmoDC2AGN.py

View check run for this annotation

Codecov / codecov/patch

slsim/Sources/cosmoDC2AGN.py#L28-L29

Added lines #L28 - L29 were not covered by tests
18 changes: 16 additions & 2 deletions slsim/Util/param_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
from scipy.signal import convolve2d
from scipy.signal import fftconvolve
from lenstronomy.Util.param_util import transform_e1e2_product_average
from lenstronomy.Util.param_util import ellipticity2phi_q
from astropy.io import fits
from astropy import units as u
import warnings


def epsilon2e(epsilon):
"""Translates ellipticity definitions from.
"""Translates ellipticity definitions from epsilon to e.

.. math::
epsilon = \\equic \\frac{1 - q^2}{1 + q^2}
Expand All @@ -31,6 +30,21 @@ def epsilon2e(epsilon):
raise ValueError('Value of "epsilon" is %s and needs to be in [0, 1]' % epsilon)


def ellipticity2phi_q(e1, e2):
"""Transforms complex ellipticity moduli in orientation angle and axis ratio.

:param e1: eccentricity in x-direction
:param e2: eccentricity in xy-direction
:return: angle in radian, axis ratio (minor/major)
"""

phi = np.arctan2(e2, e1) / 2
c = np.sqrt(e1**2 + e2**2)
c = np.minimum(c, 0.9999)
q = (1 - c) / (1 + c)
return phi, q


def e2epsilon(e):
"""Translates ellipticity definitions from.

Expand Down
64 changes: 64 additions & 0 deletions slsim/image_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
:return: 2d array unblurred image
"""
kwargs_model, kwargs_params = lens_class.lenstronomy_kwargs(band)

kwargs_band = {
"pixel_scale": delta_pix,
"magnitude_zero_point": mag_zero_point,
Expand Down Expand Up @@ -166,6 +167,69 @@
return image_rgb


def quasar_image(
lens_class,
band,
kwargs_band,
num_pix,
with_source=True,
with_ps=True,
with_deflector=True,
unconvolved=False,
add_noise=True,
bg_noise=True,
):
"""
:param lens_class: Lens() object
:param band: imaging band
:param kwargs_band: key word arguments including: read_noise, pixel_scale, ccd_gain,
exposure_time, sky_brightness, magnitude_zero_point, num_exposures, seeing, psf_type,
kernel_point_source
:param num_pix: number of pixels per axis
:param with_source: bool, if True includes extended source light
:param with_ps: bool, if True includes point source light
:param with_deflector: bool, if True includes deflector light
:param unconvolved: bool, if True PSF is not convolved with extended source light or lens light
:param add_noise: bool, if True add noise
:return: 2d array of image
"""
kwargs_model, kwargs_params = lens_class.lenstronomy_kwargs(band)
kwargs_band = kwargs_band
sim_api = SimAPI(

Check warning on line 198 in slsim/image_simulation.py

View check run for this annotation

Codecov / codecov/patch

slsim/image_simulation.py#L196-L198

Added lines #L196 - L198 were not covered by tests
numpix=num_pix, kwargs_single_band=kwargs_band, kwargs_model=kwargs_model
)
kwargs_lens_light, kwargs_source, kwargs_ps = sim_api.magnitude2amplitude(

Check warning on line 201 in slsim/image_simulation.py

View check run for this annotation

Codecov / codecov/patch

slsim/image_simulation.py#L201

Added line #L201 was not covered by tests
kwargs_lens_light_mag=kwargs_params.get("kwargs_lens_light", None),
kwargs_source_mag=kwargs_params.get("kwargs_source", None),
kwargs_ps_mag=kwargs_params.get("kwargs_ps", None),
)
kwargs_numerics = {"supersampling_factor": 1}
image_model = sim_api.image_model_class(kwargs_numerics)
kwargs_lens = kwargs_params.get("kwargs_lens", None)
image = image_model.image(

Check warning on line 209 in slsim/image_simulation.py

View check run for this annotation

Codecov / codecov/patch

slsim/image_simulation.py#L206-L209

Added lines #L206 - L209 were not covered by tests
kwargs_lens=kwargs_lens,
kwargs_source=kwargs_source,
kwargs_lens_light=kwargs_lens_light,
kwargs_ps=kwargs_ps,
unconvolved=unconvolved,
source_add=with_source,
lens_light_add=with_deflector,
point_source_add=with_ps,
)
if add_noise:
image += sim_api.noise_for_model(model=image, background_noise=bg_noise)

Check warning on line 220 in slsim/image_simulation.py

View check run for this annotation

Codecov / codecov/patch

slsim/image_simulation.py#L219-L220

Added lines #L219 - L220 were not covered by tests

return (

Check warning on line 222 in slsim/image_simulation.py

View check run for this annotation

Codecov / codecov/patch

slsim/image_simulation.py#L222

Added line #L222 was not covered by tests
image,
kwargs_model,
kwargs_params,
kwargs_lens,
kwargs_lens_light,
kwargs_source,
kwargs_ps,
)


def rgb_image_from_image_list(image_list, stretch):
"""Creates a rgb image using list of images in r, g, and b.

Expand Down
Loading
Loading