Skip to content

Commit 6f4bbee

Browse files
Autofix formatting from pre-commit.com hooks
1 parent a693f7e commit 6f4bbee

35 files changed

Lines changed: 1053 additions & 716 deletions

slsim/Sources/SourceTypes/double_sersic.py

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,52 @@
33
from slsim.Util.param_util import ellipticity_slsim_to_lenstronomy
44
from slsim.Util.param_util import surface_brightness_reff
55

6+
67
class DoubleSersic(SourceBase):
7-
"""class to manage source with double sersic light profile"""
8+
"""Class to manage source with double sersic light profile."""
9+
810
def __init__(self, source_dict):
911
"""
1012
:param source_dict: Source properties. May be a dictionary or an Astropy table.
11-
This dict or table should contain atleast redshift, a magnitude in any band,
13+
This dict or table should contain atleast redshift, a magnitude in any band,
1214
sersic indices, sersic weight, angular sizes in arcsec, ellipticity.
1315
eg: {"z": 0.8, "mag_i": 22, "n_sersic_0": 1, "n_sersic_1": 4, "w0": 0.1,
14-
"w1": 0.9, "angular_size0": 0.10, "angular_size1": 0.05, "e0_1": 0.002,
15-
"e0_2": 0.001, "e1_1": 0.0, "e1_2": 0.0}. One can provide magnitudes in
16+
"w1": 0.9, "angular_size0": 0.10, "angular_size1": 0.05, "e0_1": 0.002,
17+
"e0_2": 0.001, "e1_1": 0.0, "e1_2": 0.0}. One can provide magnitudes in
1618
multiple bands.
1719
:type source_dict: dict or astropy.table.Table
1820
"""
19-
super().__init__(source_dict = source_dict)
21+
super().__init__(source_dict=source_dict)
2022

2123
@property
2224
def n_sersic(self):
2325
"""Returns sersic indices of the source for double sersic profile."""
2426

25-
return (float(self.source_dict["n_sersic_0"]),
26-
float(self.source_dict["n_sersic_1"]))
27-
27+
return (
28+
float(self.source_dict["n_sersic_0"]),
29+
float(self.source_dict["n_sersic_1"]),
30+
)
31+
2832
@property
2933
def sersicweight(self):
30-
"""Returns weight of the sersic components"""
34+
"""Returns weight of the sersic components."""
3135

3236
return self.source_dict["w0"], self.source_dict["w1"]
3337

3438
@property
3539
def angular_size(self):
36-
"""Returns angular size of the source for two component of
37-
the sersic profile."""
40+
"""Returns angular size of the source for two component of the sersic
41+
profile."""
3842

39-
return (float(self.source_dict["angular_size0"]),
40-
float(self.source_dict["angular_size1"]))
43+
return (
44+
float(self.source_dict["angular_size0"]),
45+
float(self.source_dict["angular_size1"]),
46+
)
4147

4248
@property
4349
def ellipticity(self):
44-
"""Returns ellipticity components of source for the both component of
45-
the light profile. first two ellipticity components are associated with the
50+
"""Returns ellipticity components of source for the both component of
51+
the light profile. first two ellipticity components are associated with the
4652
first sersic component and last two are associated with the second sersic component.
4753
Defined as:
4854
@@ -53,9 +59,13 @@ def ellipticity(self):
5359
with q being the minor-to-major axis ratio.
5460
"""
5561

56-
return (float(self.source_dict["e0_1"]), float(self.source_dict["e0_2"]),
57-
float(self.source_dict["e1_1"]), float(self.source_dict["e1_2"]))
58-
62+
return (
63+
float(self.source_dict["e0_1"]),
64+
float(self.source_dict["e0_2"]),
65+
float(self.source_dict["e1_1"]),
66+
float(self.source_dict["e1_2"]),
67+
)
68+
5969
def extended_source_magnitude(self, band):
6070
"""Get the magnitude of the extended source in a specific band.
6171
@@ -71,12 +81,12 @@ def extended_source_magnitude(self, band):
7181
band_string = "mag_" + band
7282
source_mag = self.source_dict[band_string]
7383
return source_mag
74-
84+
7585
def kwargs_extended_source_light(self, reference_position, draw_area, band=None):
7686
"""Provides dictionary of keywords for the source light model(s).
7787
Kewords used are in lenstronomy conventions.
7888
79-
:param reference_position: reference position. the source postion will be
89+
:param reference_position: reference position. the source postion will be
8090
defined relative to this position.
8191
Eg: np.array([0, 0])
8292
:param draw_area: The area of the test region from which we randomly draw a
@@ -136,11 +146,11 @@ def extended_source_light_model(self):
136146
:return: list of extented source model.
137147
"""
138148
source_models_list = [
139-
"SERSIC_ELLIPSE",
140-
"SERSIC_ELLIPSE",
141-
]
149+
"SERSIC_ELLIPSE",
150+
"SERSIC_ELLIPSE",
151+
]
142152
return source_models_list
143-
153+
144154
def surface_brightness_reff(self, band=None):
145155
"""Calculate average surface brightness within half light radius.
146156
@@ -150,8 +160,11 @@ def surface_brightness_reff(self, band=None):
150160
"""
151161
angularsize = np.mean(self.angular_size)
152162
# reference_position and draw_area do not matter, they are dummy input here.
153-
kwargs_source = self.kwargs_extended_source_light(reference_position=[0, 0],
154-
draw_area=4*np.pi, band=band)
155-
return surface_brightness_reff(angular_size=angularsize,
156-
source_model_list=self.extended_source_light_model(),
157-
kwargs_extended_source=kwargs_source)
163+
kwargs_source = self.kwargs_extended_source_light(
164+
reference_position=[0, 0], draw_area=4 * np.pi, band=band
165+
)
166+
return surface_brightness_reff(
167+
angular_size=angularsize,
168+
source_model_list=self.extended_source_light_model(),
169+
kwargs_extended_source=kwargs_source,
170+
)

slsim/Sources/SourceTypes/extended_source.py

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@
44

55
_SUPPORTED_EXTENDED_SOURCES = ["single_sersic", "double_sersic", "interpolated"]
66

7+
78
class ExtendedSource(object):
8-
"""Class to manage a single extended source"""
9-
def __init__(self, source_dict,
10-
cosmo=None, **kwargs):
9+
"""Class to manage a single extended source."""
10+
11+
def __init__(self, source_dict, cosmo=None, **kwargs):
1112
"""
1213
:param source_dict: Source properties. May be a dictionary or an Astropy table.
1314
For a detailed description of this dictionary, please see the documentation for
1415
the SingleSersic, DoubleSersic, and Interpolated classes.
1516
:type source_dict: dict or astropy.table.Table
1617
:param extendedsource_type: keyword for specifying light profile model.
17-
:type extendedsource_type: str. supported types are "single_sersic",
18+
:type extendedsource_type: str. supported types are "single_sersic",
1819
"double_sersic", "interpolated".
1920
:param cosmo: astropy.cosmology instance
2021
:param kwargs: dictionary of keyword arguments for a extended source.
21-
eg: kwargs = {"extendedsource_type": "single_sersic"}. Other supported
22+
eg: kwargs = {"extendedsource_type": "single_sersic"}. Other supported
2223
types are "single_sersic", "double_sersic", "interpolated".
2324
"""
2425
self.extendedsource_type = kwargs["extendedsource_type"]
@@ -33,19 +34,19 @@ def __init__(self, source_dict,
3334
"Extended source type %s not supported. Chose among %s."
3435
% (self.extendedsource_type, _SUPPORTED_EXTENDED_SOURCES)
3536
)
36-
37+
3738
@property
3839
def redshift(self):
3940
"""Returns source redshift."""
4041

4142
return self._source.redshift
42-
43+
4344
@property
4445
def angular_size(self):
4546
"""Returns angular size of the source."""
4647

4748
return self._source.angular_size
48-
49+
4950
@property
5051
def ellipticity(self):
5152
"""Returns ellipticity components of source.
@@ -57,9 +58,9 @@ def ellipticity(self):
5758
5859
with q being the minor-to-major axis ratio.
5960
"""
60-
61+
6162
return self._source.ellipticity
62-
63+
6364
@property
6465
def n_sersic(self):
6566
"""Returns sersic indices of the source profile."""
@@ -68,48 +69,49 @@ def n_sersic(self):
6869

6970
@property
7071
def sersicweight(self):
71-
"""Returns weight of the sersic components"""
72+
"""Returns weight of the sersic components."""
7273

7374
return self._source.sersicweight
74-
75+
7576
@property
7677
def image_redshift(self):
77-
"""Returns redshift of a given image"""
78-
78+
"""Returns redshift of a given image."""
79+
7980
return self._source.image_redshift
80-
81+
8182
@property
8283
def image(self):
83-
"""Returns image of a given extended source"""
84-
84+
"""Returns image of a given extended source."""
85+
8586
return self._source.image
8687

8788
@property
8889
def phi(self):
89-
"""Returns position angle of a given image in arcsec"""
90+
"""Returns position angle of a given image in arcsec."""
9091

9192
return self._source.phi
92-
93+
9394
@property
9495
def pixel_scale(self):
95-
"""Returns pixel scale of a given image"""
96+
"""Returns pixel scale of a given image."""
9697

9798
return self._source.pixel_scale
98-
99+
99100
def extended_source_position(self, reference_postion, draw_area):
100101
"""Extended source position. If a center has already been provided (and
101-
stored in self._center_source during initialization of _source), then it is simply
102-
returned. Otherwise, a source position is drawn uniformly within the
103-
circle of the test area centered on the deflector position. see: _source.
102+
stored in self._center_source during initialization of _source), then
103+
it is simply returned. Otherwise, a source position is drawn uniformly
104+
within the circle of the test area centered on the deflector position.
105+
see: _source.
104106
105-
:param reference_position: reference position. the source postion will be
107+
:param reference_position: reference position. the source postion will be
106108
defined relative to this position.
107109
Eg: np.array([0, 0])
108110
:param draw_area: The area of the test region from which we randomly draw a source
109111
position. Eg: 4*pi.
110112
:return: [x_pos, y_pos]
111113
"""
112-
114+
113115
return self._source.extended_source_position(reference_postion, draw_area)
114116

115117
def extended_source_magnitude(self, band):
@@ -122,29 +124,31 @@ def extended_source_magnitude(self, band):
122124
"""
123125

124126
return self._source.extended_source_magnitude(band=band)
125-
127+
126128
def kwargs_extended_source_light(self, reference_position, draw_area, band=None):
127129
"""Provides dictionary of keywords for the source light model(s).
128130
Kewords used are in lenstronomy conventions.
129131
130-
:param reference_position: reference position. the source postion will be
132+
:param reference_position: reference position. the source postion will be
131133
defined relative to this position.
132134
Eg: np.array([0, 0])
133135
:param draw_area: The area of the test region from which we randomly draw a
134136
source position. Eg: 4*pi.
135137
:param band: Imaging band
136138
:return: dictionary of keywords for the source light model(s)
137139
"""
138-
139-
return self._source.kwargs_extended_source_light(reference_position, draw_area, band)
140-
140+
141+
return self._source.kwargs_extended_source_light(
142+
reference_position, draw_area, band
143+
)
144+
141145
def extended_source_light_model(self):
142146
"""Provides a list of source models.
143147
144148
:return: list of extented source model.
145149
"""
146150
return self._source.extended_source_light_model()
147-
151+
148152
def surface_brightness_reff(self, band=None):
149153
"""Calculate average surface brightness within half light radius.
150154
@@ -153,4 +157,4 @@ def surface_brightness_reff(self, band=None):
153157
[mag/arcsec^2]
154158
"""
155159

156-
return self._source.surface_brightness_reff(band=band)
160+
return self._source.surface_brightness_reff(band=band)

slsim/Sources/SourceTypes/general_lightcurve.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
from slsim.Sources.SourceVariability.variability import Variability
22
from slsim.Sources.SourceTypes.source_base import SourceBase
33

4+
45
class GeneralLightCurve(SourceBase):
5-
"""A class to manage a source with given lightcurve"""
6-
def __init__(self,
7-
source_dict,
8-
**kwargs
9-
):
6+
"""A class to manage a source with given lightcurve."""
7+
8+
def __init__(self, source_dict, **kwargs):
109
"""
1110
:param source_dict: Source properties. May be a dictionary or an Astropy table.
12-
This table or dict should contain atleast redshift of a supernova, offset from
13-
the host if host galaxy is available, and lightcurve in a desired band.
14-
eg: data={"z": 0.8, "MJD":
15-
np.array([1,2,3,4,5,6,7,8,9]),
11+
This table or dict should contain atleast redshift of a supernova, offset from
12+
the host if host galaxy is available, and lightcurve in a desired band.
13+
eg: data={"z": 0.8, "MJD":
14+
np.array([1,2,3,4,5,6,7,8,9]),
1615
"ps_mag_i": np.array([15, 16, 17, 18, 19, 20, 21, 22, 23]), "ra_off": 0.001,
1716
"dec_off": 0.002}
1817
:type source_dict: dict or astropy.table.Table
@@ -22,10 +21,11 @@ def __init__(self,
2221
input for the Variability class.
2322
:type variability_model: str
2423
"""
25-
26-
super().__init__(source_dict = source_dict)
24+
25+
super().__init__(source_dict=source_dict)
2726
# These are the keywords that kwargs dict should contain
2827
self.variability_model = kwargs.get("variability_model")
28+
2929
def point_source_magnitude(self, band, image_observation_times=None):
3030
"""Get the magnitude of the point source in a specific band.
3131
@@ -39,18 +39,21 @@ def point_source_magnitude(self, band, image_observation_times=None):
3939

4040
column_names = self.source_dict.colnames
4141
if "ps_mag_" + band not in column_names:
42-
raise ValueError("%s band magnitudes are missing in the source dictionary." % band)
42+
raise ValueError(
43+
"%s band magnitudes are missing in the source dictionary." % band
44+
)
4345
else:
4446
band_string = "ps_mag_" + band
45-
kwargs_variab_band = {"MJD": self.source_dict["MJD"],
46-
band_string: self.source_dict[band_string]}
47+
kwargs_variab_band = {
48+
"MJD": self.source_dict["MJD"],
49+
band_string: self.source_dict[band_string],
50+
}
4751
self.variability_class = Variability(
48-
self.variability_model, **kwargs_variab_band
49-
)
52+
self.variability_model, **kwargs_variab_band
53+
)
5054
if image_observation_times is not None:
51-
variable_mag = self.variability_class.variability_at_time(
52-
image_observation_times
53-
)
54-
return variable_mag
55+
variable_mag = self.variability_class.variability_at_time(
56+
image_observation_times
57+
)
58+
return variable_mag
5559
return kwargs_variab_band[band_string]
56-

0 commit comments

Comments
 (0)