IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41657 for trunk/psastro


Ignore:
Timestamp:
Jun 8, 2021, 3:40:00 PM (5 years ago)
Author:
eugene
Message:

merge changes from tags/ipp-ps1-20210510: improve crosstalk and ghost analysis

Location:
trunk/psastro
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/psastro

  • trunk/psastro/src/Makefile.am

    r38040 r41657  
    109109        psastroMosaicSetMatch.c     \
    110110        psastroFindChip.c           \
     111        psastroFindChipGPC.c           \
    111112        psastroZeroPoint.c          \
    112113        psastroDemoDump.c           \
  • trunk/psastro/src/psastro.h

    r41500 r41657  
    184184bool              psastroFPAtoChip (double *xChip, double *yChip, pmFPA *fpa, int nChip, double xFPA, double yFPA);
    185185
     186pmChip           *psastroFindChipGPC (double *xChip, double *yChip, pmFPA *fpa, double xFPA, double yFPA);
     187bool              psastroChipBoundsGPC (pmFPA *fpa);
     188pmChip           *psastroCheckChip (double *xChip, double *yChip, pmFPA *fpa, int nChip, double xFPA, double yFPA);
     189bool              psastroExtractFreeChipBoundsGPC(void);
     190
    186191//bool              psastroMaskStats(pmConfig *config, psMetadata *stats);
    187192
  • trunk/psastro/src/psastroLoadCrosstalk.c

    r41590 r41657  
    1212
    1313# include "psastroInternal.h"
     14#include <time.h>
    1415
    1516# define ESCAPE { \
     
    135136      while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
    136137        psTrace ("psastro.crosstalk", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
    137 
    138138        if (!cell->process || !cell->file_exists) { continue; }
    139139
     
    398398
    399399              int crossChip = psMetadataLookupS32 (&status, crossItem->data.md, "CHIP.SRC");
    400               int crossCell = psMetadataLookupS32 (&status, crossItem->data.md, "CELL.SRC");
    401               int crossChipOffset = psMetadataLookupS32 (&status, crossItem->data.md, "CHIP.OFFSET");
    402               int crossCellOffset = psMetadataLookupS32 (&status, crossItem->data.md, "CELL.OFFSET");
    403               float crossMagOff = psMetadataLookupF32 (&status, crossItem->data.md, "CROSS.MAGDIFF");
    404               if (!status) {
    405                 psWarning ("CROSSTALK.RULE entry is missing necessary entry");
    406                 continue;
    407               }
    408 
    409400              if (!(X == crossChip)) {
    410401                psTrace ("psastro.crosstalk",2,"Chip (%d%d) not a known crosstalk source.",X,Y);
     
    412403              }
    413404
     405              int crossCell = psMetadataLookupS32 (&status, crossItem->data.md, "CELL.SRC");
     406              char *strChipOffset = psMetadataLookupStr (&status, crossItem->data.md, "CHIP.OFFSET");
     407              char *strCellOffset = psMetadataLookupStr (&status, crossItem->data.md, "CELL.OFFSET");
     408              char *strMagOffset = psMetadataLookupStr (&status, crossItem->data.md, "CROSS.MAGDIFF");
     409
     410              //Parse the strings into individual entries
     411              int crossChipOffset[40];
     412              int crossCellOffset[40];
     413              float crossMagOffset[40];
     414
     415              int nrul = 0;
     416              char *p = strtok (strChipOffset, "/");
     417              while (p != NULL) {
     418                  crossChipOffset[nrul++] = atoi(p);
     419                  p = strtok (NULL, "/");
     420              } 
     421              int nrul2 = 0;
     422              char *p2 = strtok (strCellOffset, "/");
     423              while (p2 != NULL) {
     424                  crossCellOffset[nrul2++] = atoi(p2);
     425                  p2 = strtok (NULL, "/");
     426              } 
     427              int nrul3 = 0;
     428              char *p3 = strtok (strMagOffset, "/");
     429              while (p3 != NULL) {
     430                  crossMagOffset[nrul3++] = atof(p3);
     431                  p3 = strtok (NULL, "/");
     432              } 
     433
     434              if ((nrul != nrul2) | (nrul != nrul3)) {
     435                psWarning ("CROSSTALK.RULE entry is not correctly formatted or incomplete");
     436                continue;
     437              }
     438
    414439              //the source star needs to be bright enough to produce a crosstalk feature on the target chip/cell that is above the refmag
    415               float INSTR_CROSS_MAX_MAG = de->magRef - crossMagOff;
     440              //float INSTR_CROSS_MAX_MAG = de->magRef - crossMagOff;
     441              float INSTR_CROSS_MAX_MAG = de->magRef;
    416442              float CROSS_MAX_MAG = INSTR_CROSS_MAX_MAG + MagOffset;
    417443
     
    423449              for (int i = 0; i < calstars->n; i++) {
    424450                pmAstromObj *cal = calstars->data[i];
    425                 //kick out stars too faint to produce crosstalk with this rule
    426                 if (cal->Mag > INSTR_CROSS_MAX_MAG) { continue; }
     451                //kick out stars too faint to produce crosstalk with any rule
     452                if (cal->Mag > (INSTR_CROSS_MAX_MAG-6.)) { continue; }
    427453
    428454                // Identify which cell holds the star
     
    454480                }
    455481
    456                 int chipTarget = chipNum + crossChipOffset ;
    457                 int cellTarget = cellNum + crossCellOffset ;
    458 
    459                 // Convert target cell coordinates to target chip coordinates
    460                 psString targetChipName = NULL;
    461                 if(chipTarget > 8) {
    462                   psStringAppend(&targetChipName,"XY%2d",chipTarget);
    463                 }
    464                 if(chipTarget < 8) {
    465                   psStringAppend(&targetChipName,"XY0%1d",chipTarget);
    466                 }
    467                 psString targetCellName = NULL;
    468                 if(cellTarget > 8) {
    469                   psStringAppend(&targetCellName,"xy%2d",cellTarget);
    470                 }
    471                 if(cellTarget < 8) {
    472                   psStringAppend(&targetCellName,"xy0%1d",cellTarget);
    473                 }
    474 
    475                 psTrace ("psastro.crosstalk",2,"CTsource from DETEC @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%2dxy%2d@%f,%f [%s %s]",
     482                for (int k = 0 ; k < nrul; k++) {
     483                    int chipTarget = chipNum + crossChipOffset[k] ;
     484                    int cellTarget = cellNum + crossCellOffset[k] ;
     485                    if (cal->Mag > (INSTR_CROSS_MAX_MAG-crossMagOffset[k])) { continue; }
     486
     487                    // Convert target cell coordinates to target chip coordinates
     488                    psString targetChipName = NULL;
     489                    if(chipTarget > 8) {
     490                      psStringAppend(&targetChipName,"XY%2d",chipTarget);
     491                    }
     492                    if(chipTarget < 8) {
     493                      psStringAppend(&targetChipName,"XY0%1d",chipTarget);
     494                    }
     495                    psString targetCellName = NULL;
     496                    if(cellTarget > 8) {
     497                      psStringAppend(&targetCellName,"xy%2d",cellTarget);
     498                    }
     499                    if(cellTarget < 8) {
     500                      psStringAppend(&targetCellName,"xy0%1d",cellTarget);
     501                    }
     502
     503                    psTrace ("psastro.crosstalk",2,"CTsource from DETEC @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%2dxy%2d@%f,%f [%s %s]",
    476504                       X,Y,U,V,x_cell,y_cell,chipTarget,cellTarget,x_t_cell,y_t_cell,
    477505                       targetChipName,targetCellName);
    478506
    479                 pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName);
    480                 if (!CTtargetCell) continue;
    481 
    482                 pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell);
    483 
    484                 psTrace ("psastro.crosstalk",2,"CTsource from DETEC @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%2dxy%2d@%f,%f ChipLoc: (%f,%f)",
     507                    pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName);
     508                    if (!CTtargetCell) continue;
     509
     510                    pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell);
     511
     512                    psTrace ("psastro.crosstalk",2,"CTsource from DETEC @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%2dxy%2d@%f,%f ChipLoc: (%f,%f)",
    485513                       X,Y,U,V,x_cell,y_cell,chipTarget,cellTarget,x_t_cell,y_t_cell,x_t_chip,y_t_chip);
    486514
    487                 // Hunt down the readout for the target, and save the chip position and magnitude of source star.
    488                 pmChip *targetChip = getChipByName(fpa,targetChipName);
    489                 if (!targetChip) continue;
    490                 if (!targetChip->cells) continue;
    491                 if (!targetChip->cells->n) continue;
    492 
    493                 pmCell *targetCell = targetChip->cells->data[0];
    494                 if (!targetCell) continue;
    495                 if (!targetCell->readouts) continue;
    496                 if (!targetCell->readouts->n) continue;
    497                 pmReadout *targetReadout = targetCell->readouts->data[0];
    498                 if (!targetReadout) continue;
    499 
    500                 //check if the crosstalk is above the target chip background level
    501                 pmDetEff *tarde = psMetadataLookupPtr(NULL, targetReadout->analysis, PM_DETEFF_ANALYSIS); // Detection efficiency
    502                 if (isnan(tarde->magRef)) { continue; }
    503 
    504                 float TARGET_CROSS_MAX_MAG = tarde->magRef-crossMagOff;
    505 
    506                 if (cal->Mag > TARGET_CROSS_MAX_MAG) { continue; }
    507 
    508                 pmAstromObj *crosstalk = pmAstromObjAlloc();
     515                    // Hunt down the readout for the target, and save the chip position and magnitude of source star.
     516                    pmChip *targetChip = getChipByName(fpa,targetChipName);
     517                    if (!targetChip) continue;
     518                    if (!targetChip->cells) continue;
     519                    if (!targetChip->cells->n) continue;
     520
     521                    pmCell *targetCell = targetChip->cells->data[0];
     522                    if (!targetCell) continue;
     523                    if (!targetCell->readouts) continue;
     524                    if (!targetCell->readouts->n) continue;
     525                    pmReadout *targetReadout = targetCell->readouts->data[0];
     526                    if (!targetReadout) continue;
     527
     528                    //check again if the crosstalk is above the target chip background level
     529                    pmDetEff *tarde = psMetadataLookupPtr(NULL, targetReadout->analysis, PM_DETEFF_ANALYSIS); // Detection efficiency
     530                    if (isnan(tarde->magRef)) { continue; }
     531
     532                    float TARGET_CROSS_MAX_MAG = tarde->magRef-crossMagOffset[k];
     533                    if (cal->Mag > TARGET_CROSS_MAX_MAG) { continue; }
     534                    pmAstromObj *crosstalk = pmAstromObjAlloc();
    509535           
    510                 crosstalk->Mag = cal->Mag;
    511                 crosstalk->chip->x = x_t_chip;
    512                 crosstalk->chip->y = y_t_chip;
    513 
    514                 psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS");
    515                 if (crosstalks == NULL) {
    516                   crosstalks = psArrayAllocEmpty(100);
    517                   if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) {
    518                     psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout");
    519                     goto escape;
    520                   }
    521                   psFree(crosstalks);
    522                 }
    523                 psArrayAdd(crosstalks,100,crosstalk);
     536                    crosstalk->Mag = cal->Mag;
     537                    crosstalk->chip->x = x_t_chip;
     538                    crosstalk->chip->y = y_t_chip;
     539
     540                    psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS");
     541                    if (crosstalks == NULL) {
     542                      crosstalks = psArrayAllocEmpty(100);
     543                      if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) {
     544                        psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout");
     545                        goto escape;
     546                      }
     547                      psFree(crosstalks);
     548                    }
     549                    psArrayAdd(crosstalks,100,crosstalk);
    524550           
    525                 psFree(targetChipName);
    526                 psFree(targetCellName);
    527                 psFree(crosstalk);
    528 
    529                 // Determine if we need to add a spike mask.
    530                 // TdB20210304: This should not be relevant for faint crosstalk rules. Do this rather ad hoc right now by placing a limit at 8 mags of difference
    531                 if( crossMagOff > 8.) { continue; }
    532                 if (cal->Mag < SPIKE_MAX_MAG) {       
    533                   int Xt = X;
    534                   int Yt = Y;
    535                   int Vt = V;
     551                    psFree(targetChipName);
     552                    psFree(targetCellName);
     553                    psFree(crosstalk);
     554
     555                    // Determine if we need to add a spike mask.
     556                    // TdB20210304: This should not be relevant for faint crosstalk rules. Do this rather ad hoc right now by placing a limit at 8 mags of difference
     557                    if( crossMagOffset[k] > 8.) { continue; }
     558                    if ((cal->Mag + MagOffset) < SPIKE_MAX_MAG) {             
     559                      int Xt = X;
     560                      int Yt = Y;
     561                      int Vt = V;
    536562             
    537                   for (int Ut = 0; Ut < 8; Ut++) {
    538                     psString targetChipName = NULL;
    539                     psStringAppend(&targetChipName,"XY%d%d",Xt,Yt);
    540                     psString targetCellName = NULL;
    541                     psStringAppend(&targetCellName,"xy%d%d",Ut,Vt);
    542                
    543                     psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f [%s %s]",
     563                      for (int Ut = 0; Ut < 8; Ut++) {
     564                        psString targetChipName = NULL;
     565                        psStringAppend(&targetChipName,"XY%d%d",Xt,Yt);
     566                        psString targetCellName = NULL;
     567                        psStringAppend(&targetCellName,"xy%d%d",Ut,Vt);
     568               
     569                        psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f [%s %s]",
    544570                           X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell,
    545571                           targetChipName,targetCellName);
    546572               
    547                     pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName);
    548                     if (!CTtargetCell) continue;
    549                
    550                     pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell);
    551 
    552                     psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f ChipLoc: (%f,%f)",
     573                        pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName);
     574                        if (!CTtargetCell) continue;
     575               
     576                        pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell);
     577
     578                        psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f ChipLoc: (%f,%f)",
    553579                           X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell,x_t_chip,y_t_chip);
    554580               
    555                     // Hunt down the readout for the target, and save the chip position and magnitude of source star.
    556                     pmChip *targetChip = getChipByName(fpa,targetChipName);
    557                     if (!targetChip) continue;
    558                     if (!targetChip->cells) continue;
    559                     if (!targetChip->cells->n) continue;
     581                        // Hunt down the readout for the target, and save the chip position and magnitude of source star.
     582                        pmChip *targetChip = getChipByName(fpa,targetChipName);
     583                        if (!targetChip) continue;
     584                        if (!targetChip->cells) continue;
     585                        if (!targetChip->cells->n) continue;
    560586                 
    561                     pmCell *targetCell = targetChip->cells->data[0];
    562                     if (!targetCell) continue;
    563                     if (!targetCell->readouts) continue;
    564                     if (!targetCell->readouts->n) continue;
    565                     pmReadout *targetReadout = targetCell->readouts->data[0];
    566                     if (!targetReadout) continue;
    567                
    568                     pmAstromObj *crosstalk = pmAstromObjAlloc();
    569                
    570                     crosstalk->Mag = cal->Mag;
    571                     crosstalk->chip->x = x_t_chip;
    572                     crosstalk->chip->y = y_t_chip;
    573                
    574                     psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS.SPIKES");
    575                     if (crosstalks == NULL) {
    576                       crosstalks = psArrayAllocEmpty(100);
    577                       if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS.SPIKES", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) {
    578                         psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout");
    579                         goto escape;
    580                       }
    581                       psFree(crosstalks);
    582                     }
    583                     psArrayAdd(crosstalks,100,crosstalk);
    584                
    585                     psFree(targetChipName);
    586                     psFree(targetCellName);
    587                     psFree(crosstalk);
    588                   }
    589                 } // End satspike crosstalks
     587                        pmCell *targetCell = targetChip->cells->data[0];
     588                        if (!targetCell) continue;
     589                        if (!targetCell->readouts) continue;
     590                        if (!targetCell->readouts->n) continue;
     591                        pmReadout *targetReadout = targetCell->readouts->data[0];
     592                        if (!targetReadout) continue;
     593               
     594                        pmAstromObj *crosstalk = pmAstromObjAlloc();
     595               
     596                        crosstalk->Mag = cal->Mag + MagOffset;
     597                        crosstalk->chip->x = x_t_chip;
     598                        crosstalk->chip->y = y_t_chip;
     599               
     600                        psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS.SPIKES");
     601                        if (crosstalks == NULL) {
     602                          crosstalks = psArrayAllocEmpty(100);
     603                          if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS.SPIKES", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) {
     604                            psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout");
     605                            goto escape;
     606                          }
     607                          psFree(crosstalks);
     608                        }
     609                        psArrayAdd(crosstalks,100,crosstalk);
     610               
     611                        psFree(targetChipName);
     612                        psFree(targetCellName);
     613                        psFree(crosstalk);
     614                      }
     615                    } // End satspike crosstalks
     616                  } //end of rules block
    590617              } // End calMags
    591618
    592          
    593619              // We also want to use the refstars to check for crosstalk. In particular, the detections
    594620              // do not do well for bright stars, and saturated detections will underestimate the size of the crostalk
     
    601627                // This is the source of the ct.
    602628                pmAstromObj *ref = refstars->data[i];
    603 
    604                 if (ref->Mag > CROSS_MAX_MAG) { continue; }
     629                if (ref->Mag > (CROSS_MAX_MAG-6.)) { continue; }
    605630
    606631                // Identify which cell holds the star
     
    633658                }
    634659
    635                 int chipTarget = chipNum + crossChipOffset ;
    636                 int cellTarget = cellNum + crossCellOffset ;
    637 
    638                 // Convert target cell coordinates to target chip coordinates
    639                 psString targetChipName = NULL;
    640                 if(chipTarget > 8) {
    641                   psStringAppend(&targetChipName,"XY%2d",chipTarget);
    642                 }
    643                 if(chipTarget < 8) {
    644                   psStringAppend(&targetChipName,"XY0%1d",chipTarget);
    645                 }
    646                 psString targetCellName = NULL;
    647                 if(cellTarget > 8) {
    648                   psStringAppend(&targetCellName,"xy%2d",cellTarget);
    649                 }
    650                 if(cellTarget < 8) {
    651                   psStringAppend(&targetCellName,"xy0%1d",cellTarget);
    652                 }
    653 
    654                 psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%2dxy%2d@%f,%f [%s %s]",
     660                for (int k = 0 ; k < nrul; k++) {
     661                    int chipTarget = chipNum + crossChipOffset[k] ;
     662                    int cellTarget = cellNum + crossCellOffset[k] ;
     663                    if (ref->Mag > (CROSS_MAX_MAG-crossMagOffset[k])) { continue; }
     664
     665                    // Convert target cell coordinates to target chip coordinates
     666                    psString targetChipName = NULL;
     667                    if(chipTarget > 8) {
     668                      psStringAppend(&targetChipName,"XY%2d",chipTarget);
     669                    }
     670                    if(chipTarget < 8) {
     671                      psStringAppend(&targetChipName,"XY0%1d",chipTarget);
     672                    }
     673                    psString targetCellName = NULL;
     674                    if(cellTarget > 8) {
     675                      psStringAppend(&targetCellName,"xy%2d",cellTarget);
     676                    }
     677                    if(cellTarget < 8) {
     678                      psStringAppend(&targetCellName,"xy0%1d",cellTarget);
     679                    }
     680
     681                    psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%2dxy%2d@%f,%f [%s %s]",
    655682                       X,Y,U,V,x_cell,y_cell,chipTarget,cellTarget,x_t_cell,y_t_cell,
    656683                       targetChipName,targetCellName);
    657684
    658                 pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName);
    659                 if (!CTtargetCell) continue;
    660 
    661                 pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell);
    662 
    663                 psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%2dxy%2d@%f,%f ChipLoc: (%f,%f)",
     685                    pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName);
     686                    if (!CTtargetCell) continue;
     687
     688                    pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell);
     689
     690                    psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%2dxy%2d@%f,%f ChipLoc: (%f,%f)",
    664691                       X,Y,U,V,x_cell,y_cell,chipTarget,cellTarget,x_t_cell,y_t_cell,x_t_chip,y_t_chip);
    665692
    666                 // Hunt down the readout for the target, and save the chip position and magnitude of source star.
    667                 pmChip *targetChip = getChipByName(fpa,targetChipName);
    668                 if (!targetChip) continue;
    669                 if (!targetChip->cells) continue;
    670                 if (!targetChip->cells->n) continue;
    671 
    672                 pmCell *targetCell = targetChip->cells->data[0];
    673                 if (!targetCell) continue;
    674                 if (!targetCell->readouts) continue;
    675                 if (!targetCell->readouts->n) continue;
    676                 pmReadout *targetReadout = targetCell->readouts->data[0];
    677                 if (!targetReadout) continue;
    678 
    679                 //check if the crosstalk is above the target chip background level
    680                 pmDetEff *tarde = psMetadataLookupPtr(NULL, targetReadout->analysis, PM_DETEFF_ANALYSIS); // Detection efficiency
    681                 if (isnan(tarde->magRef)) { continue; }
    682 
    683                 float TARGET_CROSS_MAX_MAG = tarde->magRef-crossMagOff + MagOffset;
    684                 if (ref->Mag > TARGET_CROSS_MAX_MAG) { continue; }
    685 
    686                 pmAstromObj *crosstalk = pmAstromObjAlloc();
     693                    // Hunt down the readout for the target, and save the chip position and magnitude of source star.
     694                    pmChip *targetChip = getChipByName(fpa,targetChipName);
     695                    if (!targetChip) continue;
     696                    if (!targetChip->cells) continue;
     697                    if (!targetChip->cells->n) continue;
     698
     699                    pmCell *targetCell = targetChip->cells->data[0];
     700                    if (!targetCell) continue;
     701                    if (!targetCell->readouts) continue;
     702                    if (!targetCell->readouts->n) continue;
     703                    pmReadout *targetReadout = targetCell->readouts->data[0];
     704                    if (!targetReadout) continue;
     705
     706                    //check if the crosstalk is above the target chip background level
     707                    pmDetEff *tarde = psMetadataLookupPtr(NULL, targetReadout->analysis, PM_DETEFF_ANALYSIS); // Detection efficiency
     708                    if (isnan(tarde->magRef)) { continue; }
     709
     710                    float TARGET_CROSS_MAX_MAG = tarde->magRef-crossMagOffset[k] + MagOffset;
     711                    if (ref->Mag > TARGET_CROSS_MAX_MAG) { continue; }
     712
     713                    pmAstromObj *crosstalk = pmAstromObjAlloc();
    687714           
    688                 crosstalk->Mag = ref->Mag - MagOffset;
    689                 crosstalk->chip->x = x_t_chip;
    690                 crosstalk->chip->y = y_t_chip;
    691 
    692                 psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS");
    693                 if (crosstalks == NULL) {
    694                   crosstalks = psArrayAllocEmpty(100);
    695                   if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) {
    696                     psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout");
    697                     goto escape;
    698                   }
    699                   psFree(crosstalks);
    700                 }
    701                 psArrayAdd(crosstalks,100,crosstalk);
     715                    crosstalk->Mag = ref->Mag - MagOffset;
     716                    crosstalk->chip->x = x_t_chip;
     717                    crosstalk->chip->y = y_t_chip;
     718
     719                    psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS");
     720                    if (crosstalks == NULL) {
     721                      crosstalks = psArrayAllocEmpty(100);
     722                      if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) {
     723                        psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout");
     724                        goto escape;
     725                      }
     726                      psFree(crosstalks);
     727                    }
     728                    psArrayAdd(crosstalks,100,crosstalk);
    702729           
    703                 psFree(targetChipName);
    704                 psFree(targetCellName);
    705                 psFree(crosstalk);
    706 
    707                 // Determine if we need to add a spike mask.
    708                 // TdB20210304: This should not be relevant for faint crosstalk rules. Do this rather ad hoc right now by placing a limit at 8 mags of difference
    709                 if( crossMagOff > 8.) { continue; }
    710                 if (ref->Mag < SPIKE_MAX_MAG) {       
    711                   int Xt = X;
    712                   int Yt = Y;
    713                   int Vt = V;
     730                    psFree(targetChipName);
     731                    psFree(targetCellName);
     732                    psFree(crosstalk);
     733
     734                    // Determine if we need to add a spike mask.
     735                    // TdB20210304: This should not be relevant for faint crosstalk rules. Do this rather ad hoc right now by placing a limit at 8 mags of difference
     736                    if( crossMagOffset[k] > 8.) { continue; }
     737                    if (ref->Mag < SPIKE_MAX_MAG) {           
     738                      int Xt = X;
     739                      int Yt = Y;
     740                      int Vt = V;
    714741             
    715                   for (int Ut = 0; Ut < 8; Ut++) {
    716                     psString targetChipName = NULL;
    717                     psStringAppend(&targetChipName,"XY%d%d",Xt,Yt);
    718                     psString targetCellName = NULL;
    719                     psStringAppend(&targetCellName,"xy%d%d",Ut,Vt);
    720                
    721                     psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f [%s %s]",
     742                      for (int Ut = 0; Ut < 8; Ut++) {
     743                        psString targetChipName = NULL;
     744                        psStringAppend(&targetChipName,"XY%d%d",Xt,Yt);
     745                        psString targetCellName = NULL;
     746                        psStringAppend(&targetCellName,"xy%d%d",Ut,Vt);
     747               
     748                        psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f [%s %s]",
    722749                           X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell,
    723750                           targetChipName,targetCellName);
    724751               
    725                     pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName);
    726                     if (!CTtargetCell) continue;
    727                
    728                     pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell);
    729 
    730                     psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f ChipLoc: (%f,%f)",
     752                        pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName);
     753                        if (!CTtargetCell) continue;
     754               
     755                        pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell);
     756
     757                        psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f ChipLoc: (%f,%f)",
    731758                           X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell,x_t_chip,y_t_chip);
    732759               
    733                     // Hunt down the readout for the target, and save the chip position and magnitude of source star.
    734                     pmChip *targetChip = getChipByName(fpa,targetChipName);
    735                     if (!targetChip) continue;
    736                     if (!targetChip->cells) continue;
    737                     if (!targetChip->cells->n) continue;
     760                        // Hunt down the readout for the target, and save the chip position and magnitude of source star.
     761                        pmChip *targetChip = getChipByName(fpa,targetChipName);
     762                        if (!targetChip) continue;
     763                        if (!targetChip->cells) continue;
     764                        if (!targetChip->cells->n) continue;
    738765                 
    739                     pmCell *targetCell = targetChip->cells->data[0];
    740                     if (!targetCell) continue;
    741                     if (!targetCell->readouts) continue;
    742                     if (!targetCell->readouts->n) continue;
    743                     pmReadout *targetReadout = targetCell->readouts->data[0];
    744                     if (!targetReadout) continue;
    745                
    746                     pmAstromObj *crosstalk = pmAstromObjAlloc();
    747                
    748                     crosstalk->Mag = ref->Mag - MagOffset;
    749                     crosstalk->chip->x = x_t_chip;
    750                     crosstalk->chip->y = y_t_chip;
    751                
    752                     psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS.SPIKES");
    753                     if (crosstalks == NULL) {
    754                       crosstalks = psArrayAllocEmpty(100);
    755                       if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS.SPIKES", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) {
    756                         psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout");
    757                         goto escape;
    758                       }
    759                       psFree(crosstalks);
    760                     }
    761                     psArrayAdd(crosstalks,100,crosstalk);
    762                
    763                     psFree(targetChipName);
    764                     psFree(targetCellName);
    765                     psFree(crosstalk);
    766                   }
    767                 } // End satspike crosstalks
     766                        pmCell *targetCell = targetChip->cells->data[0];
     767                        if (!targetCell) continue;
     768                        if (!targetCell->readouts) continue;
     769                        if (!targetCell->readouts->n) continue;
     770                        pmReadout *targetReadout = targetCell->readouts->data[0];
     771                        if (!targetReadout) continue;
     772               
     773                        pmAstromObj *crosstalk = pmAstromObjAlloc();
     774               
     775                        crosstalk->Mag = ref->Mag ;
     776                        crosstalk->chip->x = x_t_chip;
     777                        crosstalk->chip->y = y_t_chip;
     778               
     779                        psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS.SPIKES");
     780                        if (crosstalks == NULL) {
     781                          crosstalks = psArrayAllocEmpty(100);
     782                          if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS.SPIKES", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) {
     783                            psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout");
     784                            goto escape;
     785                          }
     786                          psFree(crosstalks);
     787                        }
     788                        psArrayAdd(crosstalks,100,crosstalk);
     789               
     790                        psFree(targetChipName);
     791                        psFree(targetCellName);
     792                        psFree(crosstalk);
     793                      }
     794                    } // End satspike crosstalks
     795                  } // End rules block
    768796              } // End refMags
    769 
    770797            }
    771798          }
  • trunk/psastro/src/psastroLoadGhosts.c

    r41434 r41657  
    120120
    121121    //We need to check whether we are dealing with an old style ghost_model, or a new style model. Check if the mirror_rad polynomial exists
    122     float mirCheck = 0;
     122    int mirCheck = 0;
    123123    md = psMetadataLookupMetadata (&status, ghostModel, "GHOST.MIRROR.RAD");
    124124    if (!md) { psLogMsg ("psastro", PS_LOG_INFO, "No ghost mirror_rad polynomial found. Assuming old-style ghost masking"); }
     
    144144    pmFPA *fpa = astrom->fpa;
    145145
     146    // select the reference mask fpa :: we use this to determine cell boundaries
     147    pmFPAfile *refMask = psMetadataLookupPtr (NULL, config->files, "PSASTRO.REFMASK");
     148    if (!refMask) {
     149      psError(PSASTRO_ERR_CONFIG, true, "Can't find mask reference");
     150      return false;
     151    }
     152    // Activate the reference mask to generate an FPA structure we can use to map stars down to cells
     153    pmFPAfileActivate (config->files, false, NULL);
     154    pmFPAfileActivate (config->files, true, "PSASTRO.REFMASK");
     155
    146156    // raise an error if the config is broken
    147157    if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &INSTR_MAX_MAG, NULL, fpa, recipe)) {
     
    161171        if (!chip->fromFPA) { continue; }
    162172
     173        // Get the current chip's name, and parse out the grid location.
     174        pmChip *refChip  = pmFPAviewThisChip (view, refMask->fpa);
     175        const char *chipName = psMetadataLookupStr(NULL,refChip->concepts, "CHIP.NAME");
     176        int X = chipName[2] - '0';
     177        int Y = chipName[3] - '0';
     178
     179        //Check if we are in the central 8 chips, where old ghost-style locations work better
     180        int cenChip = 0;
     181        if ( (Y >= 3)&&(Y <=4)&&(X >= 2)&&(X <= 5) ) {cenChip = 0;}
     182
    163183        while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
    164184            psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     
    188208
    189209                    double rSrc = hypot (cal->FP->x, cal->FP->y);
    190                     double theta0 = atan2(cal->FP->x,cal->FP->y);
    191 
    192                     if(mirCheck) {
     210                    double theta0 = atan2(cal->FP->y,cal->FP->x);
     211
     212                    if((mirCheck) & (!cenChip)) {
    193213                         //TdB: first mirror the reference star positions (around the 0,0 pixel) using the radial offset coefficients and the ghost/star angle
    194214                        double ghost_offset_rad = psPolynomial1DEval (mirrorRad, rSrc);
     
    200220                        ghost->FP->y = ghost_y_fpa_mirror + psPolynomial2DEval(centerY, ghost_x_fpa_mirror, ghost_y_fpa_mirror);
    201221                    } 
    202                     if(!mirCheck) {
     222                    if((!mirCheck) | cenChip) {
    203223                        //Use the old-style ghost position determination
    204224                        ghost->FP->x = -cal->FP->x + psPolynomial2DEval(centerX, -cal->FP->x, -cal->FP->y);
     
    312332                    double theta0 = atan2(ref->FP->y,ref->FP->x);
    313333
    314                     if(mirCheck) {
     334                    if((mirCheck) & (!cenChip)) {
    315335                         //TdB: first mirror the reference star positions (around the 0,0 pixel) using the radial offset coefficients and the ghost/star angle
    316336                        double ghost_offset_rad = psPolynomial1DEval (mirrorRad, rSrc);
     
    322342                        ghost->FP->y = ghost_y_fpa_mirror + psPolynomial2DEval(centerY, ghost_x_fpa_mirror, ghost_y_fpa_mirror);
    323343                    } 
    324                     if(!mirCheck) {
     344                    if((!mirCheck) | cenChip) {
    325345                        //Use the old-style ghost position determination
    326346                        ghost->FP->x = -ref->FP->x + psPolynomial2DEval(centerX, -ref->FP->x, -ref->FP->y);
  • trunk/psastro/src/psastroMaskUpdates.c

    r41551 r41657  
    127127    }
    128128    psLogMsg ("psastro", PS_LOG_INFO, "generating a bright-star mask");
    129     
     129 
    130130    bool REFSTAR_MASK_BLEED                = psMetadataLookupBool (&status, recipe, "REFSTAR_MASK_BLEED");
    131131    bool REFSTAR_MASK_BLEED_ORIENTATION_X  = psMetadataLookupBool (&status, recipe, "REFSTAR_MASK_BLEED_ORIENTATION_X");
     
    479479                            ref->chip->x,ref->chip->y,ref->Mag,radius);
    480480                    // XXX for now, assume cell binning is 1x1 relative to chip
    481                     psastroMaskCircle (readoutMask->mask, crosstalkMaskValue, ref->chip->x, ref->chip->y, radius, radius);
     481                    //For the moment, make the crostalk masks into ovals by doing a simple 1:2 scaling with radius. Not ideal, but better until we can get more examples.
     482                    psastroMaskCircle (readoutMask->mask, crosstalkMaskValue, ref->chip->x, ref->chip->y, radius/2., radius);
    482483                  }
    483484                }
Note: See TracChangeset for help on using the changeset viewer.