I think the logic on this needs to be:
```
if not ( 'image' in config and 'n_photons' in config['image'] ):
```
However, this suggests that you should probably switch the order of these two cases, and do the `n_photons` case first.