deepskies / deeplenstronomy

A pipeline for versatile strong lens sample simulations
MIT License
26 stars 7 forks source link

Make it easy to fix values of parameters in a configuration #117

Closed musoke closed 1 year ago

musoke commented 1 year ago

I have created a configuration file in which some of the parameters are random.

I want to generate some images in which the random parameters are set to known, fixed values. I am envisioning being able to write something along the lines of


import deeplenstronomy.deeplenstronomy as dl
import yaml

with open("dls_config.yaml", "r") as stream:
    try:
        config = yaml.safe_load(stream)
    except yaml.YAMLError as exc:
        raise exc

fixed_params = [
  {"path": ['PLANE_1', 'OBJECT_1', 'MASS_PROFILE_1', 'Rs'], "value":1.0},
  {"path": ['PLANE_1', 'OBJECT_1', 'MASS_PROFILE_1', 'alpha_Rs'], "value":1.0},
]

dl.make_dataset(config, param_overrides=fixed_params)
Jasonpoh commented 1 year ago

There are currently two ways to fix parameters in a configuration:

1) Fix those values directly in the yaml file.

This is a bit clunky, but you could duplicate that yaml file and fix those values directly in the yaml file and generate a second dataset with those fixed model parameters.

2) Use Dataset.update_param

The Dataset object has a method update_param which allows you to update parameters to new values. For example:

model.update_param({'PLANE_1-OBJECT_1-MASS_PROFILE_1-theta_E-g': 2}, 'CONFIGURATION_1')

Changes the Einstein radius of all my PLANE_1, OBJECT_1, MASS_PROFILE_1 objects to 2. Follow this up with:

model.regenerate()

which will take the updated parameter dictionaries to regenerate an updated dataset including images.

I think method 2 is very similar to what you suggested. Let me know if this solves your requirements!

musoke commented 1 year ago

@Jasonpoh, thank you for the reply.

I ended up doing what you describe in 1).

2) is indeed quite similar to what wanted, the main difference being that the data set is generated first. I may use that in future if it works for me too.