LSSTDESC / imSim

GalSim based Rubin Observatory image simulation package
https://lsstdesc.org/imSim
BSD 3-Clause "New" or "Revised" License
37 stars 15 forks source link

Telescope doesn't load when nproc>1 #321

Closed jmeyers314 closed 1 year ago

jmeyers314 commented 1 year ago

I think this is a bug with the InputProxy stuff for the telescope loader, but haven't been able to pinpoint the problem yet. (In particular, I'm not sure if the problem is GalSim or ImSim).

Arises with the following wavefront sensor donut config. This works fine when output.nproc=1, but not when output.nproc=2.

modules:
  - imsim
  - astropy
  - astropy.time

eval_variables:
  cboresight:
    type: RADec
    ra: 0 deg
    dec: 0 deg
  sband: &band r

input:
  telescope:
    file_name: LSST_r.yaml
    perturbations:
      M2:
        shift: [3e-3, 0, 0]

  atm_psf:
    airmass: 1.1
    rawSeeing:  0.5
    band:  *band
    boresight: $boresight

    # Optional parameters:  (Unless otherwise stated, these are the default values.)
    t0: 0               # seconds
    exptime: 30.0
    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_scale: 0.1   # meters
    doOpt: False

image:
  type: Scattered
  xsize: $xsize  # $xsize is populated by output.LSST_CCD.  Could this automatically apply to Scattered.xsize?
  ysize: $ysize
  nobjects: 4
  image_pos: $image_center  # Draw one donut at the center of each WFS CCD

  bandpass:
    file_name:
      type: FormattedStr
      format: LSST_%s.dat
      items:
        - *band
    wave_type: nm
  stamp_size: 3000

  wcs:
    type: Batoid
    camera: "@output.camera"
    boresight: $boresight
    obstime:  # Tried placing this in `eval_variables`, wouldn't work.
      type: Eval
      str: astropy.time.Time('J2022')  # makes ra=dec=0 appear at ~45 zenith angle
    det_name: $det_name
    # band: *band

  noise:
      type: CCD
      gain: 1
      read_noise: 0  # The read noise is applied later.  Only sky noise here.
  random_seed: 57721

gal:
  type: DeltaFunction
  sed:
    file_name: vega.txt
    wave_type: nm
    flux_type: flambda
    # norm_flux_density: 1.65e5
    norm_flux_density: 1.65e4
    norm_wavelength: 500

psf:
  type: Gaussian
  fwhm: 0.7

stamp:
  draw_method: phot
  photon_ops:
    -
      type: PupilAnnulusSampler
      R_inner: 2.5
      R_outer: 4.18
    -
      type: TimeSampler
    -
      type: lsst_optics
      camera: "@output.camera"
      boresight: $boresight
  image_pos:
    - $image_center + PositionD(0, 200)
    - $image_center + PositionD(0, 100)
    - $image_center + PositionD(0, 0)
    - $image_center + PositionD(100, 0)

output:
  type: LSST_CCD
  nproc: 2    # Change this to work on multiple CCDs at once.
  nfiles: 8   # WFS files

  camera: LsstCam

  exp_time: 30

  cosmic_ray_rate: 0.0

  det_num:
    type: List
    items: [191, 192, 195, 196, 199, 200, 203, 204]  # WF sensors

  dir: wfs_output
  file_name:
    type: FormattedStr
    format : raw_%08d-%1d-%s-%s-det%03d.fits
    items:
      - 99999999
      - 0
      - r
      - $det_name   # A value stored in the dict by LSST_CCD
      - "@output.det_num"
jchiang87 commented 1 year ago

I think I'm seeing the same thing using a fairly generic config. Here's one I've been using to make darks:

gal.type: SkyCatObj
image.nobjects: 0
image.random_seed: 42
image.sky_level: 0
input.atm_psf: ''
psf.items: ""
psf.type: Gaussian
psf.fwhm: 0.7
input.instance_catalog: ''
input.opsim_meta_dict.file_name: /home/jchiang/work/DESC/imSim/tests/data/small_opsim_9683.db
input.opsim_meta_dict.visit: 11873
input.sky_catalog: ""
input.tree_rings.only_dets:
- R22_S11
- R22_S12
modules:
- imsim
output.camera: LsstCam
output.det_num.first: 0
output.dir: dark_frames
output.exp_time: 300
output.file_name:
  format: eimage_%s-%03d-%s.fits
  items:
  - dark
  - 0
  - $det_name
  type: FormattedStr
output.nfiles: 2
output.nproc: 2
output.only_dets:
- R22_S11
- R22_S12
output.readout.file_name:
  format: amp_%s-%03d-%s.fits.fz
  items:
  - dark
  - 0
  - $det_name
  type: FormattedStr
output.timeout: 100000.0
output.truth: ''
stamp.world_pos.type: SkyCatWorldPos
stamp.fft_sb_thresh: 1e5
stamp.size: 40
template: imsim-config

and here's the error output:

Process-1: Exception caught for file 0 = dark_frames/eimage_dark-000-R22_S11.fits
Traceback (most recent call last):
  File "/opt/lsst/software/stack/conda/miniconda3-py38_4.9.2/envs/lsst-scipipe-5.1.0/lib/python3.10/site-packages/galsim/config/util.py", line 732, in worker
    result = job_func(**kwargs)
  File "/opt/lsst/software/stack/conda/miniconda3-py38_4.9.2/envs/lsst-scipipe-5.1.0/lib/python3.10/site-packages/galsim/config/output.py", line 248, in BuildFile
    data = builder.buildImages(output, config, file_num, image_num, obj_num, ignore, logger)
  File "/home/jchiang/work/DESC/imSim/imsim/ccd.py", line 101, in buildImages
    image = galsim.config.BuildImage(base, image_num, obj_num, logger=logger)
  File "/opt/lsst/software/stack/conda/miniconda3-py38_4.9.2/envs/lsst-scipipe-5.1.0/lib/python3.10/site-packages/galsim/config/image.py", line 265, in BuildImage
    SetupConfigImageSize(config, xsize, ysize, logger)
  File "/opt/lsst/software/stack/conda/miniconda3-py38_4.9.2/envs/lsst-scipipe-5.1.0/lib/python3.10/site-packages/galsim/config/image.py", line 212, in SetupConfigImageSize
    wcs = BuildWCS(image, 'wcs', config, logger)
  File "/opt/lsst/software/stack/conda/miniconda3-py38_4.9.2/envs/lsst-scipipe-5.1.0/lib/python3.10/site-packages/galsim/config/wcs.py", line 103, in BuildWCS
    wcs = builder.buildWCS(param, base, logger)
  File "/home/jchiang/work/DESC/imSim/imsim/batoid_wcs.py", line 498, in buildWCS
    kwargs['telescope'] = GetInputObj('telescope', config, base, 'telescope')['base']
TypeError: 'load_telescope_dict_Proxy' object is not subscriptable