EranOfek / AstroPack

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

Problem with empty array in AstroTable.insertColumn when using MovingSource.selectGoodCand #461

Closed saraylet closed 1 month ago

saraylet commented 1 month ago

Running these lines of code:

MP = MovingSource.read(Files(Ind).name);
MP.popKnownAst;
FC = MP.selectGoodCand;

Using this file:

LAST.01.01.01_20240108.191341.991_clear_043+18_041_001_001_sci_merged_Asteroids_1.mat

Results in this error:

Error using AstroTable.insertColumn (line 424)
Number of rows in column to insert must equal to the number of rows in array

Error in AstroTable/insertCol (line 1086)
                    Obj(Iobj).Catalog = AstroTable.insertColumn(Obj(Iobj).Catalog, Data, ColInd);

Error in imProc.sources.psfFitPhot (line 230)
                ResultObj(Iobj).CatData.insertCol(double([Result.X, Result.Y, Result.Flux, Result.Mag, Result.MagErr, Result.Chi2./Result.Dof,Result.SNm]),...

Error in MovingSource/psfFitExtended (line 1446)
                        [~, ResultPSF] = imProc.sources.psfFitPhot(Obj(Iobj).Stamps(Istamp), Args.psfFirPhotArgs{:}, 'FitRadius',Args.FitRadius);

Error in MovingSource/selectGoodCand (line 929)
            ResultExt = Obj.psfFitExtended(Args.psfFitExtended{:});

Error in readMovingSources (line 48)
        FC = MP.selectGoodCand;

It is trying to run these lines of code in AstroTable.m:

function NewArray = insertColumn(OldArray,NewData,ColInd)
            [Nrow,Ncol]   = size(OldArray);
            [NrowI,NcolI] = size(NewData);
            if  (Nrow~=NrowI)
                error('Number of rows in column to insert must equal to the number of rows in array');
            end
...

At the time of the error, MP is not empty, it is a 1x5 MovingSource object. OldArray is empty (problematic) and NewData is a 2x7 double. Therefore, Nrow is 0 and NrowI is 2.

EranOfek commented 1 month ago

[dev1 84926b1e] The problem was due to a bug in AstroTable/insertCol - it couldn't handle empty columns. Made some modifications to insertCol and also to fitPhotCube.

In psfFitPhot: line 145 - add && Args.FindSrc and argument added with default false.

In AstroTable/insertCol line 1043: added: if ~isempty(Data)