EranOfek / AstroPack

Astronomy & Astrophysics Software Pacakge
Other
17 stars 4 forks source link

`imProc.astrometry.astrometryQualityData` error #170

Closed EastEriq closed 1 year ago

EastEriq commented 1 year ago
 R=imProc.astrometry.astrometryQualityData(AI)
Unable to perform assignment because the size of the left side is 1-by-1 and the size
of the right side is 0-by-1.

Error in fminsearch (line 216)
fv(:,1) = funfcn(x,varargin{:});

Error in celestial.coo.boundingCircle (line 48)
[BestCoo, BestRadius] = fminsearch(@radiusForCenter,[MidLon, MidLat], Options);

Error in AstroCatalog/boundingCircle (line 696)
                        [BestCoo, BestRadius] = celestial.coo.boundingCircle(X, Y);   % [radians]

Error in imProc.match.returnMatched_catsHTM (line 100)
            [CircX, CircY, CircR] = CatIn(Iobj).boundingCircle('OutUnits','rad', 'CooType','sphere');

Error in imProc.astrometry.astrometryQualityData (line 153)
        [MatchedRefCat(Iobj), ResInd(Iobj), CatH] = imProc.match.returnMatched_catsHTM(Obj(Iobj), Args.CatName,...

AI is a processed PTF image ( /raid/enrico/PTF/2ndTake/images/level1/proc/2012/01/07/f12/c0/p5/v1/PTF_201201075042_i_p_scie_t120602_u011065103_f12_p015199_c00.fits), with the code

T=readIVOtable('/raid/enrico/PTF/2ndTake/M81.tbl');
ff=fullfile('/raid/enrico/PTF/2ndTake/images/level1',T.pfilename);
AI=AstroImage(ff(5));
AI.populateWCS; %not automatical, https://github.com/EranOfek/AstroPack/issues/151
imProc.calib.gainCorrect(AI);

% ad hoc corrections for defects of ccd 0
if AI.HeaderData.getVal('CCDID')==0
    AI.Image=adHocTreatmentPTFccd0(AI.Image);
end

imProc.calib.equaliseLineMean(AI);

AI.MaskData.Data=mapPTF2oursMask(MaskImage(strrep(ff{1},'scie','mask')));

imProc.background.background(AI, 'SubSizeXY',[128 128]);
imProc.mask.maskHoles(AI);
imProc.mask.maskSourceNoise(AI);

%  no imProc equivalent for masking bad columns, do it in steps
%  threshold is a bit delicate. I would prefer a more robust method,
%    marking perhaps only the bad part of the column
% mask=imUtil.background.flag_badcol(AI.Image,'Dim',1,'CollapseFun','std','Threshold',50);

imProc.sources.findMeasureSources(AI,'RemoveBadSources',true,'RemoveEdgeDist',3);
imProc.psf.constructPSF(AI); % a few hundred Nsrc
[~,Sources]=imProc.sources.psfFitPhot(AI) % thousands Sources
astrometry=imProc.astrometry.astrometryRefine(AI)

% file #3, bad column 461, lots of false sources

ds9(AI,'zoom','to fit')
%ds9.plotXY([Sources.X(Sources.ConvergeFlag),Sources.Y(Sources.ConvergeFlag)])
ds9.plotXY([Sources.X,Sources.Y])
%ds9.plotXY([Sources.X(Sources.Chi2<100),Sources.Y(Sources.Chi2<100)])
EranOfek commented 1 year ago

Note that AI.poopualteWCS is not needed anymore - happens automatically.

EranOfek commented 1 year ago

The problem is that the RA/Dec were not propogatyed to the catalog. To fix this:

  1. It will now will fain with error: "Can not find RA/Dec coordinates in catalog"
  2. in astrometryRefine I added a new option: 'AddCoo2Cat' which will do it (note that right now the default is false)
  3. Instead you can directly use:
    AI=imProc.astrometry.addCoordinates2catalog(AI)
EastEriq commented 1 year ago

I'm using [W,AI]=imProc.astrometry.astrometryRefine(AI,'AddCoo2Cat',true), but now I get

Error using AstroCatalog/boundingCircle
Can not find RA/Dec coordinates in catalog

Error in imProc.calib.photometricZP (line 229)
                    [RA, Dec, CircleRadius] = boundingCircle(Cat, 'OutUnits','rad', 'CooType','sphere');

when I subsequently call [AI, ZP, PhotCat] =imProc.calib.photometricZP(AI)

EastEriq commented 1 year ago

And if I prepend AI=imProc.astrometry.addCoordinates2catalog(AI) to that call to photometricZP(), I get

Index exceeds the number of array elements. Index must not exceed 0.

Error in VO.search.search_sortedlat_multiNearest (line 67)
Ilowhigh = double(Inear(Ilat));

Error in imProc.match.matchReturnIndices (line 152)
        [IndTable, CatFlagNearest, CatFlagAll, IndInObj2] = VO.search.search_sortedlat_multiNearest(Coo1,...

Error in imProc.calib.photometricZP (line 260)
            ResMatch = imProc.match.matchReturnIndices(PhotCat(Iobj), Cat, 'Radius',Args.Radius,...

Great.

EastEriq commented 1 year ago

Guess what is DistFun at line 152 of imProc.match.matchReturnIndices. Again #156 . ^%#&^@#!!!

EastEriq commented 1 year ago

but besides line 237 of imProc.calib.photometricZP retrieves an empty PhotCat(1), which is the cause of this error. Give me a break.

EastEriq commented 1 year ago

The empty catalog comes from this call: https://github.com/EranOfek/AstroPack/blob/9e08b02e19594ffedc43d1575671553aeb5378c0/matlab/image/%2BimProc/%2Bcat/getAstrometricCatalog.m#L102 which calls cone_search. Guess which function uses cone_search? But that anyway seems not the problem. boundingCircle at line 229 returns a very small CircleRadius, 2.2744e-06. I suspect it might be an unit issue. At that point, Cat.ColUnits are mostly empty, notably columns 52 and 53 for Ra and Dec.

EranOfek commented 1 year ago

I suspect you are right - this is a units problem.

On Sun, Aug 6, 2023 at 3:25 PM EastEriq @.***> wrote:

The empty catalog comes from this call: https://github.com/EranOfek/AstroPack/blob/9e08b02e19594ffedc43d1575671553aeb5378c0/matlab/image/%2BimProc/%2Bcat/getAstrometricCatalog.m#L102 which calls cone_search. Guess which function uses cone_search? But that anyway seems not the problem. boundingCircle at line 229 gets a very small CircleRadius, I suspect. Maybe it is an unit issue. At that point, Cat.ColUnits are mostly empty, notably columns 52 and 53 for Ra and Dec.

— Reply to this email directly, view it on GitHub https://github.com/EranOfek/AstroPack/issues/170#issuecomment-1666841941, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJUQ4PXKTDVA6VFRR5TWWLXT6EK3ANCNFSM6AAAAAAZYGDGLY . You are receiving this because you modified the open/close state.Message ID: @.***>

EastEriq commented 1 year ago

Opened issue #213 separately for this

EastEriq commented 1 year ago

The latter problems solved by commit 9ce248d62fc.