Changeset 36075
- Timestamp:
- Aug 30, 2013, 4:55:55 PM (13 years ago)
- Location:
- branches/eam_branches/ipp-20130711
- Files:
-
- 9 edited
-
. (modified) (1 prop)
-
PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm (modified) (16 diffs)
-
PS-IPP-PStamp/lib/PS/IPP/PStamp/RequestFile.pm (modified) (4 diffs)
-
ppSub/src/ppSubMatchPSFs.c (modified) (2 diffs)
-
psModules (modified) (1 prop)
-
psModules/src/imcombine/pmSubtractionMatch.c (modified) (1 diff)
-
psModules/src/imcombine/pmSubtractionSimple.c (modified) (7 diffs)
-
psModules/src/imcombine/pmSubtractionSimple.h (modified) (1 diff)
-
psModules/src/objects/pmPSFtryFitPSF.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20130711
- Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20130711/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm
r35625 r36075 34 34 use POSIX; 35 35 use Time::HiRes qw(gettimeofday); 36 use IO::Handle; 36 37 37 38 my $dvo_verbose = 0; … … 176 177 $need_magic, $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, 177 178 0, 0, # fwhm cuts are not applied here 178 undef, undef, undef, $verbose); 179 undef, 0, # no cam run information 180 undef, undef, $verbose); 179 181 180 182 return $results; … … 243 245 if (isnull($filter)) { 244 246 $filter = undef; 247 } 248 249 if ($stage eq 'stack_summary') { 250 # stack_summary jobs are so different from others that we lookup in a specialized function 251 return lookup_stack_summary($ipprc, $row, $imagedb, $tess_id, $component, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose); 245 252 } 246 253 … … 322 329 0, $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, 323 330 getValOrZero($row->{FWHM_MIN}), getValOrZero($row->{FWHM_MAX}), 324 undef, $release_name, $survey,331 undef, 0, $release_name, $survey, 325 332 $verbose); 326 333 … … 351 358 my $fwhm_max = shift; 352 359 my $selectedAstrom = shift; 360 my $selected_cam_id = shift; 353 361 my $release_name = shift; 354 362 my $survey = shift; … … 602 610 # The image selectors are such that multiple runs my have be returned for the same exposure. 603 611 # Return only the latest one. 604 $images = filterRuns($stage, $ need_magic, $images, $inverse, $verbose);612 $images = filterRuns($stage, $choose_components, $need_magic, $images, $inverse, $verbose); 605 613 } 606 614 … … 699 707 $out->{astrom} = $selectedAstrom; 700 708 $out->{cam_path_base} = $selectedAstrom; 709 $out->{cam_id} = $selected_cam_id if $selected_cam_id; 701 710 if ($selectedAstrom =~ /\.smf$/) { 702 711 $out->{cam_path_base} =~ s/\.smf$//; … … 731 740 732 741 return $output; 742 } 743 744 sub lookup_stack_summary { 745 my ($ipprc, $row, $imagedb, $tess_id, $component, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose) = @_; 746 747 $row->{error_code} = $PSTAMP_NO_IMAGE_MATCH; 748 749 $component = '' if $component eq 'all'; 750 751 my $req_type = $row->{REQ_TYPE}; 752 my $results; 753 if ($req_type eq 'byid') { 754 my $sass_id = $row->{ID}; 755 my $command = "$stacktool -dbname $imagedb -summary -sass_id $sass_id"; 756 $results = runToolAndParse($command, $verbose); 757 } else { 758 my ($release_name, $survey, $default_tess_id) = get_release_info($row); 759 if (!$tess_id and $default_tess_id) { 760 $tess_id = $default_tess_id; 761 } 762 763 my $skycells; 764 if ($req_type eq 'bycoord') { 765 my $ra = $row->{CENTER_X}; 766 my $dec = $row->{CENTER_Y}; 767 $skycells = lookup_skycell_by_coords($ipprc, $tess_id, $component, $ra, $dec, $verbose); 768 } elsif ($req_type eq 'byskycell') { 769 if (!defined $tess_id or !defined $component) { 770 print STDERR "Error: TESS_ID and COMPONENT are required for REQ_TYPE byskycell\n"; 771 $row->{error_code} = $PSTAMP_INVALID_REQUEST; 772 } 773 my $skycell = { 774 tess_id => $tess_id, 775 component => $component 776 }; 777 push @$skycells, $skycell 778 } else { 779 print STDERR "Error: $req_type is not a valid REQ_TYPE for IMG_TYPE stack_summary\n"; 780 $row->{error_code} = $PSTAMP_INVALID_REQUEST; 781 return undef; 782 } 783 784 if ($skycells) { 785 # We have a list of skycells. Find matching projection cells. 786 # and then matching rows in stackSummary 787 788 my %projection_cells_found; 789 foreach my $skycell (@$skycells) { 790 my $tess_id = $skycell->{tess_id}; 791 my $skycell_id = $skycell->{component}; 792 793 my $projection_cell = skycell_id_to_projection_cell($skycell_id); 794 795 # only need to include a projection cell once 796 next if $projection_cells_found{$projection_cell}; 797 798 $projection_cells_found{$projection_cell} = 1; 799 800 # print "$tess_id $skycell_id $projection_cell\n"; 801 802 my $command; 803 if ($release_name or $survey) { 804 $command = "$releasetool -dbname $imagedb"; 805 if ($release_name) { 806 $command .= " -release_name $release_name"; 807 } else { 808 $command .= " -priority_order"; 809 } 810 $command .= " -surveyName $survey"; 811 } else { 812 $command = "$stacktool -dbname $imagedb"; 813 } 814 $command .= " -summary -tess_id $tess_id"; 815 $command .= " -projection_cell $projection_cell"; 816 817 $command .= " -filter $filter" if $filter; 818 $command .= " -data_group $data_group" if $data_group; 819 820 my $these_results = runToolAndParse($command, $verbose); 821 push @$results, @$these_results if $these_results; 822 } 823 } 824 } 825 826 if ($results) { 827 foreach my $summary (@$results) { 828 my $path_base = $summary->{path_base}; 829 my $projection_cell = $summary->{projection_cell}; 830 831 # we need to flesh out the hashes returned with values that the parser expects 832 $summary->{stage} = 'stack_summary'; 833 $summary->{component} = $projection_cell; 834 $summary->{stage_id} = $summary->{sass_id}; 835 $summary->{path_base} = "$path_base.$projection_cell"; 836 837 # The stack_summary stage doesn't follow the usual ipp conventions for file rules 838 # and path_base. We leave it up to the program that runs the job to handle this. 839 # However, the parser uses the image parameter to set the job's outputBase (by removing the .fits) 840 # so we need to set it. Just use the new path_base. 841 $summary->{image} = $summary->{path_base}; 842 $summary->{state} = 'full'; 843 $summary->{data_state} = 'full'; 844 $summary->{fault} = 0; 845 $summary->{imagedb} = $imagedb; 846 $summary->{row_index} = []; 847 push @{$summary->{row_index}}, 0; 848 849 # XXX: Are there any other required parameters? 850 # TODO: create a function to validate the components returned 851 # and make sure that any required elements are there. 852 } 853 } 854 855 return $results; 733 856 } 734 857 … … 946 1069 $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, 947 1070 $fwhm_min, $fwhm_max, 948 $chip->{astrom}, undef, undef,1071 $chip->{astrom}, $chip->{cam_id}, undef, undef, 949 1072 $verbose); 950 1073 … … 970 1093 $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, 971 1094 $fwhm_min, $fwhm_max, 972 undef, $release_name, $survey,1095 undef, 0, $release_name, $survey, 973 1096 $verbose); 974 1097 … … 1166 1289 1167 1290 my @lines; 1168 { 1291 my $looked_up_fast; 1292 if ($requested_tess_id) { 1293 # try using the last method first 1294 $looked_up_fast = lookup_skycells_fast($ipprc, \@lines, $requested_tess_id, $ra, $dec, $verbose); 1295 } 1296 1297 if (!$looked_up_fast) { 1169 1298 my $command = "$whichimage $ra $dec"; 1170 1299 $command .= " --tess_id $requested_tess_id" if $requested_tess_id; … … 1302 1431 $image->{astrom} = $astromFile; 1303 1432 $image->{cam_path_base} = $camRoot; 1433 $image->{cam_id} = $camRun->{cam_id}; 1304 1434 1305 1435 return 1; … … 1649 1779 sub filterRuns { 1650 1780 my $stage = shift; 1781 my $drop_duplicate_runs = shift; 1651 1782 my $need_magic = shift; 1652 1783 my $inputs = shift; … … 1694 1825 } 1695 1826 1696 $printed = 1 if (($exp_id == $last_exp_id) and ($run_id == $last_run_id));1827 # $printed = 1 if (($exp_id == $last_exp_id) and ($run_id == $last_run_id)); 1697 1828 1698 1829 # skip if we need magicked run and this one has never been magicked … … 1702 1833 } 1703 1834 1704 if (($exp_id == $last_exp_id) and ($ run_id != $last_run_id)) {1835 if (($exp_id == $last_exp_id) and ($drop_duplicate_runs || ($run_id != $last_run_id))) { 1705 1836 print "Skipping duplicate ${stage}Run $run_id for $exp_id\n" if !$printed; 1706 1837 next; … … 1873 2004 return $diff_mode; 1874 2005 } 2006 2007 sub setErrorCodesForRows { 2008 my $rowList = shift; 2009 my $error_code = shift; 2010 2011 foreach my $row (@$rowList) { 2012 $row->{error_code} = $error_code; 2013 } 2014 2015 } 2016 2017 # Convert from skycell_id to projection_cell 2018 # This code is not particularly elegant but I think that it matches the SQL used 2019 # to create stackAssocations does. 2020 2021 sub skycell_id_to_projection_cell { 2022 my $skycell_id = shift; 2023 2024 # split skycell_id into '.' separated components 2025 my @strs = split '\.', $skycell_id; 2026 2027 my $num = scalar @strs; 2028 2029 # projection_cell is 'skycell_id' plus all .num values except the last one 2030 my $projection_cell = $strs[0]; 2031 for (my $i=1; $i < $num - 1; $i++) { 2032 $projection_cell .= ".$strs[$i]"; 2033 } 2034 2035 return $projection_cell; 2036 } 2037 2038 # lookup_skycells_fast() 2039 # Lookup using a "skycell server" process which is implemented by running dvoImagesAtCoords in "server" mode. 2040 # Repeated calls to this function will reuse an existing process. This avoids having to loading the 2041 # tessellation over and over again for each skycell lookup. 2042 # When this parse process exists, the pipes are closed which causes the skycell server to exit. 2043 2044 my $scs_tess_id; # tess_id for existing scs (skycell server) (if any) 2045 my $scs_out; # reference filehandle for sending data to the scs 2046 my $scs_in; # filehandle for response from scs 2047 2048 sub lookup_skycells_fast { 2049 my ($ipprc, $results, $tess_id, $ra, $dec, $verbose) = @_; 2050 2051 # see if we need to start the scs (skycell server) 2052 2053 if (!$scs_tess_id or ($scs_tess_id ne $tess_id)) { 2054 if ($scs_tess_id) { 2055 # tess_id has changed, close down existing scs 2056 close $scs_out; 2057 $scs_out = undef; 2058 close $scs_in; 2059 $scs_in = undef; 2060 $scs_tess_id = undef; 2061 } 2062 2063 # convert tess_id to a directory name 2064 my $tess_dir = $ipprc->tessellation_catdir( $tess_id ); 2065 unless ($tess_dir) { 2066 print STDERR "Unrecognized tess_id: $tess_id\n"; 2067 return 0; 2068 } 2069 2070 # convert tess_dir to an absolute directory name 2071 my $tess_dir_resolved = $ipprc->convert_filename_absolute( $tess_dir ); 2072 unless ($tess_dir_resolved and -d $tess_dir_resolved) { 2073 print STDERR "failed to resolve tessellation directory for $tess_id\n"; 2074 return 0; 2075 } 2076 2077 # start an scs 2078 2079 # create pipes for communicating with the server 2080 pipe $scs_in, SERVER_WRITER; 2081 pipe SERVER_READER, $scs_out; 2082 2083 # set our output to be unbuffered 2084 $scs_out->autoflush(1); 2085 2086 # FORK 2087 my $scs_pid = fork(); 2088 2089 if (!$scs_pid) { 2090 unless (defined $scs_pid) { 2091 # This is still in parent process. No joy. 2092 print STDERR "fork of skycell server failed: $!"; 2093 return 0; 2094 } 2095 2096 # This code is running in the child process - the skycell server 2097 # Close file handles for the parent's ends of the pipes 2098 close $scs_in; 2099 close $scs_out; 2100 # close stdio filehandles. we are about to redirect them 2101 # (STDERR stays open pointing to the parser log) 2102 close STDIN; 2103 close STDOUT; 2104 2105 # redirect our stdio file handles to the proper end of the pipes 2106 open (STDIN, "<&SERVER_READER") or die "\nSCS: failed to redirect stdin"; 2107 open (STDOUT, ">>&SERVER_WRITER") or die "\nSCS: failed to redirect stdout"; 2108 2109 # All set. Now exec dvoImagesAtCoords 2110 2111 my $command = "$dvoImagesAtCoords -D CATDIR $tess_dir_resolved -coords -"; 2112 2113 print STDERR "SCS: execing $command\n"; 2114 2115 unless(exec $command) { 2116 # note parent will notice that we are gone due to the pipes getting broken 2117 # when this child dies. 2118 die "SCS: failed to exec $command"; 2119 } 2120 } 2121 2122 # This code is running in the parent process (the parser). 2123 # We have succesfully launched the scs process. 2124 # Close file handles for the scs' end of the pipes. 2125 close SERVER_WRITER; 2126 close SERVER_READER; 2127 2128 # remember the tess_id 2129 $scs_tess_id = $tess_id; 2130 } 2131 2132 # send coordinates to the skycell server and wait for the results 2133 # (which come nearly instantly which is the point of doing this) 2134 2135 # If pipes to the skycell server die, don't abort. 2136 # Our reads and writes detect errors and act sensibly. 2137 local $SIG{PIPE} = 'IGNORE'; 2138 2139 # write the coordinates to the pipe 2140 my $write_ok = print $scs_out "1 $ra $dec\n"; 2141 if (!$write_ok) { 2142 # server process probably didn't start properly or died. Fail. 2143 # Caller will attempt to use the conventional method. 2144 print STDERR "write to skycell server failed. Error is $!\n"; 2145 return 0; 2146 } 2147 2148 my $very_verbose = 0; 2149 print STDERR " sent coordinates to skycell server\n" if $very_verbose; 2150 2151 my $received_done = 0; 2152 2153 # Wait for response. If pipe breaks the read returns with no data. 2154 while (my $line = <$scs_in>) { 2155 chomp $line; 2156 if ($line eq 'DONE') { 2157 # No more results for these coordinates. 2158 $received_done = 1; 2159 print STDERR " received DONE\n" if $very_verbose; 2160 last; 2161 } 2162 print STDERR " received $line\n" if $very_verbose; 2163 2164 # The caller expects the output to be in the format used by whichimage 2165 # which omits the point number and includes the tess_id. 2166 my ($ptnum, $raout, $decout, $skycell_id) = split " ", $line; 2167 2168 my $out = "$raout $decout $tess_id $skycell_id"; 2169 2170 # print the result to the log 2171 print "$out\n" if $verbose; 2172 2173 push @$results, $out; 2174 } 2175 2176 print STDERR "Out of wait for responses loop\n" if $very_verbose; 2177 2178 if (!$received_done) { 2179 # something has gone wrong. 2180 print STDERR "Read loop exited without receiving DONE.\n"; 2181 2182 die "BAILING out" if $very_verbose; 2183 2184 # forget about the existing server instance 2185 $scs_tess_id = undef; 2186 close $scs_out; 2187 close $scs_in; 2188 2189 # drop any results received so far 2190 @$results = (); 2191 return 0; 2192 } 2193 2194 return 1; 2195 } 2196 1875 2197 1876 2198 -
branches/eam_branches/ipp-20130711/PS-IPP-PStamp/lib/PS/IPP/PStamp/RequestFile.pm
r35466 r36075 29 29 $PSTAMP_SELECT_BACKMDL 30 30 $PSTAMP_SELECT_JPEG 31 $PSTAMP_SELECT_EXP 32 $PSTAMP_SELECT_NUM 31 33 $PSTAMP_SELECT_UNCOMPRESSED 32 34 $PSTAMP_SELECT_INVERSE … … 71 73 our $PSTAMP_SELECT_BACKMDL = 32; 72 74 our $PSTAMP_SELECT_JPEG = 64; 73 # unused 128 74 # unused 256 75 our $PSTAMP_SELECT_EXP = 128; 76 our $PSTAMP_SELECT_NUM = 256; 75 77 our $PSTAMP_SELECT_UNCOMPRESSED = 512; 76 78 our $PSTAMP_SELECT_INVERSE = 1024; … … 97 99 our $PSTAMP_INVALID_REQUEST = 21; 98 100 our $PSTAMP_UNKNOWN_PROJECT = 22; 99 our $PSTAMP_UNKNOWN_PRODUCT = 22; #this error code was mis-named it is left for compatabiliyt101 our $PSTAMP_UNKNOWN_PRODUCT = 22; #this error code was a typo it is left for compatabiliy 100 102 our $PSTAMP_NO_IMAGE_MATCH = 23; 101 103 our $PSTAMP_NOT_DESTREAKED = 24; 102 104 our $PSTAMP_NOT_AVAILABLE = 25; 103 our $PSTAMP_GONE = 26; # this value is used in ippTools105 our $PSTAMP_GONE = 26; # this value is also used in ippTools 104 106 our $PSTAMP_NO_JOBS_QUEUED = 27; 105 107 our $PSTAMP_NO_OVERLAP = 28; 106 108 our $PSTAMP_NOT_AUTHORIZED = 29; 109 our $PSTAMP_NO_VALID_PIXELS = 30; 107 110 108 111 … … 143 146 PSTAMP_NO_OVERLAP 144 147 PSTAMP_NOT_AUTHORIZED 145 PSTAMP_NO T_AUTHORIZED148 PSTAMP_NO_VALID_PIXELS 146 149 ); 147 150 -
branches/eam_branches/ipp-20130711/ppSub/src/ppSubMatchPSFs.c
r35240 r36075 57 57 if (!pmFPACopy(photFile->fpa, ro->parent->parent->parent)) { 58 58 psError(PPSUB_ERR_CONFIG, false, "Unable to copy FPA for photometry"); 59 return false;59 return NAN; 60 60 } 61 61 … … 76 76 psWarning("Unable to determine PSF."); 77 77 psFree(view); 78 return true;78 return NAN; 79 79 } 80 80 psFree(view); -
branches/eam_branches/ipp-20130711/psModules
- Property svn:mergeinfo changed
/trunk/psModules (added) merged: 35814,35817,35821,35867,35925,35938
- Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20130711/psModules/src/imcombine/pmSubtractionMatch.c
r35771 r36075 540 540 // Bail here if we're doing the simple matching 541 541 if (type == PM_SUBTRACTION_KERNEL_SIMPLE) { 542 if (!pmSubtractionSimpleMatch(conv1,conv2,ro1,ro2,sources,size,maskVal,maskBad,maskPoor )) {542 if (!pmSubtractionSimpleMatch(conv1,conv2,ro1,ro2,sources,size,maskVal,maskBad,maskPoor,optThreshold)) { 543 543 return false; 544 544 } -
branches/eam_branches/ipp-20130711/psModules/src/imcombine/pmSubtractionSimple.c
r35784 r36075 63 63 } 64 64 65 bool simple_apply_mask(psImage *image, psImage *weight, psImage *mask, 66 psImageMaskType maskVal) { 67 for (int y = 0; y < mask->numRows; y++) { 68 for (int x = 0; x < mask->numCols; x++) { 69 if (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal) { 70 image->data.F32[y][x] = NAN; 71 if (weight) { 72 weight->data.F32[y][x] = NAN; 73 } 74 } 75 } 76 } 77 return(true); 78 } 79 80 81 // Copied from pmSubtraction 82 static void solvedKernelPreCalc(psKernel *kernel, // Kernel, updated 83 const pmSubtractionKernels *kernels, // Kernel basis functions 84 float value, // Normalisation value for basis function 85 int index // Index of basis function of interest 86 ) 87 { 88 int size = kernels->size; // Kernel half-size 89 pmSubtractionKernelPreCalc *preCalc = kernels->preCalc->data[index]; // Precalculated values 90 for (int v = -size; v <= size; v++) { 91 for (int u = -size; u <= size; u++) { 92 kernel->kernel[v][u] += value * preCalc->kernel->kernel[v][u]; 93 } 94 } 95 96 return; 97 } 98 //End copy 99 65 100 bool pmSubtractionSimpleMatch(pmReadout *conv1, 66 101 pmReadout *conv2, … … 71 106 psImageMaskType maskVal, 72 107 psImageMaskType maskBad, 73 psImageMaskType maskPoor 108 psImageMaskType maskPoor, 109 float deconvolveThreshold 74 110 ) { 75 111 // 76 112 // We've already validated the input values at this level 77 113 float sig2fwhm = 2.0 * sqrt(2.0 * log(2.0)); 78 float fwhm1 ,fwhm2;79 float sigma1 ,sigma2,sigmaKern;114 float fwhm1 = 0,fwhm2 = 0; 115 float sigma1 = 0,sigma2 = 0,sigmaKern = 0; 80 116 float chisq = 1.0; 81 117 int convolution_direction = 0; 82 psImage *image1; 83 psImage *mask1; 84 psImage *var1; 85 86 psImage *image2; 87 psImage *mask2; 88 psImage *var2; 89 90 psImage *imageC1; 91 psImage *maskC1; 92 psImage *varC1; 93 94 psImage *imageC2; 95 psImage *maskC2; 96 psImage *varC2; 97 118 psImage *image1 = NULL; 119 psImage *mask1 = NULL; 120 psImage *var1 = NULL; 121 122 psImage *image2 = NULL; 123 psImage *mask2 = NULL; 124 psImage *var2 = NULL; 125 126 psImage *imageC1 = NULL; 127 psImage *maskC1 = NULL; 128 psImage *varC1 = NULL; 129 130 psImage *imageC2 = NULL; 131 psImage *maskC2 = NULL; 132 psImage *varC2 = NULL; 133 134 psImage *maskTemp = NULL; 135 98 136 // Allocate images, as this is usually done by subtractionMatchAlloc after this function is called. 99 137 int numCols = ro1->image->numCols; … … 101 139 102 140 if (conv1) { 103 conv1->covariance = psMemIncrRefCounter(ro1->covariance);141 // conv1->covariance = psMemIncrRefCounter(ro1->covariance); 104 142 if (!conv1->image) { 105 143 conv1->image = psImageAlloc(numCols, numRows, PS_TYPE_F32); … … 118 156 } 119 157 if (conv2) { 120 conv2->covariance = psMemIncrRefCounter(ro2->covariance);158 // 121 159 if (!conv2->image) { 122 160 conv2->image = psImageAlloc(numCols, numRows, PS_TYPE_F32); … … 171 209 if (!conv1) { 172 210 if (convolution_direction == 1) { 173 chisq = 100; 174 } 175 convolution_direction = 2; 211 if (sigma1 - sigma2 > deconvolveThreshold) { 212 chisq = 100; 213 } 214 } 215 // convolution_direction = 2; 176 216 } 177 217 if (!conv2) { 178 218 if (convolution_direction == 2) { 179 chisq = 100; 180 } 181 convolution_direction = 1; 219 if (sigma2 - sigma1 > deconvolveThreshold) { 220 chisq = 100; 221 } 222 } 223 // convolution_direction = 1; 182 224 } 183 225 … … 186 228 int maskBox = (int) ceil(sigmaKern * 1.1774); // diameter is 1/2 FWHM 187 229 int maskBlank = 8; // I should be able to get this from a reference, right? 188 189 // 190 // Construct required kernel. No longer needed as we can direct convolve 191 // psVector *kernelVec = pmSubtractionKernelSIMPLE(sigmaKern,0,size); // This is normalized to unity. 192 // psFree(kernelVec); 193 194 // 195 // Do convolutions 196 if (convolution_direction == 1) { 197 psImageSmoothMask_Threaded(imageC1,image1,mask1,maskVal,sigmaKern,6,1e-6); 198 psImageSmoothMask_Threaded(varC1,var1,mask1,maskVal,sigmaKern * M_SQRT1_2,6,1e-6); 199 maskC1 = psImageConvolveMask(maskC1,mask1,maskVal,maskBad, 200 -maskBox,maskBox,-maskBox,maskBox); 201 if (conv2) { 202 imageC2 = psImageCopy(imageC2,image2,PS_TYPE_F32); 203 varC2 = psImageCopy(varC2,var2,PS_TYPE_F32); 204 maskC2 = psImageCopy(maskC2,mask2,PS_TYPE_IMAGE_MASK); 205 } 206 pmSubtractionBorder(imageC1,varC1,maskC1,maskBox,maskBlank); 207 pmSubtractionMaskApply(imageC1,varC1,maskC1,PM_SUBTRACTION_MODE_1); 208 } 209 else if (convolution_direction == 2) { 210 psImageSmoothMask_Threaded(imageC2,image2,mask2,maskVal,sigmaKern,6,1e-6); 211 psImageSmoothMask_Threaded(varC2,var2,mask2,maskVal,sigmaKern * M_SQRT1_2,6,1e-6); 212 maskC2 = psImageConvolveMask(maskC2,mask2,maskVal,maskBad, 213 -maskBox,maskBox,-maskBox,maskBox); 214 if (conv1) { 215 imageC1 = psImageCopy(imageC1,image1,PS_TYPE_F32); 216 varC1 = psImageCopy(varC1,var1,PS_TYPE_F32); 217 maskC1 = psImageCopy(maskC1,mask1,PS_TYPE_IMAGE_MASK); 218 } 219 pmSubtractionBorder(imageC2,varC2,maskC2,maskBox,maskBlank); 220 pmSubtractionMaskApply(imageC2,varC2,maskC2,PM_SUBTRACTION_MODE_2); 221 } 222 223 // 224 // Do normalization 225 float normalization = 1.0; 226 227 // Scan source list, do box photometry on peaks, and then solve the linear relation. 228 int photRadius = (int) floor(PS_MAX(sigma1,sigma2) * 2.0 * sqrt(2.0 * log(2.0))); // Go out a FWHM diameter from the center. 229 psVector *logFluxDifferences = psVectorAlloc(sources->n,PS_TYPE_F32); 230 psVector *fitMask = psVectorAlloc(sources->n,PS_TYPE_VECTOR_MASK); 231 for (int i = 0; i < sources->n; i++) { 232 pmSource *source = sources->data[i]; 233 int nPix1,nPix2; 234 float flux1,flux2; 235 236 if (convolution_direction == 1) { 237 simple_do_boxphot(&nPix1,&flux1,source,imageC1,maskC1,maskBad,photRadius); 238 if (conv2) { 239 simple_do_boxphot(&nPix2,&flux2,source,imageC2,maskC2,maskBad,photRadius); 240 } 241 else { 242 simple_do_boxphot(&nPix2,&flux2,source,image2,mask2,maskBad,photRadius); 243 } 244 } 245 else if (convolution_direction == 2) { 246 simple_do_boxphot(&nPix2,&flux2,source,imageC2,maskC2,maskBad,photRadius); 247 if (conv1) { 248 simple_do_boxphot(&nPix1,&flux1,source,imageC1,maskC1,maskBad,photRadius); 249 } 250 else { 251 simple_do_boxphot(&nPix1,&flux1,source,image1,mask1,maskBad,photRadius); 252 } 253 } 254 logFluxDifferences->data.F32[i] = flux2 - flux1; 255 fitMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0; 256 if ((PS_MIN(nPix1,nPix2) <= 0.75 * PS_MAX(nPix1,nPix2))|| 257 (!isfinite(flux1))||(!isfinite(flux2))) { 258 fitMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0xff; 259 } 260 261 // fprintf(stderr,"SOURCES: %d %g %g %g -> %d %d %g %g %d %g\n",i,source->peak->xf,source->peak->yf,source->psfMag, 262 // nPix1,nPix2,flux1,flux2,fitMask->data.PS_TYPE_VECTOR_MASK_DATA[i],logFluxDifferences->data.F32[i]); 263 264 } 265 266 // Given the differences in log-flux space, the normalization factor is just the exponential of the median difference 267 psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); 268 if (!psVectorStats(stats,logFluxDifferences,NULL,fitMask,0xff)) { 269 // This should complain. 270 normalization = 1.0; 271 } 272 273 normalization = pow(10,stats->robustMedian); 274 // fprintf(stderr,"NORM: %g+/-%g\n",stats->robustMedian,stats->robustStdev); 275 276 psFree(stats); 277 psFree(logFluxDifferences); 278 psFree(fitMask); 279 280 // Apply normalization 281 if (normalization != 1.0) { 282 if ((conv1)&&((convolution_direction == 1))) { 283 psBinaryOp(imageC1,imageC1,"*",psScalarAlloc((float) normalization, PS_TYPE_F32)); 284 psBinaryOp(varC1,varC1,"*",psScalarAlloc((float) PS_SQR(normalization), PS_TYPE_F32)); 285 } 286 else if ((conv2)&&(convolution_direction == 2)) { 287 normalization = 1.0 / normalization; // Because we fit one way, but are using it in the other. 288 psBinaryOp(imageC2,imageC2,"*",psScalarAlloc((float) normalization, PS_TYPE_F32)); 289 psBinaryOp(varC2,varC2,"*",psScalarAlloc((float) PS_SQR(normalization), PS_TYPE_F32)); 290 } 291 } 292 293 230 int maskPoorVal = 16384; // Another value that should be found elsewhere. 294 231 // 295 232 // Make a fake pmSubtractionKernels element so we can add it appropriately. 296 // I call it fake because we've successfully done everything at this point297 // without having to define these things.233 // Defining everything here is a bit clunky, but it's necessary to get the covariance 234 // correct. 298 235 psVector *fwhms = psVectorAlloc(1,PS_TYPE_F32); 299 236 fwhms->data.F32[0] = sigmaKern * sig2fwhm; … … 329 266 kernels->numStamps = sources->n; 330 267 268 psKernel *kernel = psKernelAlloc(-size,size,-size,size); 269 solvedKernelPreCalc(kernel,kernels,1.0,0); 270 271 // 272 // Do convolutions 273 if (convolution_direction == 1) { 274 if (conv1) { 275 psImageSmoothMask_Threaded(imageC1,image1,mask1,maskVal,sigmaKern,6,1e-6); 276 psImageSmoothMask_Threaded(varC1,var1,mask1,maskVal,sigmaKern * M_SQRT1_2,6,1e-6); 277 278 maskTemp = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK); 279 maskTemp = psImageConvolveMask(maskTemp,mask1,maskVal,maskBad, // Mask bad values 280 -maskBox,maskBox,-maskBox,maskBox); 281 maskC1 = psImageConvolveMask(maskC1,maskTemp,maskPoorVal,maskPoor, // Mask poor values 282 -maskBox,maskBox,-maskBox,maskBox); 283 psFree(maskTemp); 284 285 conv1->covariance = psImageCovarianceCalculate(kernel,ro1->covariance); 286 pmSubtractionBorder(imageC1,varC1,maskC1,maskBox,maskBlank); 287 simple_apply_mask(imageC1,varC1,maskC1,maskBad); 288 } 289 if (conv2) { 290 imageC2 = psImageCopy(imageC2,image2,PS_TYPE_F32); 291 varC2 = psImageCopy(varC2,var2,PS_TYPE_F32); 292 maskC2 = psImageCopy(maskC2,mask2,PS_TYPE_IMAGE_MASK); 293 conv2->covariance = psMemIncrRefCounter(ro2->covariance); 294 } 295 } 296 else if (convolution_direction == 2) { 297 if (conv2) { 298 psImageSmoothMask_Threaded(imageC2,image2,mask2,maskVal,sigmaKern,6,1e-6); 299 psImageSmoothMask_Threaded(varC2,var2,mask2,maskVal,sigmaKern * M_SQRT1_2,6,1e-6); 300 301 maskTemp = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK); 302 maskTemp = psImageConvolveMask(maskTemp,mask2,maskVal,maskBad, // Mask bad values 303 -maskBox,maskBox,-maskBox,maskBox); 304 maskC2 = psImageConvolveMask(maskC2,maskTemp,maskPoorVal,maskPoor, // Mask poor values 305 -maskBox,maskBox,-maskBox,maskBox); 306 psFree(maskTemp); 307 308 conv2->covariance = psImageCovarianceCalculate(kernel,ro2->covariance); 309 pmSubtractionBorder(imageC2,varC2,maskC2,maskBox,maskBlank); 310 simple_apply_mask(imageC2,varC2,maskC2,maskBad); 311 } 312 if (conv1) { 313 imageC1 = psImageCopy(imageC1,image1,PS_TYPE_F32); 314 varC1 = psImageCopy(varC1,var1,PS_TYPE_F32); 315 maskC1 = psImageCopy(maskC1,mask1,PS_TYPE_IMAGE_MASK); 316 conv1->covariance = psMemIncrRefCounter(ro1->covariance); 317 } 318 } 319 320 psFree(kernel); // No longer needed after doing covariance calculation 321 322 // 323 // Do normalization 324 float normalization = 1.0; 325 326 // Scan source list, do box photometry on peaks, and then solve the linear relation. 327 int photRadius = (int) floor(PS_MAX(sigma1,sigma2) * 2.0 * sqrt(2.0 * log(2.0))); // Go out a FWHM diameter from the center. 328 psVector *logFluxDifferences = psVectorAlloc(sources->n,PS_TYPE_F32); 329 psVector *fitMask = psVectorAlloc(sources->n,PS_TYPE_VECTOR_MASK); 330 for (int i = 0; i < sources->n; i++) { 331 pmSource *source = sources->data[i]; 332 int nPix1,nPix2; 333 float flux1,flux2; 334 335 if (conv1) { 336 simple_do_boxphot(&nPix1,&flux1,source,imageC1,maskC1,maskBad,photRadius); 337 } 338 else { 339 simple_do_boxphot(&nPix1,&flux1,source,image1,mask1,maskBad,photRadius); 340 } 341 342 if (conv2) { 343 simple_do_boxphot(&nPix2,&flux2,source,imageC2,maskC2,maskBad,photRadius); 344 } 345 else { 346 simple_do_boxphot(&nPix2,&flux2,source,image2,mask2,maskBad,photRadius); 347 } 348 349 logFluxDifferences->data.F32[i] = flux2 - flux1; 350 fitMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0; 351 if ((PS_MIN(nPix1,nPix2) <= 0.75 * PS_MAX(nPix1,nPix2))|| 352 (!isfinite(flux1))||(!isfinite(flux2))) { 353 fitMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = 0xff; 354 } 355 356 // fprintf(stderr,"SOURCES: %d %g %g %g -> %d %d %g %g %d %g\n",i,source->peak->xf,source->peak->yf,source->psfMag, 357 // nPix1,nPix2,flux1,flux2,fitMask->data.PS_TYPE_VECTOR_MASK_DATA[i],logFluxDifferences->data.F32[i]); 358 } 359 360 // Given the differences in log-flux space, the normalization factor is just the exponential of the median difference 361 psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); 362 if (!psVectorStats(stats,logFluxDifferences,NULL,fitMask,0xff)) { 363 // This should complain. 364 normalization = 1.0; 365 } 366 367 normalization = pow(10,stats->robustMedian); 368 // fprintf(stderr,"NORM: %g+/-%g\n",stats->robustMedian,stats->robustStdev); 369 370 psFree(stats); 371 psFree(logFluxDifferences); 372 psFree(fitMask); 373 374 // Apply normalization 375 if (normalization != 1.0) { 376 if ((conv1)&&((convolution_direction == 1))) { 377 psBinaryOp(imageC1,imageC1,"*",psScalarAlloc((float) normalization, PS_TYPE_F32)); 378 psBinaryOp(varC1,varC1,"*",psScalarAlloc((float) PS_SQR(normalization), PS_TYPE_F32)); 379 } 380 else if ((conv2)&&(convolution_direction == 2)) { 381 normalization = 1.0 / normalization; // Because we fit one way, but are using it in the other. 382 psBinaryOp(imageC2,imageC2,"*",psScalarAlloc((float) normalization, PS_TYPE_F32)); 383 psBinaryOp(varC2,varC2,"*",psScalarAlloc((float) PS_SQR(normalization), PS_TYPE_F32)); 384 } 385 } 386 387 388 // 389 331 390 // 332 391 // Actually add it to the headers -
branches/eam_branches/ipp-20130711/psModules/src/imcombine/pmSubtractionSimple.h
r35771 r36075 16 16 psImageMaskType maskVal, 17 17 psImageMaskType maskBad, 18 psImageMaskType maskPoor 18 psImageMaskType maskPoor, 19 float deconvolveThreshold 19 20 ); 20 21 -
branches/eam_branches/ipp-20130711/psModules/src/objects/pmPSFtryFitPSF.c
r35768 r36075 75 75 psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PSFTRY_MASK_BAD_MODEL; 76 76 psTrace ("psModules.objects", 4, "dropping %d (%d,%d) : bad PSF fit\n", i, source->peak->x, source->peak->y); 77 return false;77 continue; 78 78 } 79 79
Note:
See TracChangeset
for help on using the changeset viewer.
