- Timestamp:
- Jul 16, 2019 3:11:12 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_DIVUtils.ipf
r1152 r1178 61 61 DrawText 32,200,"Repeat for the other carriage(s)" 62 62 63 Button button2,pos={54.00,145.00},size={120.00,20.00},proc=V_DIVNormalizeButtonProc,title="Normalize+Copy" 63 Button button2,pos={54.00,145.00},size={120.00,20.00},proc=V_DIVCopyButtonProc,title="Copy" 64 Button button4,pos={54.00,235.00},size={120.00,20.00},proc=V_DIVNormalizeButtonProc,title="Normalize" 64 65 65 66 DrawText 32,290,"Once data for both (or 3) carriages\rhas been normalized, save the file" … … 128 129 End 129 130 131 132 // copies the data for a particular carriage that has been reduced to COR 133 // to a storage location for later normalization 134 Function V_DIVCopyButtonProc(ba) : ButtonControl 135 STRUCT WMButtonAction &ba 136 137 switch( ba.eventCode ) 138 case 2: // mouse up 139 // click code here 140 Execute "V_DIVCopy_proc()" 141 break 142 case -1: // control being killed 143 break 144 endswitch 145 146 return 0 147 End 148 130 149 Function V_DIVMaskButtonProc(ba) : ButtonControl 131 150 STRUCT WMButtonAction &ba … … 161 180 162 181 182 183 Proc V_DIVCopy_proc(reducedFolderType,carriageStr,first) 184 String reducedFolderType="COR",carriageStr="F" 185 Variable first=1 186 187 Vf_DIVCopy_proc(reducedFolderType,carriageStr,first) 188 end 189 190 191 192 Function Vf_DIVCopy_proc(reducedFolderType,carriageStr,first) 193 String reducedFolderType,carriageStr 194 Variable first 195 196 if (cmpstr(carriageStr,"B")==0) 197 V_NormalizeDIV_onePanel(reducedFolderType,"B") 198 else 199 // if it's the first one, copy the whole folder, otherwise just copy over what's needed 200 if(first) 201 V_CopyHDFToWorkFolder("COR","STO") 202 else 203 String topath = "root:Packages:NIST:VSANS:STO:entry:instrument:detector_" 204 String fromPath = "root:Packages:NIST:VSANS:COR:entry:instrument:detector_" 205 String detStrList,detStr 206 Variable num,ii 207 208 if(cmpstr(carriageStr,"F")==0) 209 detStrList = "FL;FR;FT;FB;" 210 else 211 detStrList = "ML;MR;MT;MB;" 212 endif 213 num=ItemsInList(detStrlist) 214 215 // loop over the list of panels to copy the data 216 for(ii=0;ii<num;ii+=1) 217 detStr = StringFromList(ii, detStrList) 218 Duplicate/O $(fromPath+detStr+":data") $(toPath+detStr+":data") 219 Duplicate/O $(fromPath+detStr+":linear_data_error") $(toPath+detStr+":linear_data_error") 220 endfor 221 endif 222 223 endif 224 225 return(0) 226 End 227 228 229 230 // this is called from the button 231 // 163 232 Proc V_NormalizeDIV_proc(reducedFolderType,carriageStr) 164 233 String reducedFolderType="COR",carriageStr="F" … … 167 236 end 168 237 238 239 // this function now treats all 8 panels as a single detector 240 // for the normalization. 241 // it is assuming that data from both carriages has been reduced to the COR stage 242 // and has been copied over to the STO folder where it will be normalized before 243 // copying to the DIV folder for saving. 244 // 169 245 Function Vf_NormalizeDIV_proc(reducedFolderType,carriageStr) 170 246 String reducedFolderType,carriageStr … … 172 248 if (cmpstr(carriageStr,"B")==0) 173 249 V_NormalizeDIV_onePanel(reducedFolderType,"B") 174 elseif (cmpstr(carriageStr,"F")==0)175 V_NormalizeDIV_onePanel(reducedFolderType,"FL")176 V_NormalizeDIV_onePanel(reducedFolderType,"FR")177 V_NormalizeDIV_onePanel(reducedFolderType,"FT")178 V_NormalizeDIV_onePanel(reducedFolderType,"FB")179 250 else 180 V_NormalizeDIV_onePanel(reducedFolderType,"ML") 181 V_NormalizeDIV_onePanel(reducedFolderType,"MR") 182 V_NormalizeDIV_onePanel(reducedFolderType,"MT") 183 V_NormalizeDIV_onePanel(reducedFolderType,"MB") 184 endif 251 DoAlert 0,"data for both carriages must already be in STO" 252 V_NormalizeDIV_allEight("STO") //forces reduced folder type to STO 253 endif 254 255 // if (cmpstr(carriageStr,"B")==0) 256 // V_NormalizeDIV_onePanel(reducedFolderType,"B") 257 // elseif (cmpstr(carriageStr,"F")==0) 258 // DoAlert 0,"data for both carriages must already be in STO" 259 // V_NormalizeDIV_allEight("STO") //forces reduced folder type to STO 260 // 261 //// V_NormalizeDIV_oneCarriage(reducedFolderType,carriageStr) 262 // 263 //// V_NormalizeDIV_onePanel(reducedFolderType,"FL") 264 //// V_NormalizeDIV_onePanel(reducedFolderType,"FR") 265 //// V_NormalizeDIV_onePanel(reducedFolderType,"FT") 266 //// V_NormalizeDIV_onePanel(reducedFolderType,"FB") 267 // else 268 // 269 //// V_NormalizeDIV_oneCarriage(reducedFolderType,carriageStr) 270 // 271 //// V_NormalizeDIV_onePanel(reducedFolderType,"ML") 272 //// V_NormalizeDIV_onePanel(reducedFolderType,"MR") 273 //// V_NormalizeDIV_onePanel(reducedFolderType,"MT") 274 //// V_NormalizeDIV_onePanel(reducedFolderType,"MB") 275 // endif 185 276 186 277 return(0) 187 278 End 188 279 189 // Normalizes a single panel 280 281 // Normalizes all eight panels (M + F) as a single detector 190 282 // then copies that panel over to the DIV_Struct for later saving 191 283 // … … 201 293 // what is done in SANS) 202 294 // 295 Function V_NormalizeDIV_allEight(type) 296 String type 297 298 Variable ii,totCts,pixelX,pixelY,sumCts,sumPts,num 299 String detStr,detStrList 300 301 detStrList = "FL;FR;FT;FB;ML;MR;MT;MB;" 302 num=ItemsInList(detStrlist) 303 304 // loop over the list of panels (n=8) to get the sums 305 sumCts = 0 306 sumPts = 0 307 for(ii=0;ii<num;ii+=1) 308 detStr = StringFromList(ii, detStrList) 309 Wave w = V_getDetectorDataW(type,detStr) 310 Wave w_err = V_getDetectorDataErrW(type,detStr) 311 312 // WaveStats/Q/M=1 w 313 // Print detStr 314 // Print "RAW V_avg = ",V_avg 315 // Print "RAW V_avg*V_npnts = ",V_avg*V_npnts 316 317 // get the mask data 318 // 1== mask, 0 == no mask 319 Wave maskW = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+detStr+":data") 320 321 // work on a copy of the data and error 322 // Duplicate/O w w_copy 323 // Duplicate/O w_err w_err_copy 324 325 w = (maskW == 1) ? NaN : w //set masked areas to NaN 326 WaveStats/Q/M=1 w 327 sumCts += V_npnts*V_avg // does not count the NaN values 328 sumPts += V_npnts 329 330 // totCts = V_npnts*V_avg // does not count the NaN values 331 // Print "Masked V_avg = ",V_avg 332 // Print "Masked V_npnts = ",V_npnts 333 // Print "Masked V_avg*V_npnts = ",V_avg*V_npnts 334 335 endfor 336 337 // now normalize each panel (in place) 338 for(ii=0;ii<num;ii+=1) 339 detStr = StringFromList(ii, detStrList) 340 Wave w = V_getDetectorDataW(type,detStr) 341 Wave w_err = V_getDetectorDataErrW(type,detStr) 342 343 w /= sumCts 344 w *= sumPts 345 346 w_err /= sumCts 347 w_err *= sumPts 348 349 // DONE: 350 // x- I replace the NaN values with 1 for the DIV (the user will mask the data as 351 // needed, and the NaN values may be an issue later... 352 w = (numtype(w) == 2) ? 1 : w //turns 2==NaN into 1 353 354 // 355 // copy the normalized data to the folder to save 356 Wave w_norm = $("root:VSANS_DIV_file:entry:instrument:detector_"+detStr+":data") 357 Wave w_norm_err = $("root:VSANS_DIV_file:entry:instrument:detector_"+detStr+":linear_data_error") 358 359 w_norm = w 360 w_norm_err = w_err 361 endfor 362 363 // KillWaves/Z w_copy,w_err_copy 364 365 return(0) 366 End 367 368 369 370 371 // Normalizes a single carriage, treating all four panels as a single panel 372 // then copies that panel over to the DIV_Struct for later saving 373 // 374 // type is the work folder where the (? corrected) data is currently 375 // 376 // DONE 377 // x- data should be copied to some alternate work folder before this step 378 // x- for T/B detectors, this may not work as intended if the whole detector is not illuminated. 379 // How to handle? A mask? 380 // x- is this the correct calculation of the error? (YES) It should be correct up to this point since the 381 // standard reduction has been used, but now the normalization step is a multiplication 382 // by a constant (w/no error). Be sure this error transformation is correct. (YES - this is correct, and is 383 // what is done in SANS) 384 // 385 Function V_NormalizeDIV_oneCarriage(type,carriageStr) 386 String type,carriageStr 387 388 Variable ii,totCts,pixelX,pixelY,sumCts,sumPts 389 String detStr,detStrList 390 391 if(cmpstr(carriageStr,"F")==0) 392 detStrList = "FL;FR;FT;FB;" 393 else 394 detStrList = "ML;MR;MT;MB;" 395 endif 396 397 // loop over the list of panels (n=4) to get the sums 398 sumCts = 0 399 sumPts = 0 400 for(ii=0;ii<4;ii+=1) 401 detStr = StringFromList(ii, detStrList) 402 Wave w = V_getDetectorDataW(type,detStr) 403 Wave w_err = V_getDetectorDataErrW(type,detStr) 404 405 // WaveStats/Q/M=1 w 406 // Print detStr 407 // Print "RAW V_avg = ",V_avg 408 // Print "RAW V_avg*V_npnts = ",V_avg*V_npnts 409 410 // get the mask data 411 // 1== mask, 0 == no mask 412 Wave maskW = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+detStr+":data") 413 414 // work on a copy of the data and error 415 // Duplicate/O w w_copy 416 // Duplicate/O w_err w_err_copy 417 418 w = (maskW == 1) ? NaN : w //set masked areas to NaN 419 WaveStats/Q/M=1 w 420 sumCts += V_npnts*V_avg // does not count the NaN values 421 sumPts += V_npnts 422 423 // totCts = V_npnts*V_avg // does not count the NaN values 424 // Print "Masked V_avg = ",V_avg 425 // Print "Masked V_npnts = ",V_npnts 426 // Print "Masked V_avg*V_npnts = ",V_avg*V_npnts 427 428 endfor 429 430 // now normalize each panel (in place) 431 for(ii=0;ii<4;ii+=1) 432 detStr = StringFromList(ii, detStrList) 433 Wave w = V_getDetectorDataW(type,detStr) 434 Wave w_err = V_getDetectorDataErrW(type,detStr) 435 436 w /= sumCts 437 w *= sumPts 438 439 w_err /= sumCts 440 w_err *= sumPts 441 442 // DONE: 443 // x- I replace the NaN values with 1 for the DIV (the user will mask the data as 444 // needed, and the NaN values may be an issue later... 445 w = (numtype(w) == 2) ? 1 : w //turns 2==NaN into 1 446 447 // 448 // copy the normalized data to the folder to save 449 Wave w_norm = $("root:VSANS_DIV_file:entry:instrument:detector_"+detStr+":data") 450 Wave w_norm_err = $("root:VSANS_DIV_file:entry:instrument:detector_"+detStr+":linear_data_error") 451 452 w_norm = w 453 w_norm_err = w_err 454 endfor 455 456 // KillWaves/Z w_copy,w_err_copy 457 458 return(0) 459 End 460 461 462 463 // Normalizes a single panel 464 // then copies that panel over to the DIV_Struct for later saving 465 // 466 // type is the work folder where the (? corrected) data is currently 467 // 468 // DONE 469 // x- data should be copied to some alternate work folder before this step 470 // x- for T/B detectors, this may not work as intended if the whole detector is not illuminated. 471 // How to handle? A mask? 472 // x- is this the correct calculation of the error? (YES) It should be correct up to this point since the 473 // standard reduction has been used, but now the normalization step is a multiplication 474 // by a constant (w/no error). Be sure this error transformation is correct. (YES - this is correct, and is 475 // what is done in SANS) 476 // 203 477 Function V_NormalizeDIV_onePanel(type,detStr) 204 478 String type,detStr … … 212 486 // pixelY = V_getDet_pixel_num_y(type,detStr) 213 487 488 // WaveStats/Q/M=1 w 489 // Print detStr 490 // Print "RAW V_avg = ",V_avg 491 // Print "RAW V_avg*V_npnts = ",V_avg*V_npnts 492 214 493 // get the mask data 215 494 // 1== mask, 0 == no mask … … 223 502 WaveStats/Q/M=1 w_copy 224 503 totCts = V_npnts*V_avg // does not count the NaN values 504 // Print "Masked V_avg = ",V_avg 505 // Print "Masked V_npnts = ",V_npnts 506 // Print "Masked V_avg*V_npnts = ",V_avg*V_npnts 225 507 226 508
Note: See TracChangeset
for help on using the changeset viewer.