Skip to content

Commit

Permalink
Merge pull request #422 from LSSTDESC/u/cwalter/update_screen_memory
Browse files Browse the repository at this point in the history
Update the memory used by the atmospheric screen.

Because of an error we were trying to fix in the CI, this PR also wound up modifying the CI to use conda for rubin_sim and updating the bandpasses to 1.9.
  • Loading branch information
cwwalter authored Sep 28, 2023
2 parents aaa44cf + 15b73d9 commit fe7d976
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 31 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
conda install -y mamba
mamba install -y --file etc/standalone_conda_requirements.txt
conda info
conda list
mamba list
- name: Install skyCatalogs from source
run: |
Expand All @@ -56,18 +56,14 @@ jobs:
- name: Install rubin_sim and rubin_sim_data
run: |
# Do the minimal installation from source to avoid installing
# a bunch of unneeded packages.
git clone https://github.com/lsst/rubin_sim.git
cd rubin_sim
git checkout 1.1.1
pip install -e .
cd ..
# Install a fixed version so we control the code for tests etc.
mamba install rubin-sim=1.1.1
#
mkdir rubin_sim_data
mkdir rubin_sim_data/sims_sed_library
# Just get the skybrightness, throughputs, and SED data for now.
curl https://s3df.slac.stanford.edu/groups/rubin/static/sim-data/rubin_sim_data/skybrightness_may_2021.tgz | tar -C rubin_sim_data -xz
curl https://s3df.slac.stanford.edu/groups/rubin/static/sim-data/rubin_sim_data/throughputs_aug_2021.tgz | tar -C rubin_sim_data -xz
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
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
- name: Install imSim
Expand Down
2 changes: 1 addition & 1 deletion config/imsim-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ input:
t0: 0 # seconds
exptime: $exptime
kcrit: 0.2 # in units of 1/r0
screen_size: 409.6 # Default=812.2, which takes a lot of memory, so use this for testing.
screen_size: 819.2 # To use less memory for testing/development, you can try 409.6
screen_scale: 0.1 # meters
doOpt: False
nproc: 1 # Default (None) means one proc per screen.
Expand Down
1 change: 1 addition & 0 deletions imsim/bandpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def RubinBandpass(band, logger=None):
logger.warning("Warning: Using the old bandpass files from GalSim, not lsst.sims")
file_name = f"LSST_{band}.dat"
bp = galsim.Bandpass(file_name, wave_type='nm')
bp = bp.truncate(relative_throughput=1.e-3)
bp = bp.thin()
bp = bp.withZeropoint('AB')
return bp
Expand Down
2 changes: 1 addition & 1 deletion tests/data/reference_sky_levels.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"u": 940.8063879564563, "g": 8041.5851235691625, "r": 16237.67541651461, "i": 28067.137304469303, "z": 47780.00064197293, "y": 46624.55973988414}
{"u": 966.8740383242452, "g": 9565.16844049534, "r": 20335.64330578381, "i": 39770.05348346839, "z": 66820.68250072759, "y": 62387.30799288845}
7 changes: 4 additions & 3 deletions tests/sky_level_reference_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import galsim
from rubin_sim import skybrightness
import imsim


RUBIN_AREA = 0.25 * np.pi * 649**2 # cm^2
Expand All @@ -19,12 +20,12 @@
sky_model = skybrightness.SkyModel()
with warnings.catch_warnings():
warnings.simplefilter('ignore')
sky_model.setRaDecMjd(ra, dec, mjd, degrees=True)
sky_model.set_ra_dec_mjd(ra, dec, mjd, degrees=True)

sky_levels = {}
for band in 'ugrizy':
bandpass = galsim.RubinBandpass(band)
wave, spec = sky_model.returnWaveSpec()
bandpass = imsim.RubinBandpass(band)
wave, spec = sky_model.return_wave_spec()
lut = galsim.LookupTable(wave, spec[0])
sed = galsim.SED(lut, wave_type='nm', flux_type='flambda')
sky_levels[band] = sed.calculateFlux(bandpass)*RUBIN_AREA*exptime
Expand Down
37 changes: 30 additions & 7 deletions tests/test_bandpass.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import numpy as np
import galsim
from imsim import RubinBandpass
from unittest import mock
from imsim_test_helpers import CaptureLog

def test_rubin_bandpass():
"""Check the RubinBandpass functions to check that they are similar to GalSim lsst_*.dat files.
Expand All @@ -11,14 +13,35 @@ def test_rubin_bandpass():
print(f'Band = {band}')
print('Rubin_bp: ',rubin_bp.blue_limit, rubin_bp.effective_wavelength, rubin_bp.red_limit)
print('galsim_bp: ',galsim_bp.blue_limit, galsim_bp.effective_wavelength, galsim_bp.red_limit)
# These are quite close. The only exception is the blue_limit of the u band, where the
# old GalSim bandpass is too red.
if band == 'u':
assert np.isclose(rubin_bp.blue_limit, galsim_bp.blue_limit, atol=20)
#print('Rubin_bp: ',repr(rubin_bp))

# These are reasonably close. Especially in the effective wavelength.
# The limits of the actual filters are a bit different in some cases though from what was
# estimated many years ago. Especially for u and y bands.
if band in 'uy':
assert np.isclose(rubin_bp.blue_limit, galsim_bp.blue_limit, atol=30)
assert np.isclose(rubin_bp.red_limit, galsim_bp.red_limit, atol=10)
assert np.isclose(rubin_bp.effective_wavelength, galsim_bp.effective_wavelength, atol=5)
else:
assert np.isclose(rubin_bp.blue_limit, galsim_bp.blue_limit, atol=1)
assert np.isclose(rubin_bp.red_limit, galsim_bp.red_limit, atol=1)
assert np.isclose(rubin_bp.effective_wavelength, galsim_bp.effective_wavelength, atol=3)
assert np.isclose(rubin_bp.blue_limit, galsim_bp.blue_limit, atol=15)
assert np.isclose(rubin_bp.red_limit, galsim_bp.red_limit, atol=8)
assert np.isclose(rubin_bp.effective_wavelength, galsim_bp.effective_wavelength, atol=3)


# If RUBIN_SIM_DATA isn't availble, then RubinBandpass reverts to the galsim files,
# and everything should match exactly.
with mock.patch('os.getenv', return_value=''):
with CaptureLog() as cl:
alt_rubin_bp = RubinBandpass(band, logger=cl.logger)
assert "Using the old bandpass files" in cl.output
print('Alt_Rubin_bp: ',alt_rubin_bp.blue_limit, alt_rubin_bp.effective_wavelength,
alt_rubin_bp.red_limit)
galsim_bp = galsim.Bandpass(f"LSST_{band}.dat", wave_type='nm')
galsim_bp = galsim_bp.truncate(relative_throughput=1.e-3)
galsim_bp = galsim_bp.thin()
galsim_bp = galsim_bp.withZeropoint('AB')
assert alt_rubin_bp == galsim_bp



if __name__ == "__main__":
Expand Down
12 changes: 2 additions & 10 deletions tests/test_sky_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import logging
import galsim
from imsim import SkyModel, SkyGradient, make_batoid_wcs, RubinBandpass
from unittest import mock
from imsim_test_helpers import CaptureLog

DATA_DIR = Path(__file__).parent / 'data'

Expand All @@ -32,12 +30,7 @@ def test_sky_model():
expected_sky_levels = json.load(fobj)

for band in 'ugrizy':
# This regression test used the GalSim bandpasses.
# So use them here by mocking that RUBIN_DATA_DIR is not defined.
with mock.patch('os.getenv', return_value=''):
with CaptureLog() as cl:
bandpass = RubinBandpass(band, logger=cl.logger)
assert "Using the old bandpass files" in cl.output
bandpass = RubinBandpass(band)
sky_model = SkyModel(exptime, mjd, bandpass)
sky_level = sky_model.get_sky_level(skyCoord)
np.testing.assert_approx_equal(sky_level, expected_sky_levels[band],
Expand All @@ -50,7 +43,6 @@ def test_sky_gradient():
# http://astro-lsst-01.astro.washington.edu:8080/
ra = 54.9348753510528
dec = -35.8385705255579
skyCoord = galsim.CelestialCoord(ra*galsim.degrees, dec*galsim.degrees)
mjd = 60232.3635999295
rottelpos = 350.946271812373
exptime = 30.
Expand Down Expand Up @@ -91,7 +83,6 @@ def test_sky_gradient():
sky_gradient(*r[:2]),
significant=4)


# Check that it gets applied by LSST_Image
config = {
'input': {
Expand Down Expand Up @@ -126,6 +117,7 @@ def test_sky_gradient():
image2 = galsim.config.BuildImage(config, logger=logger)
assert image2 == image


if __name__ == "__main__":
testfns = [v for k, v in vars().items() if k[:5] == 'test_' and callable(v)]
for testfn in testfns:
Expand Down

0 comments on commit fe7d976

Please sign in to comment.