Skip to content

Commit

Permalink
Merge branch 'main' into centers
Browse files Browse the repository at this point in the history
  • Loading branch information
rmjarvis authored Jun 6, 2024
2 parents 5edf1df + 25f868b commit 07fd55c
Show file tree
Hide file tree
Showing 38 changed files with 1,471 additions and 667 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
ignore = N802,N806,E226,N803,W503,W504,E231,E129,E302,E201,E202,E501
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.fits binary
*.fits.fz binary
*.fits.gz binary
18 changes: 14 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,21 @@ jobs:
run: |
git clone https://github.com/LSSTDESC/skyCatalogs.git
cd skyCatalogs
git checkout v1.6.0rc2
pip install -e .
git checkout v1.7.0rc4
# fix bug specifying version
sed -i.bak 's/\.skycatalogs/skycatalogs/' pyproject.toml
pip install --no-build-isolation --no-deps -e .
cd ..
- name: Cache data
id: cache-data
uses: actions/cache@v4
with:
path: rubin_sim_data
key: "2024-05-10" # Update the key if we ever change the data.

- name: Install rubin_sim_data
if: steps.cache-data.outputs.cache-hit != 'true'
run: |
mkdir rubin_sim_data
mkdir rubin_sim_data/sims_sed_library
Expand All @@ -69,14 +79,14 @@ jobs:

- name: Install test deps
run:
conda install -y pytest nose || true
conda install -y pytest nose pytest-durations pytest-xdist || true

- name: Run tests
run: |
export RUBIN_SIM_DATA_DIR=`pwd`/rubin_sim_data
eups list lsst_distrib
galsim --version
pytest
pytest --durations=10 -n auto
- name: Check example config files
run: |
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN sed '/stackvana/d' imSim/etc/standalone_conda_requirements.txt > imSim/etc/d
RUN source /opt/lsst/software/stack/loadLSST.bash &&\
setup lsst_distrib &&\
mamba install -y --file imSim/etc/docker_conda_requirements.txt &&\
python3 -m pip install batoid skyCatalogs==1.6.0-rc2 gitpython &&\
python3 -m pip install batoid skyCatalogs==1.7.0-rc4 gitpython &&\
python3 -m pip install rubin_sim/ &&\
python3 -m pip install imSim/

Expand All @@ -33,7 +33,7 @@ WORKDIR /opt/lsst/software/stack
# Download Rubin Sim data.
RUN mkdir -p rubin_sim_data/sims_sed_library
RUN curl https://s3df.slac.stanford.edu/groups/rubin/static/sim-data/rubin_sim_data/skybrightness_may_2021.tgz | tar -C rubin_sim_data -xz
RUN curl https://s3df.slac.stanford.edu/groups/rubin/static/sim-data/rubin_sim_data/throughputs_aug_2021.tgz | tar -C rubin_sim_data -xz
RUN curl https://s3df.slac.stanford.edu/groups/rubin/static/sim-data/rubin_sim_data/throughputs_2023_09_07.tgz | tar -C rubin_sim_data -xz
RUN curl https://s3df.slac.stanford.edu/groups/rubin/static/sim-data/sed_library/seds_170124.tar.gz | tar -C rubin_sim_data/sims_sed_library -xz

# Set location of Rubin sim data (downloaded in step above).
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[<img src="https://img.shields.io/badge/dockerhub-imSim image-orange.svg?logo=Docker">](https://hub.docker.com/r/lsstdesc/imsim-env)
[![Build Status](https://travis-ci.org/LSSTDESC/imSim.svg?branch=main)](https://travis-ci.org/LSSTDESC/imSim)
[![Coverage Status](https://coveralls.io/repos/github/LSSTDESC/imSim/badge.svg?branch=main)](https://coveralls.io/github/LSSTDESC/imSim?branch=main)
[![Build Status](https://github.com/LSSTDESC/imSim/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/LSSTDESC/imSim/actions/workflows/ci.yml/badge.svg?branch=main)

# imSim
imSim is a software package that simulates the LSST telescope and survey.
Expand Down
1 change: 1 addition & 0 deletions config/imsim-config-instcat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ input.instance_catalog:
# This should be overridden below or on the command line.
file_name: default_catalog_file.txt
sed_dir: $os.environ.get('SIMS_SED_LIBRARY_DIR')
pupil_area: $pupil_area

input.opsim_data:
# Read the visit meta data. By default, we use the same file as the above
Expand Down
1 change: 1 addition & 0 deletions config/imsim-config-skycat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ input.sky_catalog:
file_name: default_sky_cat.yaml
band: $band
mjd: { type: OpsimData, field: mjd }
pupil_area: $pupil_area

input.opsim_data:
file_name: default_opsim.db
Expand Down
11 changes: 9 additions & 2 deletions config/imsim-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ eval_variables:
type: Degrees
theta: { type: OpsimData, field: rotTelPos }

fpupil_R_outer: 4.18
fpupil_R_inner: 2.55 # M1 inner diameter is 2.558, but we need a bit of slack for off-axis rays
fpupil_area:
type: Eval
str: "np.pi * (pupil_R_outer**2 - pupil_R_inner**2) * 100**2"

sband: { type: OpsimData, field: band }

fexptime: { type: OpsimData, field: exptime }
Expand Down Expand Up @@ -75,6 +81,7 @@ input:
# background level.
exptime: $exptime
mjd: { type: OpsimData, field: mjd }
pupil_area: $pupil_area

atm_psf:
# This enables the AtmosphericPSF type for the PSF
Expand Down Expand Up @@ -260,8 +267,8 @@ stamp:
exptime: $exptime
-
type: PupilAnnulusSampler
R_outer: 4.18
R_inner: 2.55 # M1 inner diameter is 2.558, but we need a bit of slack for off-axis rays
R_outer: "$pupil_R_outer"
R_inner: "$pupil_R_inner"
-
type: PhotonDCR
base_wavelength: $bandpass.effective_wavelength
Expand Down
6 changes: 6 additions & 0 deletions data/LsstCamSim_info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tree_rings_file_name: tree_ring_parameters_2018-04-26.txt
vignetting_file_name: LSSTCam_vignetting_data.json
telescope_format: LSST_%s.yaml
bias_levels_file: LSSTCam_bias_levels_run_13421.json
camera_name: LsstCam
ndets: 189
5 changes: 4 additions & 1 deletion doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ Now we are ready to install *imSim*. First go to the directory where you would l
# Install imSim:
pip install --no-deps imSim/
pip install --no-deps skyCatalogs/
# turn off build isolation for newer pip
pip install --no-build-isolation --no-deps skyCatalogs/
Install *rubin_sim_data*
~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -180,6 +181,8 @@ Set runtime environment variables for the *Conda* environment

.. code-block:: sh
# e.g. if imSim is in ~/git/imSim you would set IMSIM_HOME to ~/git
conda env config vars set IMSIM_HOME=/path/to/imSim-git-repo
conda env config vars set RUBIN_SIM_DATA_DIR=$(pwd)/rubin_sim_data
conda env config vars set SIMS_SED_LIBRARY_DIR=$(pwd)/rubin_sim_data/sims_sed_library
Expand Down
3 changes: 3 additions & 0 deletions imsim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from ._version import *
from .meta_data import *
from .stamp import *
from . import stamp_utils
from . import psf_utils
from .instcat import *
from .opsim_data import *
from .ccd import *
Expand All @@ -36,3 +38,4 @@
from .vignetting import *
from .sag import *
from .process_info import *
from .table_row import *
9 changes: 8 additions & 1 deletion imsim/bandpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,14 @@ def RubinBandpass(
if (camera is None) != (det_name is None):
raise ValueError("Must provide both camera and det_name if using one.")
match camera:
case 'LsstCam':
case 'LsstCam' | 'LsstCamSim' :
camera = 'lsstCam'
case 'LsstComCamSim':
camera = 'comCamSim'
case _:
camera = camera
tp_path = Path(os.getenv("RUBIN_SIM_DATA_DIR")) / "throughputs"
bp_hardware = None
if airmass is None and camera is None:
file_name = tp_path / "baseline" / f"total_{band}.dat"
if not file_name.is_file():
Expand Down Expand Up @@ -183,6 +184,12 @@ def RubinBandpass(
bp = bp.truncate(relative_throughput=1.e-3)
bp = bp.thin()
bp = bp.withZeropoint('AB')
if bp_hardware is not None:
bp_hardware.truncate(relative_throughput=1.e-3)
bp_hardware.thin()
bp_hardware.withZeropoint('AB')
bp.bp_hardware = bp_hardware

return bp


Expand Down
47 changes: 44 additions & 3 deletions imsim/batoid_wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,58 @@ def obs_boresight(self):
@galsim.utilities.lazy_property
@ignore_erfa_warnings
def q(self):
"""Parallactic angle.
Should be equal to rotTelPos - rotSkyPos.
"""Parallactic angle in radians.
Position angle of zenith measured from true north through east.
"""
# Position angle of zenith measured from _observed_ North through East
aob, zob, hob, dob, rob, eo = self._ICRF_to_observed(
self.boresight.ra.rad,
self.boresight.dec.rad,
all=True
)
return erfa.hd2pa(hob, dob, self.phi)

@galsim.utilities.lazy_property
@ignore_erfa_warnings
def pq(self):
"""Pseudo parallactic angle in radians.
Position angle of zenith measured from ICRF north through east.
"""
ra = self.boresight.ra.rad
dec = self.boresight.dec.rad
aob, zob, hob, dob, rob, eo = self._ICRF_to_observed(ra, dec, all=True)

# Let's work in ra/dec. Need to find points a little bit (ICRF) north
# of and a little be +alt of the boresight.
small_angle = (10 * galsim.arcsec).rad

ddec = np.pi/2 - dec
if ddec >= small_angle:
dec_north = dec + small_angle
ra_north = ra
else:
# We're close to the north pole. Could just use the pole, but for
# continuity, we'll travel small_angle towards the pole, passing it
# in the process.
dec_north = np.pi/2 - (small_angle - ddec)
ra_north = ra + np.pi

# Now the point a little closer to zenith.
if zob >= small_angle:
z_zen = zob - small_angle
a_zen = aob
else:
# We're close to zenith. As above, flip past it.
z_zen = small_angle - zob
a_zen = aob + np.pi
ra_zen, dec_zen = self._observed_az_to_ICRF(a_zen, z_zen)

# Now compute the angle zenith - boresight - north
pq = erfa.pas(ra, dec, ra_zen, dec_zen)
pq -= erfa.pas(ra, dec, ra_north, dec_north)
return pq

@galsim.utilities.lazy_property
def _field_wcs(self):
"""WCS for converting between observed position and field angle.
Expand Down
2 changes: 1 addition & 1 deletion imsim/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def get_camera(camera='LsstCam'):
-------
lsst.afw.cameraGeom.Camera
"""
valid_cameras = ('LsstCam', 'LsstCamImSim', 'LsstComCamSim')
valid_cameras = ('LsstCam', 'LsstCamSim', 'LsstCamImSim', 'LsstComCamSim')
if camera not in valid_cameras:
raise ValueError('Invalid camera: %s', camera)
if camera not in _camera_cache:
Expand Down
10 changes: 7 additions & 3 deletions imsim/ccd.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,11 @@ def parse(item, type, default):
# Now construct the image header
image.header['MJD'] = mjd
image.header['MJD-OBS'] = mjd_obs, 'Start of exposure'
# NOTE: Should this day be the current day,
# or the day at the time of the most recent noon?
dayobs = astropy.time.Time(mjd_obs, format='mjd').strftime('%Y%m%d')
# Subtract half-day offset from mjd-obs for dayobs calculation
# following Rubin convention. See
# https://github.com/lsst/astro_metadata_translator/blob/w.2024.19/python/astro_metadata_translator/translator.py#L1065
# and Appendix A of https://docushare.lsst.org/docushare/dsweb/Get/LSE-400
dayobs = astropy.time.Time(mjd_obs - 0.5, format='mjd').strftime('%Y%m%d')
image.header['DAYOBS'] = dayobs
image.header['SEQNUM'] = seqnum
image.header['CONTRLLR'] = 'S', 'simulated data'
Expand All @@ -192,6 +194,8 @@ def parse(item, type, default):
image.header['AMSTART'] = airmass
image.header['AMEND'] = airmass # wrong, does anyone care?
image.header['FOCUSZ'] = parse('focusZ', float, 0.0)
image.header['ALTITUDE'] = parse('altitude', float, 'N/A')
image.header['AZIMUTH'] = parse('azimuth', float, 'N/A')

# If there's anything left in header_vals, add it to the header.
for k in header_vals:
Expand Down
Loading

0 comments on commit 07fd55c

Please sign in to comment.