caracal-pipeline / caracal

Containerized Automated Radio Astronomy Calibration (CARACal) pipeline
GNU General Public License v2.0
28 stars 6 forks source link

cleaning datacubes and regrid mask sneakily fails #1462

Closed Fil8 closed 1 year ago

Fil8 commented 1 year ago

There are some issues when cleaning with a mask:

wsclean3.1 fails when cleaning a datacube with a fitsmask. It always uses the first channel for the entire band. This issue will be fixed in wsclean3.3. In the mean time use wsclean3.0.


There are some issues with re-gridding the mask in the line worker. At these lines:

https://github.com/caracal-pipeline/caracal/blob/4f716f7c7f16ff5b7face76af053fb459a06bd77/caracal/workers/line_worker.py#L908-L912

1 - if doProj switches to True because cubeHeight/Width is different from the mask, then it may switch back to None because Ra or Dec are the same

Solution:

with fits.open(mask) as hdul: 
    if hdul[0].header["NAXIS1"] != cubeWidth: 
      doProj = True 
    if hdul[0].header["NAXIS2"] != cubeHeight: 
      doProj = True 
    if hdul[0].header["CRVAL1"] != raTarget: 
      doProj = True 
    if hdul[0].header["CRVAL2"] != decTarget: 
      doProj = True   

2 - The output cube of wsclean may have a negative RA (because of some SARAO configurations?), while we define raTarget from the summary json file converting it from radians, so it will always be positive. The two angles are the same but with a difference of 360 degrees. Solution:

we make sure that the header of the output cubes always has a positive CRVAL1. We can do this in fix_specsys which will become fix_specsys_ra. This module is always called after creating the cube.

I will fix this issue in a new branch.

ATTENTION once the bug is fixed, if you will use an old mask generated with caracal, always make sure that the RA in the header is positive.

healytwin1 commented 1 year ago

In order to use WSClean 3.0 while still generally using the latest versions of stimela, one can add the following to the line_worker section:

line:
    enable: true
    cabs:
    - name: wsclean
       tag: 1.7.3
edeblok commented 1 year ago

Regarding the first item on the list (doProj). This can also be easily fixed by just swapping the first two lines and the last two lines (i.e. have CRVAL first and NAXIS second) without any further rewriting. Also no need to touch the header to change RA. I've used this trick many times when regridding fails and it's always worked.

healytwin1 commented 1 year ago

The mask cleaning issue with WSClean has now been fixed in WSClean 3.3. @SpheMakh or @Athanaseus can we please get this added to stimela?