Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sensitivity Mapping Simulation Visualization and Info #711

Merged
merged 3 commits into from
Jun 2, 2023

Conversation

Jammy2211
Copy link
Collaborator

The Simulate object used in sensitivity mapping now receives a simulate_path which is a folder where simulation specific visualization and info can be output.

In the example below, I use this to output the dataset visuals, tracer visuals and a .json containing the tracer used to simulate the data:

class SimulateImaging:
def init(self, mask, psf):

    self.mask = mask
    self.psf = psf

def __call__(self, instance, simulate_path):
    """
    Set up the `Tracer` which is used to simulate the strong lens imaging, which may include the subhalo in
    addition to the lens and source galaxy.
    """
    tracer = al.Tracer.from_galaxies(
        galaxies=[
            instance.galaxies.lens,
            instance.perturbation,
            instance.galaxies.source,
        ]
    )

    """
    Set up the grid, PSF and simulator settings used to simulate imaging of the strong lens. These should be tuned to
    match the S/N and noise properties of the observed data you are performing sensitivity mapping on.
    """
    grid = al.Grid2DIterate.uniform(
        shape_native=self.mask.shape_native,
        pixel_scales=self.mask.pixel_scales,
        fractional_accuracy=0.9999,
        sub_steps=[2, 4, 8, 16, 24],
    )

    simulator = al.SimulatorImaging(
        exposure_time=300.0,
        psf=self.psf,
        background_sky_level=0.1,
        add_poisson_noise=True,
    )

    dataset = simulator.via_tracer_from(tracer=tracer, grid=grid)
    dataset.apply_mask(mask=self.mask)

    self.output_info(simulate_path=simulate_path, dataset=dataset, tracer=tracer)

    """
    The data generated by the simulate function is that which is fitted, so we should apply the mask for 
    the analysis here before we return the simulated data.
    """
    return dataset

def output_info(self, simulate_path, dataset, tracer):

    mat_plot = aplt.MatPlot2D(
        output = aplt.Output(path=simulate_path, format="png")
    )

    dataset_plotter = aplt.ImagingPlotter(
        imaging=dataset, mat_plot_2d=mat_plot
    )
    dataset_plotter.subplot_dataset()

    tracer_plotter = aplt.TracerPlotter(
        tracer=tracer, grid=dataset.grid, mat_plot_2d=mat_plot
    )
    tracer_plotter.subplot_lensed_images()

    with open(os.path.join(simulate_path, "tracer.json"), "w+") as f:
        json.dump(tracer.dict(), f, indent=4)

@Jammy2211 Jammy2211 requested a review from rhayes777 June 1, 2023 09:31
@codecov
Copy link

codecov bot commented Jun 1, 2023

Codecov Report

Merging #711 (bcf9348) into main (560ecca) will increase coverage by 0.02%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main     #711      +/-   ##
==========================================
+ Coverage   82.00%   82.02%   +0.02%     
==========================================
  Files         180      180              
  Lines       13264    13265       +1     
==========================================
+ Hits        10877    10881       +4     
+ Misses       2387     2384       -3     

see 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Owner

@rhayes777 rhayes777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this breaks separation of concerns

@Jammy2211
Copy link
Collaborator Author

I feel like this breaks separation of concerns

I agree, but the simulation function is user-written and the quantities which are visualized depend on it, so I dont see an obvious way to avoid it.

@rhayes777
Copy link
Owner

I feel like this breaks separation of concerns

I agree, but the simulation function is user-written and the quantities which are visualized depend on it, so I dont see an obvious way to avoid it.

Fair enough

@Jammy2211 Jammy2211 merged commit a58f156 into main Jun 2, 2023
@Jammy2211 Jammy2211 deleted the feature/sensitivity_visualize branch June 12, 2023 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants