caracal-pipeline / caracal

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

crvale is not defined if CTYPE3==FREQ in line_worker.py #1529

Open ianjarog opened 1 year ago

ianjarog commented 1 year ago

Looks like in this line in line_worker.py crvale is not defined if 'FREQ' in hdul[0].header['CTYPE3']

                        if 'FREQ' in hdul[0].header['CTYPE3']:
                            ## all in Hz
                            crval = firstchanfreq[0]+chanwidth[0]*firstchan
                            cdeltm = hdul[0].header['CDELT3']
                            cdelte = crval+nchans*binchans*chanwidth[0]
                        else:
                            ## all in m/s
                            crval = C*(femit - (firstchanfreq[0]+chanwidth[0]*firstchan))/femit
                            cdeltm = hdul[0].header['CDELT3']*femit/(-C)
                            crvale = C*(femit - (firstchanfreq[0]+chanwidth[0]*firstchan+nchans*binchans*chanwidth[0]))/femit

                        cdelt = chanwidth[0]*binchans ## in Hz
                        hdr = hdul[0].header
                        ax3 = np.arange(hdr['CRVAL3']-hdr['CDELT3']*(hdr['CRPIX3']-1), hdr['CRVAL3']+hdr['CDELT3']*(hdr['NAXIS3']-hdr['CRPIX3']+1), hdr['CDELT3'])
                        if (np.max([crval, crvale]) <= np.max([ax3[0], ax3[-1]])) & (np.min([crval, crvale]) >= np.min([ax3[0], ax3[-1]])):
                            caracal.log.info("Requested channels are contained in mask {}.".format(gridMask))

                            idx = np.argmin(abs(ax3-crval))
                            ide = np.argmin(abs(ax3-crvale))
paoloserra commented 1 year ago

This is the bit where, since the user mask cube is not on the same channel grid as the new image cube being made, some channel selection and/or binning needs to happen before the mask can be used for cleaning.

I'm not sure why crvale is not defined when the spectral axis is in frequency. @healytwin1 @Fil8 any idea?

healytwin1 commented 11 months ago

Sorry I didn't see this earlier. Not sure why crvale wouldn't be defined. Out of interest, what does the header file that is triggering the error look like?

healytwin1 commented 8 months ago

@ianjarog is this still a problem?

ianjarog commented 8 months ago

@ianjarog is this still a problem?

@healytwin1 This happened to the latest branch at the time of testing and I switched to another branch to bypass it. I need to test again to confirm. I think the code itself is very clear that there is no crvale defined if 'FREQ' in hdul[0].header['CTYPE3']

ianjarog commented 5 months ago

@healytwin1 crvale=firstchanfreq[0]+chanwidth[0]firstchan+nchansbinchans*chanwidth[0] should be added to the line in if 'FREQ' in hdul[0].header['CTYPE3']: I also noticed that this condition (np.max([crval, crvale]) <= np.max([ax3[0], ax3[-1]])) & (np.min([crval, crvale]) >= np.min([ax3[0], ax3[-1]])) was not satisfied in case where it should be satisfied (in case of a very small difference in frequency).