Changeset 17935
- Timestamp:
- Jun 5, 2008, 3:29:09 AM (18 years ago)
- Location:
- branches/eam_branch_20080511/ppSim/src
- Files:
-
- 6 edited
-
ppSimCreate.c (modified) (1 diff)
-
ppSimInsertStars.c (modified) (2 diffs)
-
ppSimLoadForceSources.c (modified) (1 diff)
-
ppSimLoadSpots.c (modified) (5 diffs)
-
ppSimLoop.c (modified) (1 diff)
-
ppSimPhotomReadout.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080511/ppSim/src/ppSimCreate.c
r17818 r17935 29 29 // generate the fpa structure used by the output camera (determined from INPUT or specified) 30 30 assert (config->camera); 31 fpa = pmFPAConstruct(config->camera ); // FPA to contain the observation31 fpa = pmFPAConstruct(config->camera, config->cameraName); // FPA to contain the observation 32 32 if (!fpa) { 33 33 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to construct an FPA from camera configuration."); -
branches/eam_branch_20080511/ppSim/src/ppSimInsertStars.c
r17850 r17935 114 114 source->errMag = sqrt(Area*PS_SQR(roughNoise) + flux) / flux; 115 115 116 // XXX add the sources to a source array117 118 116 // insert the source flux in the image 119 117 pmSourceAddWithOffset (source, PM_MODEL_OP_FULL, 0xff, dX, dY); 120 118 pmSourceAddWithOffset (source, PM_MODEL_OP_FULL | PM_MODEL_OP_NOISE, 0xff, dX, dY); 121 psArrayAdd (sources, 100,source);122 psFree(source); // Drop reference123 119 124 120 // Blow away the image parts of the source, which makes the memory explode … … 130 126 RESET(source->psfFlux); 131 127 RESET(source->blends); 128 129 // add the sources to the source array 130 psArrayAdd (sources, 100,source); 131 psFree(source); // Drop reference 132 132 } 133 133 -
branches/eam_branch_20080511/ppSim/src/ppSimLoadForceSources.c
r17930 r17935 1 1 # include "ppSim.h" 2 3 // Reset a pointer: free and set to NULL 4 #define RESET(PTR) \ 5 psFree(PTR); \ 6 PTR = NULL; 2 7 3 8 psArray *ppSimLoadForceSources(pmConfig *config, const pmFPAview *view) { 4 9 5 psArray *result = psArrayAlloc(0); 6 return result; 10 bool status; 7 11 8 # if (0) 12 pmFPAfile *outFile = psMetadataLookupPtr(NULL, config->files, "PPSIM.OUTPUT"); 13 psAssert(outFile, "missing PPSIM.OUTPUT"); 14 psAssert(outFile->fpa, "missing fpr for PPSIM.OUTPUT"); 9 15 10 // de-activate all files except PSASTRO.REFSTARS11 pm FPAfileActivate (config->files, false, NULL);12 pmFPAfileActivate (config->files, true, "PSASTRO.OUT.REFSTARS");16 pmChip *outChip = pmFPAviewThisChip (view, outFile->fpa); 17 pmPSF *psf = psMetadataLookupPtr (&status, outChip->analysis, "PSPHOT.PSF"); 18 assert (psf); 13 19 14 readout = pmFPAviewThisReadout (view, fpa);15 if (! readout->data_exists) { continue; }20 psArray *spots = psMetadataLookupPtr(&status, outFile->fpa->analysis, "FORCED.SPOTS"); 21 PS_ASSERT_PTR_NON_NULL (spots, NULL); 16 22 17 // read WCS data from the corresponding header 18 pmHDU *hdu = pmFPAviewThisHDU (view, fpa); 23 // in this program, we are looping over the output image, rather than the input as in ppImage 24 pmFPAfile *srcFile = psMetadataLookupPtr(NULL, config->files, "PPSIM.REAL.SOURCES"); 25 psAssert(srcFile, "missing PPSIM.REAL.SOURCES"); 19 26 20 int Nx = psMetadataLookupS32 (&status, hdu->header, "NAXIS1"); 21 int Ny = psMetadataLookupS32 (&status, hdu->header, "NAXIS2"); 27 pmFPA *fpa = srcFile->fpa; 28 pmChip *chip = pmFPAviewThisChip (view, fpa); 29 // pmCell *cell = pmFPAviewThisCell (view, fpa); 30 pmReadout *readout = pmFPAviewThisReadout (view, fpa); 22 31 23 float minX = -fieldPadding*Nx; 24 float maxX = (1+fieldPadding)*Nx; 25 float minY = -fieldPadding*Ny; 26 float maxY = (1+fieldPadding)*Ny; 32 // XXX we should have only one cell and readout per chip, right? 27 33 28 // the refstars is a subset within range of this chip 29 psArray *refstars = psArrayAllocEmpty (100); 34 // read WCS from existing output from psphot & psastro 35 // XXX can we be more flexible? ie, use the header of PPSIM.CHIP? 36 bool bilevelAstrometry = false; 37 status = psastroAstromGuessSetFPA (fpa, &bilevelAstrometry); 38 psAssert (status, "failed to set astrometry"); 30 39 31 // select the reference objects within range of this readout 32 // project the reference objects to this chip 33 for (int i = 0; i < refs->n; i++) { 34 pmAstromObj *ref = pmAstromObjCopy(refs->data[index->data.S32[i]]); 40 // the pixel scale is only used to set the focal-plane coordinate system 41 // setting this value to 1 makes this system have the units of pixels 42 float pixelScale = 1.0; 43 status = psastroAstromGuessSetChip (fpa, chip, view, pixelScale, bilevelAstrometry); 44 psAssert (status, "failed to set astrometry"); 35 45 36 psProject (ref->TP, ref->sky, fpa->toSky); 37 psPlaneTransformApply (ref->FP, fpa->fromTPA, ref->TP); 38 psPlaneTransformApply (ref->chip, chip->fromFPA, ref->FP); 46 float minX = 0.0; 47 float maxX = readout->image->numCols; 48 float minY = 0.0; 49 float maxY = readout->image->numRows; 39 50 40 // limit the X,Y range of the refs to the selected chip 41 if (ref->chip->x < minX) goto skip; 42 if (ref->chip->x > maxX) goto skip; 43 if (ref->chip->y < minY) goto skip; 44 if (ref->chip->y > maxY) goto skip; 51 // the sources is a subset within range of this chip 52 psArray *sources = psArrayAllocEmpty (100); 45 53 46 psArrayAdd (refstars, 100, ref);47 skip:48 psFree (ref);54 // Select the spots within range of this readout. Project the spots to this chip 55 for (int i = 0; i < spots->n; i++) { 56 pmAstromObj *obj = spots->data[i]; 49 57 50 if (nMax && (refstars->n >= nMax)) break;51 } 52 psTrace ("psastro", 4, "Added %ld refstars\n", refstars->n);58 psProject (obj->TP, obj->sky, fpa->toSky); 59 psPlaneTransformApply (obj->FP, fpa->fromTPA, obj->TP); 60 psPlaneTransformApply (obj->chip, chip->fromFPA, obj->FP); 53 61 54 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSASTRO.REFSTARS", PS_DATA_ARRAY, "astrometry matches", refstars); 55 psFree (refstars); 62 // limit the X,Y range of the objs to the selected chip 63 if (obj->chip->x < minX) continue; 64 if (obj->chip->x > maxX) continue; 65 if (obj->chip->y < minY) continue; 66 if (obj->chip->y > maxY) continue; 56 67 57 if (matchLumFunc) { 58 // in this case, no PSASTRO.REFSTARS is added to readout->analysis 59 if (!psastroRefstarSubset (readout)) { 60 psError(PSASTRO_ERR_DATA, false, "Can't determine an appropriate refstar subset\n"); 61 psFree (index); 62 psFree (view); 63 return false; 64 } 65 } 66 } 67 } 68 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE; 68 // convert the pmAstromObj to pmSource 69 70 // instantiate a model for the PSF at this location, Io = 1.0 71 pmModel *model = pmModelFromPSFforXY (psf, obj->chip->x, obj->chip->y, 1.0); 72 73 // XXX let the flux limit be a user-defined number of sky sigmas (not just 1.0) 74 // XXX use a fixed radius?? 75 // float radius = model->modelRadius (model->params, roughNoise); 76 // radius = PS_MAX (radius, 1.0); 77 float radius = 5.0; 78 79 // construct a source, with model flux pixels set, based on the model 80 pmSource *source = pmSourceFromModel (model, readout, radius, PM_SOURCE_TYPE_STAR); 81 82 // XXX set the mag & err values (should this be done in pmSourceFromModel?) 83 // XXX i should be applying the gain and the correct effective area 84 // psEllipseAxes axes = pmPSF_ModelToAxes (model->params->data.F32, 20.0); 85 // psF64 Area = 2.0 * M_PI * axes.major * axes.minor; 86 87 // these are not really needed since we will be fitting for them 88 source->psfMag = NAN; 89 source->errMag = NAN; 90 91 // insert the source flux in the image 92 // XXX not sure the offset is really 0,0 93 pmSourceAddWithOffset (source, PM_MODEL_OP_FULL, 0xff, 0.0, 0.0); 94 pmSourceAddWithOffset (source, PM_MODEL_OP_FULL | PM_MODEL_OP_NOISE, 0xff, 0.0, 0.0); 95 96 // Blow away the image parts of the source, which makes the memory explode 97 RESET(source->pixels); 98 RESET(source->weight); 99 RESET(source->maskObj); 100 RESET(source->maskView); 101 RESET(source->modelFlux); 102 RESET(source->psfFlux); 103 RESET(source->blends); 104 105 psArrayAdd (sources, 100, source); 106 psFree(source); // Drop local reference 69 107 } 70 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;108 psTrace ("psastro", 4, "Added %ld sources\n", sources->n); 71 109 72 // activate all files except PSASTRO.OUTPUT 73 74 pmFPAfileActivate (config->files, true, NULL); 75 pmFPAfileActivate (config->files, false, "PSASTRO.OUT.REFSTARS"); 76 # endif 77 78 return NULL; 110 return sources; 79 111 } -
branches/eam_branch_20080511/ppSim/src/ppSimLoadSpots.c
r17930 r17935 1 1 # include "ppSim.h" 2 2 3 // need to specify an alternative CATDIR for the force positions 4 bool ppSimLoadSpots (psArray *spots, pmFPA *fpa, pmConfig *config) { 3 // Load the relevant forced-photometry positions for this field. This function does not determine 4 // the pixel coordinates, merely the celestial coordinates for sources in the general vicinity. The 5 // sources are saved on the fpa->analysis metadata as FORCED.SPOTS. We always create an entry; it 6 // will be empty if no sources were selected or forced photometry is not desired. 7 bool ppSimLoadSpots (pmFPA *fpa, pmConfig *config) { 5 8 6 9 bool status; 10 11 psArray *spots = psArrayAllocEmpty (1); 12 psMetadataAddPtr (fpa->analysis, PS_LIST_TAIL, "FORCED.SPOTS", PS_META_REPLACE, "forced photometry positions", spots); 13 psFree (spots); // free the extra (local) reference; a copy remains on fpa->analysis 7 14 8 15 psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe … … 15 22 if (!astroRecipe) { 16 23 psError(PSASTRO_ERR_CONFIG, false, "Can't find recipe %s", PSASTRO_RECIPE); 17 return NULL;24 return false; 18 25 } 19 26 … … 22 29 float scale = psMetadataLookupF32(NULL, recipe, "PIXEL.SCALE") * M_PI / 3600.0 / 180.0; // Plate scale (radians/pixel) 23 30 31 char *catdir = psMetadataLookupStr(NULL, recipe, "FORCED.CATDIR"); 32 char *photcode = psMetadataLookupStr(NULL, recipe, "FORCED.PHOTCODE"); 33 float MAGmax = 100.0; 34 24 35 // Size of FPA 25 36 psRegion *bounds = ppSimFPABounds (fpa); … … 27 38 psFree(bounds); 28 39 29 float x0fpa = 0.5*(bounds->x0 + bounds->x1); 30 float y0fpa = 0.5*(bounds->y0 + bounds->y1); 40 // modify the PSASTRO recipe to use the values desired for FORCED.PHOT. we can use a view on 41 // the PSASTRO recipe because we are not calling psastro elsewhere in this program. XXX need to 42 // use the WCS to define the overlap region 43 psMetadataAddStr(astroRecipe, PS_LIST_TAIL, "DVO.CATDIR", PS_META_REPLACE, "", catdir); 44 psMetadataAddF32(astroRecipe, PS_LIST_TAIL, "RA_MIN", PS_META_REPLACE, "", ra0 - radius); 45 psMetadataAddF32(astroRecipe, PS_LIST_TAIL, "RA_MAX", PS_META_REPLACE, "", ra0 + radius); 46 psMetadataAddF32(astroRecipe, PS_LIST_TAIL, "DEC_MIN", PS_META_REPLACE, "", dec0 - radius); 47 psMetadataAddF32(astroRecipe, PS_LIST_TAIL, "DEC_MAX", PS_META_REPLACE, "", dec0 + radius); 48 49 // XXX these two values are somewhat bogus: can we have psastroLoadRefstars optionally ignore photcode and MAGmax? 50 psMetadataAddStr(astroRecipe, PS_LIST_TAIL, "DVO.GETSTAR.PHOTCODE", PS_META_REPLACE, "", photcode); 51 psMetadataAddF32(astroRecipe, PS_LIST_TAIL, "DVO.GETSTAR.MAG.MAX", PS_META_REPLACE, "", MAGmax); 31 52 32 // XXX need to use the WCS to define the overlap region33 psMetadataAdd(astroRecipe, PS_LIST_TAIL, "RA_MIN", PS_DATA_F32 | PS_META_REPLACE, "", ra0 - radius);34 psMetadataAdd(astroRecipe, PS_LIST_TAIL, "RA_MAX", PS_DATA_F32 | PS_META_REPLACE, "", ra0 + radius);35 psMetadataAdd(astroRecipe, PS_LIST_TAIL, "DEC_MIN", PS_DATA_F32 | PS_META_REPLACE, "", dec0 - radius);36 psMetadataAdd(astroRecipe, PS_LIST_TAIL, "DEC_MAX", PS_DATA_F32 | PS_META_REPLACE, "", dec0 + radius);37 53 psArray *refStars = psastroLoadRefstars(config); 38 54 if (!refStars || refStars->n == 0) { 39 55 psError(PS_ERR_UNKNOWN, false, "Unable to find reference stars."); 40 56 psFree(refStars); 41 return NULL;57 return false; 42 58 } 43 59 psLogMsg("ppSim", PS_LOG_INFO, "Adding %ld reference stars", refStars->n); 44 60 45 61 // convert the pmAstromObj sources to the storage format used by the CMF files 46 47 long oldSize = spots->n; 48 spots = psArrayRealloc (spots, oldSize + refStars->n); 49 50 // Conversion loop 62 psArrayRealloc (spots, refStars->n); 51 63 for (long i = 0; i < refStars->n; i++) { 52 64 ppSimStar *spot = ppSimStarAlloc (); … … 62 74 // spot->y = sin(pa) * xi + cos(pa) * eta + y0fpa; 63 75 64 spots->data[ oldSize + i] = star;76 spots->data[i] = spot; 65 77 66 78 psTrace("ppSim", 10, "Adding catalogue star: %.1f,%.1f --> %.2f\n", spot->x, spot->y, ref->Mag); 67 79 } 68 80 69 // XXX these need to be saved on PSPHOT.INPUT.CMF70 81 return true; 71 82 } -
branches/eam_branch_20080511/ppSim/src/ppSimLoop.c
r17930 r17935 27 27 int binning = psMetadataLookupS32(NULL, recipe, "BINNING"); // Binning in x and y 28 28 29 psArray *spots = psArrayAllocEmpty (1);30 29 psArray *stars = psArrayAllocEmpty (1); 31 30 psArray *galaxies = psArrayAllocEmpty (1); 32 31 if (type == PPSIM_TYPE_OBJECT) { 33 // Load forced-photometry positions 34 if (!ppSimLoadSpots ( spots,fpa, config)) ESCAPE (PS_ERR_UNKNOWN, "failed to load forced-photometry spots");32 // Load forced-photometry positions (these are placed on fpa->analysis for use in ppSimPhotomReadout) 33 if (!ppSimLoadSpots (fpa, config)) ESCAPE (PS_ERR_UNKNOWN, "failed to load forced-photometry spots"); 35 34 36 35 // Load catalogue stars -
branches/eam_branch_20080511/ppSim/src/ppSimPhotomReadout.c
r17901 r17935 37 37 } 38 38 39 # if 0 39 40 // set the photcode for this image 40 41 if (!psphotAddPhotcode (recipe, config, view, "PPSIM.CHIP")) { … … 42 43 return false; 43 44 } 45 # endif 44 46 45 47 // find the currently selected readout. … … 119 121 psFree (sources); // only frees the merged references 120 122 121 // linear fit to real + forced sources 122 sources = ppSimMergeSources (realSources, forceSources); 123 psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE); // XXX option to NOT subtract 124 psphotReplaceAllSources (sources, recipe); 125 psFree (sources); // only frees the merged references 123 // linear fit to real + forced sources (if any were selected) 124 if (forceSources->n) { 125 sources = ppSimMergeSources (realSources, forceSources); 126 psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE); // XXX option to NOT subtract 127 psphotReplaceAllSources (sources, recipe); 128 psFree (sources); // only frees the merged references 129 } 126 130 127 131 // XXX do we need to measure aperture photometry corrections? … … 157 161 psMetadataAdd (fakeReadout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY, "fake photometry ", fakeSources); 158 162 159 //psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PPSIM.FORCE.SOURCES", PS_DATA_ARRAY, "forced photometry ", forceSources);163 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PPSIM.FORCE.SOURCES", PS_DATA_ARRAY, "forced photometry ", forceSources); 160 164 psFree (forceSources); 161 165 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
