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

created a skeleton function opsim_time_series_images_data #125

Merged
merged 81 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
fd4837a
created a skeleton function opsim_time_series_images_data to get obse…
Nikki1510 Jan 25, 2024
461df2f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 25, 2024
1a6f301
commented out unused variables
Nikki1510 Jan 29, 2024
9fb415e
restructured opsim_time_series_images_data
Nikki1510 Feb 26, 2024
92dba21
added psf kernel and zero point calculation
Nikki1510 Mar 8, 2024
db01c8e
Merge branch 'LSST-strong-lensing:main' into opsim
Nikki1510 Mar 8, 2024
0827cdb
Merge branch 'opsim' of github.com:Nikki1510/slsim into opsim
Nikki1510 Mar 8, 2024
df45d13
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 8, 2024
605317e
Changed bare except clauses
Nikki1510 Mar 8, 2024
a0bbf6b
Resolved merge conflicts
Nikki1510 Mar 8, 2024
838f808
fixed some more merge conflict leftovers
Nikki1510 Mar 8, 2024
ce23d58
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 8, 2024
9e8c338
resolved merge conflict
Nikki1510 Jul 12, 2024
33aaaaa
Merge branch 'opsim' of github.com:Nikki1510/slsim into opsim
Nikki1510 Jul 12, 2024
c320667
started notebook to use opsim for simulated lensed SNe
Nikki1510 Jul 30, 2024
42fc1bb
started new notebook to test the opsim implementation
Nikki1510 Jul 30, 2024
6b51978
created function opsim_variable_lens_injection
Nikki1510 Jul 30, 2024
3e7935f
updated .gitignore to exclude the large opsim and scotch files
Nikki1510 Jul 30, 2024
5b3c5f5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 30, 2024
7118a4e
Merge remote-tracking branch 'slsim-project/main' into opsim
Nikki1510 Jul 30, 2024
61a909c
demonstrated the injection and image_series functions with opsim. sti…
Nikki1510 Aug 2, 2024
3dc9916
added the print_warning argument to opsim_time_series_images_data
Nikki1510 Aug 2, 2024
d4e72a3
Merge branch 'main' of https://github.com/LSST-strong-lensing/slsim i…
Nikki1510 Aug 2, 2024
5d31c57
Merge branch 'LSST-strong-lensing:main' into opsim
Nikki1510 Aug 2, 2024
0a85c55
solved merge conflict
Nikki1510 Aug 2, 2024
8c0f7a0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 2, 2024
d7ca480
solved merge conflicts
Nikki1510 Aug 2, 2024
6196e01
Merge branch 'opsim' of github.com:Nikki1510/slsim into opsim
Nikki1510 Aug 2, 2024
dca30b7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 2, 2024
7d7cfec
fetched new version and solved merge conflicts
Nikki1510 Aug 5, 2024
625fb8e
Merge branch 'opsim' of github.com:Nikki1510/slsim into opsim
Nikki1510 Aug 5, 2024
f13c188
solved more merge conflicts
Nikki1510 Aug 5, 2024
cad04ff
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 5, 2024
a4b0554
modified create_image_montage_from_image_list() to take in an extra p…
Nikki1510 Aug 7, 2024
bc781a9
modified lens_image_series() to also accept a list or array of bands
Nikki1510 Aug 7, 2024
e236552
added data/SALT3.NIR_WAVEEXT/ to the files to be ignored
Nikki1510 Aug 7, 2024
c1ee95f
tutorial can now use opsim to simulate time series images
Nikki1510 Aug 7, 2024
34794cb
Merge remote-tracking branch 'slsim-project/main' into opsim
Nikki1510 Aug 7, 2024
4ff46f1
Merge branch 'opsim' of github.com:Nikki1510/slsim into opsim
Nikki1510 Aug 7, 2024
978c21b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 7, 2024
9782e9e
Delete notebooks/lens_source_injection-Copy1.ipynb
Nikki1510 Aug 8, 2024
ad3dff3
simplified code using OpSimSummaryV2 to calculate ZPT and added optio…
Nikki1510 Aug 9, 2024
bd73898
Merge branch 'LSST-strong-lensing:main' into opsim
Nikki1510 Aug 9, 2024
917ee0a
Merge remote-tracking branch 'slsim-project/main' into opsim
Nikki1510 Aug 9, 2024
ff3ebcc
Merge branch 'opsim' of github.com:Nikki1510/slsim into opsim
Nikki1510 Aug 9, 2024
9ddc2f0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 9, 2024
ecd8795
Merge branch 'LSST-strong-lensing:main' into opsim
Nikki1510 Aug 29, 2024
5760e13
Merge remote-tracking branch 'slsim-project/main' into opsim
Nikki1510 Aug 29, 2024
d3472cf
Merge branch 'opsim' of github.com:Nikki1510/slsim into opsim
Nikki1510 Aug 29, 2024
47372da
changed file structure
Nikki1510 Aug 30, 2024
f5aabc8
expanded test function for create_image_montage_from_image_list
Nikki1510 Aug 30, 2024
b43ca7b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 30, 2024
78e5be6
fixed imports
Nikki1510 Aug 30, 2024
67fd972
Merge branch 'opsim' of github.com:Nikki1510/slsim into opsim
Nikki1510 Aug 30, 2024
0ec3b18
Merge remote-tracking branch 'slsim-project/main' into opsim
Nikki1510 Sep 10, 2024
2c1f7b8
fixed paths to TestData
Nikki1510 Sep 10, 2024
e681c54
changed notebook to match new version of slsim
Nikki1510 Sep 24, 2024
f4fb12f
made test functions for opsim
Nikki1510 Sep 24, 2024
410ca0e
ran notebook again
Nikki1510 Sep 24, 2024
4b8b623
added test file for opsim data
Nikki1510 Sep 24, 2024
ea4a817
replaced pickle file by hdf5
Nikki1510 Sep 24, 2024
dbf9d45
Merge remote-tracking branch 'slsim-project/main' into opsim
Nikki1510 Sep 24, 2024
c444a1e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 24, 2024
9109127
removed unused imports
Nikki1510 Sep 24, 2024
1c849b5
Merge branch 'opsim' of github.com:Nikki1510/slsim into opsim
Nikki1510 Sep 24, 2024
816dcb5
updated opsim functions
Nikki1510 Sep 24, 2024
3a23c62
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 24, 2024
7bf3ffa
debugged test functions
Nikki1510 Sep 24, 2024
ffe6712
Merge branch 'opsim' of github.com:Nikki1510/slsim into opsim
Nikki1510 Sep 24, 2024
33f9d4f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 24, 2024
c2e89e7
Merge branch 'LSST-strong-lensing:main' into opsim
Nikki1510 Oct 8, 2024
57636d9
Merge remote-tracking branch 'slsim-project/main' into opsim
Nikki1510 Oct 8, 2024
408239f
Merge branch 'opsim' of github.com:Nikki1510/slsim into opsim
Nikki1510 Oct 8, 2024
c8e05fa
added opsimsummaryv2 in test_requirements.txt
Nikki1510 Oct 8, 2024
3e5c936
changed path definition
Nikki1510 Oct 8, 2024
85e1754
changed python-version to 3.9 to be compatible with opsimsummaryv2
Nikki1510 Oct 8, 2024
164d7b0
changed function test_opsim_time_series_images_data() to only run if …
Nikki1510 Oct 8, 2024
fc42941
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 8, 2024
c791ceb
Merge branch 'LSST-strong-lensing:main' into opsim
Nikki1510 Oct 20, 2024
5336058
Merge remote-tracking branch 'slsim-project/main' into opsim
Nikki1510 Oct 20, 2024
d52d40e
Merge branch 'opsim' of github.com:Nikki1510/slsim into opsim
Nikki1510 Oct 20, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
python-version: [3.9]

steps:
- uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST
data/OpSim_database/
data/Scotch/
data/SALT3.NIR_WAVEEXT/

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
627 changes: 627 additions & 0 deletions notebooks/Opsim_supernovae_plus_extended_source_tutorial.ipynb

Large diffs are not rendered by default.

219 changes: 219 additions & 0 deletions slsim/LsstSciencePipeline/opsim_pipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
import numpy as np
from astropy.table import Table
from astropy.table import Column
from slsim.image_simulation import lens_image
import lenstronomy.Util.util as util
import lenstronomy.Util.kernel_util as kernel_util
import lenstronomy.Util.data_util as data_util


def opsim_time_series_images_data(
ra_list,
dec_list,
obs_strategy,
MJD_min=60000,
MJD_max=64000,
size=101,
moffat_beta=3.1,
readout_noise=10,
delta_pix=0.2,
print_warning=True,
opsim_path=None,
):
"""Creates time series data from opsim database.

:param ra_list: a list of ra points (in degrees) from objects we want to collect
observations for
:param dec_list: a list of dec points (in degrees) from objects we want to collect
observations for
:param obs_strategy: version of observing strategy corresponding to opsim database.
for example "baseline_v3.0_10yrs" (string)
:param MJD_min: minimum MJD for the observations
:param MJD_max: maximum MJD for the observations
:param size: cutout size of images (in pixels)
:param moffat_beta: power index of the moffat psf kernel
:param readout_noise: noise added per readout
:param delta_pix: size of pixel in units arcseonds
:param print_warning: if True, prints a warning of coordinates outside of the LSST
footprint
:param opsim_path: optional: provide a path to the opsim database.
if None: use "../data/OpSim_database/" + obs_strategy + ".db" as default path.
:return: a list of astropy tables containing observation information for each
coordinate
"""

# Import OpSimSummaryV2
try:
import opsimsummaryv2 as op

Check warning on line 47 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L46-L47

Added lines #L46 - L47 were not covered by tests
except ImportError:
raise ImportError(
"Users need to have OpSimSummaryV2 installed (https://github.com/bastiencarreres/OpSimSummaryV2)"
)

# Initialise OpSimSummaryV2 with opsim database
if opsim_path is None:
opsim_path = "../data/OpSim_database/" + obs_strategy + ".db"
try:
OpSimSurv = op.OpSimSurvey(opsim_path)
except FileNotFoundError:
raise FileNotFoundError(

Check warning on line 59 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L54-L59

Added lines #L54 - L59 were not covered by tests
"File not found: "
+ opsim_path
+ ". Input variable 'obs_strategy' should correspond to the name of an opsim database saved in the folder ../data/OpSim_database"
)

# Collect observations that cover the coordinates in ra_list and dec_list
gen = OpSimSurv.get_obs_from_coords(

Check warning on line 66 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L66

Added line #L66 was not covered by tests
ra_list,
dec_list,
is_deg=True,
formatobs=True,
keep_keys=["visitExposureTime", "seeingFwhmGeom", "fieldRA", "fieldDec"],
)

table_data_list = []

Check warning on line 74 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L74

Added line #L74 was not covered by tests

# Loop through all coordinates and compute the table_data
for i in range(len(ra_list)):

Check warning on line 77 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L77

Added line #L77 was not covered by tests

# Collect the next observation sequence from the opsim generator
seq = next(gen)
seq = seq.sort_values(by=["expMJD"])

Check warning on line 81 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L80-L81

Added lines #L80 - L81 were not covered by tests

# Check if the coordinates are in the opsim LSST footprint
opsim_ra = np.mean(seq["fieldRA"])
opsim_dec = np.mean(seq["fieldDec"])

Check warning on line 85 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L84-L85

Added lines #L84 - L85 were not covered by tests

if np.isnan(opsim_ra) or np.isnan(opsim_dec):
if print_warning:
print(

Check warning on line 89 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L87-L89

Added lines #L87 - L89 were not covered by tests
f"Coordinate ({ra_list[i]}, {dec_list[i]}) is not in the LSST footprint. This entry is skipped."
)
continue

Check warning on line 92 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L92

Added line #L92 was not covered by tests

# Get the relevant properties from opsim
obs_time = np.array(seq["expMJD"])

Check warning on line 95 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L95

Added line #L95 was not covered by tests

# Only give the observations between MJD_min and MJD_max
mask = (obs_time > MJD_min) & (obs_time < MJD_max)
obs_time = obs_time[mask]

Check warning on line 99 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L98-L99

Added lines #L98 - L99 were not covered by tests

expo_time = np.array(seq["visitExposureTime"])[mask]
bandpass = np.array(seq["BAND"])[mask]
zero_point_mag = np.array(seq["ZPT"])[mask]
sky_brightness = np.array(seq["SKYSIG"])[mask] ** 2 / (delta_pix**2 * expo_time)
psf_fwhm = np.array(seq["seeingFwhmGeom"])[mask]

Check warning on line 105 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L101-L105

Added lines #L101 - L105 were not covered by tests
# Question: use 'FWHMeff' or 'seeingFwhmGeom' for the psf?

radec_list = [(ra_list[i], dec_list[i])] * len(obs_time)

Check warning on line 108 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L108

Added line #L108 was not covered by tests

# Create a Moffat psf kernel for each epoch

psf_kernels = []

Check warning on line 112 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L112

Added line #L112 was not covered by tests

for psf in psf_fwhm:
psf_kernel = kernel_util.kernel_moffat(

Check warning on line 115 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L114-L115

Added lines #L114 - L115 were not covered by tests
num_pix=size, delta_pix=delta_pix, fwhm=psf, moffat_beta=moffat_beta
)
psf_kernel = util.array2image(psf_kernel)

Check warning on line 118 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L118

Added line #L118 was not covered by tests

psf_kernels.append(psf_kernel)

Check warning on line 120 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L120

Added line #L120 was not covered by tests

psf_kernels = np.array(psf_kernels)

Check warning on line 122 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L122

Added line #L122 was not covered by tests

# Calculate background noise
bkg_noise = data_util.bkg_noise(

Check warning on line 125 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L125

Added line #L125 was not covered by tests
readout_noise, expo_time, sky_brightness, delta_pix, num_exposures=1
)

table_data = Table(

Check warning on line 129 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L129

Added line #L129 was not covered by tests
[
bkg_noise,
psf_kernels,
obs_time,
expo_time,
zero_point_mag,
radec_list,
bandpass,
],
names=(
"bkg_noise",
"psf_kernel",
"obs_time",
"expo_time",
"zero_point",
"calexp_center",
"band",
),
)

table_data_list.append(table_data)
return table_data_list

Check warning on line 151 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L150-L151

Added lines #L150 - L151 were not covered by tests


def opsim_variable_lens_injection(
lens_class, bands, num_pix, transform_pix2angle, exposure_data
):
"""Injects variable lens to the OpSim time series data (1 object).

:param lens_class: Lens() object
:param bands: list of imaging bands of interest
:param num_pix: number of pixels per axis
:param transform_pix2angle: transformation matrix (2x2) of pixels into coordinate
displacements
:param exposure_data: An astropy table of exposure data. One entry of
table_list_data generated from the opsim_time_series_images_data function. It
must contain the rms of background noise fluctuations (column name should be
"bkg_noise"), psf kernel for each exposure (column name should be "psf_kernel",
these are pixel psf kernel for each single exposure images in time series
image), observation time (column name should be "obs_time", these are
observation time in days for each single exposure images in time series images),
exposure time (column name should be "expo_time", these are exposure time for
each single exposure images in time series images), magnitude zero point (column
name should be "zero_point", these are zero point magnitudes for each single
exposure images in time series image), coordinates of the object (column name
should be "calexp_center"), these are the coordinates in (ra, dec), and the band
in which the observation is taken (column name should be "band").
:return: Astropy table of injected lenses and exposure information of dp0 data
"""

final_image = []

for obs in range(len(exposure_data["obs_time"])):

exposure_data_obs = exposure_data[obs]

if exposure_data_obs["band"] not in bands:
continue

if "bkg_noise" in exposure_data_obs.keys():
std_gaussian_noise = exposure_data_obs["bkg_noise"]
else:
std_gaussian_noise = None

Check warning on line 192 in slsim/LsstSciencePipeline/opsim_pipeline.py

View check run for this annotation

Codecov / codecov/patch

slsim/LsstSciencePipeline/opsim_pipeline.py#L192

Added line #L192 was not covered by tests

lens_images = lens_image(
lens_class,
band=exposure_data_obs["band"],
mag_zero_point=exposure_data_obs["zero_point"],
num_pix=num_pix,
psf_kernel=exposure_data_obs["psf_kernel"],
transform_pix2angle=transform_pix2angle,
exposure_time=exposure_data_obs["expo_time"],
t_obs=exposure_data_obs["obs_time"],
std_gaussian_noise=std_gaussian_noise,
)

final_image.append(lens_images)

lens_col = Column(name="lens", data=final_image)
final_image_col = Column(name="injected_lens", data=final_image)

# Create a new Table with only the bands of interest
expo_bands = np.array([b for b in exposure_data["band"]])
mask = np.isin(expo_bands, bands)
exposure_data_new = exposure_data[mask]

# if len(exposure_data_new) > 0:
exposure_data_new.add_columns([lens_col, final_image_col])

return exposure_data_new
25 changes: 24 additions & 1 deletion slsim/Plots/plot_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@


def create_image_montage_from_image_list(
num_rows, num_cols, images, time=None, image_type="other", image_center=None
num_rows,
num_cols,
images,
time=None,
band=None,
image_type="other",
image_center=None,
):
"""Creates an image montage from an image list.

Expand All @@ -16,6 +22,8 @@ def create_image_montage_from_image_list(
:param images: list of images
:param time: array of observation time for point source images. If None, considers
static case.
:param band: array of bands corresponding to the observations. If None, does not
display any information regarding the band.
:param image_type: type of the provided image. It could be 'dp0' or any other name.
:param image_center: center of the source images.
:type image_center: array. eg: for two image, it should be like
Expand All @@ -32,6 +40,10 @@ def create_image_montage_from_image_list(
global_min = min(all_min)
global_max = max(all_max)

# If band is one string, extend to list
if isinstance(band, str):
band = [band] * len(images)

fig, axes = plt.subplots(num_rows, num_cols, figsize=(num_cols * 3, num_rows * 3))

for i in range(num_rows):
Expand Down Expand Up @@ -61,6 +73,17 @@ def create_image_montage_from_image_list(
horizontalalignment="left",
transform=axes[i, j].transAxes,
)
if band is not None:
axes[i, j].text(
0.05,
0.10,
f"Band: {band[i * num_cols + j]}",
fontsize=10,
color="white",
verticalalignment="top",
horizontalalignment="left",
transform=axes[i, j].transAxes,
)
if image_center is not None:
for k in range(len(image_center)):
axes[i, j].scatter(
Expand Down
16 changes: 11 additions & 5 deletions slsim/image_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,9 @@ def lens_image_series(
to simulate time series images of a lens.

:param lens_class: Lens() object
:param band: imaging band
:param mag_zero_point: list of magnitude zero point for sqeuence of exposure
:param band: imaging band (or list of bands).
if float: assumed to apply to the full image series.
:param mag_zero_point: list of magnitude zero point for sequence of exposure
:param num_pix: number of pixels per axis
:param psf_kernels: list of psf kernel for each exposure.
:param transform_pix2angle: list of transformation matrix (2x2) of pixels into
Expand All @@ -621,13 +622,18 @@ def lens_image_series(
:param with_deflector: If True, simulates image with deflector.
:return: list of series of images of a lens
"""

# If band is one string, extend to list
if isinstance(band, str):
band = [band] * len(mag_zero_point)

image_series = []
for time, psf_kern, mag_zero, transf_matrix, expo_time in zip(
t_obs, psf_kernel, mag_zero_point, transform_pix2angle, exposure_time
for time, psf_kern, mag_zero, transf_matrix, expo_time, band_obs in zip(
t_obs, psf_kernel, mag_zero_point, transform_pix2angle, exposure_time, band
):
image = lens_image(
lens_class=lens_class,
band=band,
band=band_obs,
mag_zero_point=mag_zero,
num_pix=num_pix,
psf_kernel=psf_kern,
Expand Down
1 change: 1 addition & 0 deletions test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# git+https://github.com/aymgal/coolest@main#egg=coolest
git+https://github.com/LSSTDESC/OpSimSummaryV2
coolest==0.1.8
galsim
Binary file added tests/TestData/expo_data_opsim.hdf5
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from astropy.table import Table
from astropy.cosmology import FlatLambdaCDM
from slsim.lens import Lens
from slsim.lsst_science_pipeline import (
from slsim.LsstSciencePipeline.lsst_science_pipeline import (
variable_lens_injection,
multiple_variable_lens_injection,
)
Expand All @@ -14,10 +14,10 @@
def pes_lens_instance():
path = os.path.dirname(__file__)
source_dict = Table.read(
os.path.join(path, "TestData/source_dict_ps.fits"), format="fits"
os.path.join(path, "../TestData/source_dict_ps.fits"), format="fits"
)
deflector_dict = Table.read(
os.path.join(path, "TestData/deflector_dict_ps.fits"), format="fits"
os.path.join(path, "../TestData/deflector_dict_ps.fits"), format="fits"
)

cosmo = FlatLambdaCDM(H0=70, Om0=0.3)
Expand All @@ -41,7 +41,7 @@ def test_variable_lens_injection(pes_lens_instance):
lens_class = pes_lens_instance
path = os.path.dirname(__file__)
expo_data = Table.read(
os.path.join(path, "TestData/expo_data_1.fits"), format="fits"
os.path.join(path, "../TestData/expo_data_1.fits"), format="fits"
)
transf_matrix_single = np.array([[0.2, 0], [0, 0.2]])
transform_matrices = [transf_matrix_single.copy() for _ in range(len(expo_data))]
Expand All @@ -59,10 +59,10 @@ def test_multiple_variable_lens_injection(pes_lens_instance):
lens_class = [pes_lens_instance, pes_lens_instance]
path = os.path.dirname(__file__)
expo_data_1 = Table.read(
os.path.join(path, "TestData/expo_data_1.fits"), format="fits"
os.path.join(path, "../TestData/expo_data_1.fits"), format="fits"
)
expo_data_2 = Table.read(
os.path.join(path, "TestData/expo_data_2.fits"), format="fits"
os.path.join(path, "../TestData/expo_data_2.fits"), format="fits"
)
expo_data = [expo_data_1, expo_data_2]
transf_matrix_single = np.array([[0.2, 0], [0, 0.2]])
Expand Down
Loading
Loading