LSSTDESC / imSim

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

Ensuring consistent yaml configs for specifying the Camera to use #452

Closed jchiang87 closed 3 months ago

jchiang87 commented 5 months ago

Currently, to switch from LsstCam to LsstComCamSim, (at least?) three entries in the yaml config need to be changed:

It would be great if all of this could be handled with a single config parameter, i.e.,

input.camera: LsstComCamSim
jmeyers314 commented 5 months ago

Looking through imsim-config.yaml, I see:

output.camera: LsstCam
output.readout.bias_levels_file: LSSTCam_bias_levels_run_13421.json
input.vignetting.file_name: LSSTCam_vignetting_data.json
input.telescope.file_name: $f"LSST_{band}.yaml"

and potentially stuff like

output.nfiles: 189 # 9 for comcam

Some ideas on how to handle:

1

In galsim-config-language something like:

input.telescope.file_name: $ f"LSST_{band}.yaml" if @output.cameraName == 'LsstCam' else f"ComCam_{band}.yaml"

though that doesn't really scale past 2 cameras (maybe that's enough?).

2

Or, in imsim-config.yaml at least, shove all the camera-dependent stuff into various eval_variables and have one section uncommented for ComCam and another for LsstCam:

eval_variables:
    sband: r
    # For LSSTCam
    scameraName: LsstCam
    sopticsFileName: LSST_{band}.yaml
    inumdet: 189
    # # For ComCam
    # scameraName: LsstComCamSim
    # sopticsFileName: ComCam_{band}.yaml
    # inumdet: 9

That keeps everything related to the camera choice localized at least.

3

Or there's the approach in https://github.com/LSSTDESC/imSim/blob/main/devel-tools/vignetting/imsim-vignetting.yaml where I made a boolean config variable and used a bunch of $ ... if IsComCam else ... lower in the config. I think this makes for an uglier config, but does have the advantage that you can easily swap the camera on the command line, e.g.: galsim blah.yaml eval_variables.bIsComCam=True.

4

Haven't experimented, but you might be able to combine 2&3 with some kind of dictionary...

eval_variables:
    sband: r
    bIsComCam: False
    camera_vars: |
        dict( |
            cameraName='LsstCam', 
            opticsFileName=f'LSST_{band}.yaml', 
            numdet=189 | 
        ) if not IsComCam else |
        dict( |
            cameraName='LsstComCamSim', 
            opticsFileName=f'ComCam_{band}.yaml', 
            numdet=9 | 
        )

...
input:
    telescope:
        filename: $camera_vars['opticsFileName']
jchiang87 commented 5 months ago

I was thinking we could have an Instrument class that serves a similar purpose as the OpsimData class in that all of the relevant info would be gathered in one place for other code to find what's needed. Doing this entirely with config-level manipulations seems confusing (to me at least) and error-prone.

jchiang87 commented 5 months ago

A simpler approach would be to have per instrument yaml configs that just set the options relevant for each particular camera. One could then just include the config file for the desired camera, though it's not clear to me that the yaml-handling code we have is able to support this.

jchiang87 commented 3 months ago

closed by #456