Skip to content

Aggregator for png splicing #1086

@Jammy2211

Description

@Jammy2211

Use Case:

To model 500 strong lens from Euclid, I found the workflow of navigating the output folder to inspect results
slow,

Furthermore, it was common for the information I needed to be spread across multiple images, leading to more clicks:

image

I developed a workflow which went to .png files I had output in the pipeline, extracted cut-outs showing the parts of the
fits of each individual lens I was interested in and saved them to .png files in a single folder that I could inspect
quickly.

The following URL shows an example of how

https://github.com/Jammy2211/autolens_workspace_test/tree/main/agg_png_csv

If you run the file png_to_single_line.py, you'll make a folder png containing images of the two example images
that enable quick inspection:

image

This uses the PIL library to open .png subplots showing many images and extract the individual images of each subplot
and save them to a new folder with a new figure and file name.

The images used by the code above to extract subplots are in the dataset folder, because for Euclid modeling
this is where I chose to store the images I used to extract subplots. However, I think a better implementation
would revolve entirely around the standard output folder produced by PyAutoFit.

AggregatorPng

I am picturing an AggregatorPng class that mirrors the API of the Aggregator class, which will allow a user
to quickly extract images from the image subplots inside the output folder and save them to a new folder.

The GitHub above has an output folder which contains the example outputs for the two lens, which is what the
AggregatorPng class can be developed to work with.

Example Query 1:

The first query would be to produce the following .png showing the fit to a given lens:

image

All of the information needed to make this plot is contained in a single .png file of each lens fit, called
subplot_fit.png. For this image, the source pixelization is shown, so we need the results of source_pix[2]:

image

So the first query for AggregatorPng would be something like:

agg = AggregatorPng.from_directory(
    directory=path.join("output),
)

image = agg.extract_images(
    image_type="subplot_fit",
    new_order = [5, 6, 11], # These are actually correct and I have chosen them based on subplot_fit.png
    original_shape = (3, 4), # The shape of the subplots in subplot_fit.png
    new_shape = (1, 3), # The shape of the new image we want to make
)


image.output_to_png(
    output_path=path.join("output", 102018665_NEG570040238507752998)
)

Automating original_shape

The original_shape can probably be determined when the .png is loaded, as the shape is clear and some
clever library can probably determine this. I dont know of one, but never looked.#

Example Query 2:

The next image adds the dataset/*/rgb_0.png image to the subplot, which shows the data of the lens:

image

image

This means the AggregatorPng class needs to be able to load multiple images and combine them into a single image,
something like this:

agg = AggregatorPng.from_directory(
    directory=path.join("output"),
)

image = agg.extract_images(
    image_name="subplot_fit",
    new_order = [5, 6, 11], # These are actually correct and I have chosen them based on subplot_fit.png
    original_shape = (3, 4), # The shape of the subplots in subplot_fit.png
    new_shape = (1, 3), # The shape of the new image we want to make
)

# Use the functionality in `png_util.add_image_to_left` to add the rgb image, but also make the API support all
directions.

[INSERT CODE HERE]

image.output_to_png(
    output_path=path.join("output", 102018665_NEG570040238507752998)
)

Example Query 3:

The image we made above only accessed one .png, subplot_fit.png. However, the output folder contains many
subplots, which we may want to combine into a single image.

For example, we may want to combine the subplot_fit.png of the source_pix[2] with the source_lp[1] result, and
put their RGB images ont he left, as done in the original example:

image

This combines the following .png files:

image

At this point, I think you get the idea of the framework I am hoping we can develop.

Example Query 4:

The final example combines the same images (e.g. the same things extract from subplot_fit.png) as rows for each result folder (vis, nir_h, nir_j, nir_y:

image

I suspect the code you develop will already support the making of this image, via a clever combination of of AggregatorPng commands.

However, this image performs a specific pattern, finding all .png files of the same name in a folder and putting the extracted images as rows. This is a common pattern, and may warrant a short-cut API. However, I think just having examples which do this in a for loop, using the base AggregatorPng API, is probably better to teach the user how to use the tool in this way, so maybe just make sure this query is doable!

Missing .png Files

A user can disable the output of .png files, so the AggregatorPNG should raise an warning if the user tries to use
the API and the file is not present.

It should still try to produce a .png where possible, for example if a subset of the .png files needed to make it are avaialble. If none are available no .png should be output.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions