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

Dirty images are scaled differently #606

Open
anawas opened this issue Aug 8, 2024 · 2 comments
Open

Dirty images are scaled differently #606

anawas opened this issue Aug 8, 2024 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@anawas
Copy link
Collaborator

anawas commented Aug 8, 2024

Summary

Dirty images created from Rascil and OSKAR are scaled differently. Rascil output pixel values that are 10x higher. We need to investigate where this comes from.

Präsentation1

How to reproduce

# To keep this demo small, we assume that the visibility is calculated elsewhere
# We need to set both parameters because Rascil needs measurement set
# Note: Visibility.read_from_file() doesn't work because it tries to read measurement set from
# random temp folder, which is empty at this time.
visibility = Visibility(vis_path="visibility.vis", ms_file_path="measurements.MS")

image_npixel = 4096
cellsize = 5e-6  # FOV / image_npixel

# Get OSKAR and Rascil imagers
oskar_imager = OskarDirtyImager(
    OskarDirtyImagerConfig(
        imaging_npixel=image_npixel,
        imaging_cellsize=cellsize,
        combine_across_frequencies=True,
    )
)

rascil_imager = RascilDirtyImager(
    RascilDirtyImagerConfig(
        imaging_npixel=image_npixel,
        imaging_cellsize=cellsize,
        combine_across_frequencies=True,
    )
)

# Calculate dirty images with the imagers
oskar_dirty_image = oskar_imager.create_dirty_image(vis)
oskar_dirty_image.plot(
    title="OSKAR dirty image",
    filename="oskar_dirty_image.png"
)

rascil_dirty_image = rascil_imager.create_dirty_image(vis.ms_file_path)
rascil_dirty_image.plot(
    title="Rascil dirty image",
    filename="rascil_dirty_image.png"
)
@anawas anawas self-assigned this Aug 8, 2024
@anawas anawas added the question Further information is requested label Aug 8, 2024
@sfiruch
Copy link
Member

sfiruch commented Aug 8, 2024

Can you add a minimal repro?

@anawas
Copy link
Collaborator Author

anawas commented Oct 28, 2024

Update

This is not a bug. The observed behaviour is due to how the two imagers handle multi-channel images. For the OSKAR backend, the dirty image will always have intensities added across all frequency channels.

By default, the RASCIL Imager produces a 4D Image object, with shape corresponding to (frequency channels, polarisations, pixels_x, pixels_y). There is an image for each channel.

The parameter combine_across_frequencies in the ImagerConfig is used to control how the imagers process multi-channel images. If set to True, which is the default, then RASCIL adds up all channels and displays the summed flux. This is done in imager_rascil.py on line 121:

if self.config.combine_across_frequencies is True:
   image.header["NAXIS4"] = 1

   assert image.data.ndim == 4
   image.data = np.array([np.sum(image.data, axis=0)])

   image.write_to_file(path=output_fits_path, overwrite=True)

If an image as 10 channels, then the flux in the RASCIL image will be 10 times higher. This is what we see when we compare the images.

The OSKAR Imager always produces one image by combining all frequency channels. Thus, this parameter has no influence here. It must be set to True, which it is by default.

Result

I suggest to close this issue. If you need images that are equally scaled you set combine_across_frequencies=False for RASCIL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants