Ignore:
Timestamp:
Nov 2, 2015 10:28:35 AM (7 years ago)
Author:
srkline
Message:

intermediate changes to the VSANS r/w routines, a utility for processing ISO8601 dates, and some testing procedures for working with the banks of tubes.

Location:
sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_ReadWrite_HDF5.ipf

    r963 r965  
    150150// depricated? in HDF5 - store all of the values as real? 
    151151// Igor sees no difference in real and integer variables (waves are different) 
     152// BUT-- Igor 7 will have integer variables 
    152153// 
    153154// truncate to integer before returning?? 
     
    174175// -- if not, read the file in, then return the value 
    175176// 
    176 // TODO -- string is checked for length, but returned right or wrong 
     177// TODO -- string could be checked for length, but returned right or wrong 
    177178// 
    178179Function/S V_getStringFromHDF5(fname,path,num) 
     
    205206 
    206207 
     208// 
    207209//Write Wave 'wav' to hdf5 file 'fname' 
    208210//Based on code from ANSTO (N. Hauser. nha 8/1/09) 
     211// 
     212// TODO: 
     213// -- figure out if this will write in the native format of the  
     214//     wave as passed in, or if it will only write as DP. 
     215// -- do I need to write separate functions for real, integer, etc.? 
     216//       
     217// -- change the /P=home to the user-defined data path (which may be home)               
     218// 
    209219Function V_WriteWaveToHDF(fname, groupName, varName, wav) 
    210220        String fname, groupName, varName 
     
    216226         
    217227        try      
    218                 HDF5OpenFile /Z fileID  as fname  //open file read-write 
     228                HDF5OpenFile/P=home /Z fileID  as fname  //open file read-write 
    219229                if(!fileID) 
    220230                        err = 1 
     
    268278 
    269279        endtry 
    270          
     280 
     281// it is not necessary to close the group here. HDF5CloseFile will close the group as well       
    271282        if(groupID) 
    272283                HDF5CloseGroup /Z groupID 
     
    311322                endif  
    312323 
    313 // TODO SRK -- skipping the concatenation of the NXentry_name - may add back in the future, but this 
     324// TODO SRK -- ??? un-did this... skipping the concatenation of the NXentry_name - may add back in the future, but this 
    314325//   prevents me from accessing the file name which I put on the top node (which may be incorrect style) 
    315326// 
     
    318329// 
    319330                //concatenate NXentry node name and groupName    
    320 //              groupName = "/" + NXentry_name + groupName 
     331                groupName = "/" + NXentry_name + groupName 
    321332                Print "groupName = ",groupName 
    322333 
     
    366377 
    367378 
    368  
    369  
    370  
    371  
    372 //transmission is at byte 158 
    373 Function V_getSampleTrans(fname) 
    374         String fname 
    375          
    376         String path = "Run1:Sample:TRNS"         
    377         return(V_getRealValueFromHDF5(fname,path)) 
    378 end 
    379  
    380 //sample transmission is a real value at byte 158 
     379////////////////////////////////////////////// 
     380////////////////////////////////// 
     381// for TESTING of the get functions - to quickly access and se if there are errors 
     382// 
     383// -- not sure how to test the string functions -- can't seem to get a FUNCREF to a string function 
     384// to work -- maybe it's not alllowed? 
     385// 
     386//      -- Not sure how to test the "write" functions. writing the wrong data type to the wrong data field will be a disaster 
     387//    Writing odd, dummy values will also be a mess - no way to know if I'm doing anything correctly 
     388// 
     389Function proto_V_get_FP(str) 
     390        String str 
     391        return(0) 
     392end 
     393 
     394//Function/S proto_V_get_STR(str) 
     395//      String str 
     396//      return("") 
     397//end 
     398 
     399Function Test_V_get_FP(str,fname) 
     400        String str,fname 
     401         
     402        Variable ii,num 
     403        String list,item 
     404         
     405         
     406        list=FunctionList(str,";","NPARAMS:1") //,VALTYPE:1 
     407        Print list 
     408        num = ItemsInlist(list) 
     409         
     410         
     411        for(ii=0;ii<num;ii+=1) 
     412                item = StringFromList(ii, list , ";") 
     413                FUNCREF proto_V_get_FP f = $item 
     414                Print item ," = ", f(fname) 
     415        endfor 
     416         
     417        return(0) 
     418end 
     419 
     420 
     421//Function Test_V_get_STR(str,fname) 
     422//      String str,fname 
     423//       
     424//      Variable ii,num 
     425//      String list,item 
     426//       
     427//       
     428//      list=FunctionList(str,";","NPARAMS:1,VALTYPE:4") 
     429//      Print list 
     430//      num = ItemsInlist(list) 
     431//       
     432//       
     433//      for(ii=0;ii<num;ii+=1) 
     434//              item = StringFromList(ii, list , ";") 
     435//              FUNCREF proto_V_get_STR f = $item 
     436//              Print item ," = ", f(fname) 
     437//      endfor 
     438//       
     439//      return(0) 
     440//end 
     441 
     442/////////////////////////////////////// 
     443 
     444 
     445////////////////////////////////////////////// 
     446 
     447 
     448/////////////////////// 
     449// 
     450// *These are the specific bits of information to retrieve (or write) to the data file 
     451// *These functions use the path to the file as input, and each has the specific 
     452//   path to the variable srting, or wave hard-coded into the access function 
     453// *They call the generic worker functions to get the values, either from the local copy if present, 
     454//   or the full file is loaded. 
     455// 
     456// *Since the path is the important bit, these are written as get/write pairs to make it easier to  
     457//   keep up with any changes in path 
     458// 
     459// 
     460// TODO -- verify the paths, and add more as needed 
     461// 
     462 
     463 
     464//////// TOP LEVEL 
     465//////// TOP LEVEL 
     466//////// TOP LEVEL 
     467 
     468 
     469 
     470//////// CONTROL 
     471//////// CONTROL 
     472//////// CONTROL 
     473 
     474//monitor count 
     475Function V_getMonitorCount(fname) 
     476        String fname 
     477         
     478        String path = "entry:control:monitor_counts"     
     479        return(V_getRealValueFromHDF5(fname,path)) 
     480end 
     481 
     482 
     483//////// INSTRUMENT 
     484//////// INSTRUMENT 
     485//////// INSTRUMENT 
     486 
     487//wavelength 
     488Function V_getWavelength(fname) 
     489        String fname 
     490         
     491        String path = "entry:instrument:beam:monochromator:wavelength"   
     492        return(V_getRealValueFromHDF5(fname,path)) 
     493end 
     494 
     495//wavelength spread 
     496Function V_getWavelengthSpread(fname) 
     497        String fname 
     498         
     499        String path = "entry:instrument:beam:monochromator:wavelength_spread"    
     500        return(V_getRealValueFromHDF5(fname,path)) 
     501end 
     502 
     503// reactor power (MW) 
     504Function V_getReactorPower(fname) 
     505        String fname 
     506 
     507        String path = "entry:instrument:source:power"    
     508        return(V_getRealValueFromHDF5(fname,path)) 
     509end 
     510 
     511 
     512//////// SAMPLE 
     513//////// SAMPLE 
     514//////// SAMPLE 
     515 
     516 
     517// sample transmission 
     518Function V_getSampleTransmission(fname) 
     519        String fname 
     520         
     521        String path = "entry:sample:transmission"        
     522//      String path = "QKK0037737:data:Transmission"     
     523        return(V_getRealValueFromHDF5(fname,path)) 
     524end 
     525 
     526// sample transmission 
    381527Function V_WriteTransmissionToHeader(fname,trans) 
    382528        String fname 
     
    384530         
    385531        Make/O/D/N=1 wTmpWrite 
    386         String groupName = "/Sample"    //      /Run1/Sample becomes groupName /Run1/Run1/Sample 
    387         String varName = "TRNS" 
     532        String groupName = "/sample"    //      skip "entry" - /entry/sample becomes groupName /entry/entry/sample 
     533        String varName = "transmission" 
     534//      Make/O/R/N=1 wTmpWrite 
     535//      String groupName = "/data"      //      skip "entry" - /entry/sample becomes groupName /entry/entry/sample 
     536//      String varName = "Transmission" 
    388537        wTmpWrite[0] = trans // 
    389538 
    390539        variable err 
    391540        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite) 
    392 //      Print "HDF write err = ",err 
    393          
     541        if(err) 
     542                Print "HDF write err = ",err 
     543        endif 
    394544        // now be sure to kill the data folder to force a re-read of the data next time this file is read in 
    395545        err = V_KillNamedDataFolder(fname) 
    396 //      Print "DataFolder kill err = ",err 
    397                  
    398         return(0) 
    399 End 
    400  
    401 // sample label (60 characters @ byte 98) 
     546        if(err) 
     547                Print "DataFolder kill err = ",err 
     548        endif 
     549        return(err) 
     550End 
     551 
     552 
     553//transmission error (one sigma) 
     554Function V_getSampleTransError(fname) 
     555        String fname 
     556         
     557        String path = "entry:sample:transmission_error"  
     558        return(V_getRealValueFromHDF5(fname,path)) 
     559end 
     560 
     561 
     562// sample label  
     563// TODO: value of num is currently not used 
     564// 
    402565Function/S V_getSampleLabel(fname) 
    403566        String fname 
    404567 
    405         String path = "Run1:runLabel" 
     568        String path = "entry:sample:description" 
    406569        Variable num=60 
    407570        return(V_getStringFromHDF5(fname,path,num)) 
     
    409572 
    410573 
    411 // sample label, starts at byte 98 
     574// sample label 
    412575// 
    413576// TODO 
     
    426589         
    427590        Make/O/T/N=1 tmpTW 
    428         String groupName = "/Run1"      //      explicitly state the group 
    429         String varName = "runLabel" 
     591        String groupName = "/sample"    //      /entry is automatically prepended -- so just explicitly state the group 
     592        String varName = "description" 
    430593        tmpTW[0] = str // 
    431594 
    432595        variable err 
    433596        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW) 
    434 //      Print "HDF write err = ",err 
     597        if(err) 
     598                Print "HDF write err = ",err 
     599        endif 
    435600         
    436601        // now be sure to kill the data folder to force a re-read of the data next time this file is read in 
    437602        err = V_KillNamedDataFolder(fname) 
    438 //      Print "DataFolder kill err = ",err 
    439          
    440         return(0) 
    441 End 
     603        if(err) 
     604                Print "DataFolder kill err = ",err 
     605        endif 
     606                 
     607        return(err) 
     608End 
     609 
     610//Sample Thickness 
     611Function V_getSampleThickness(fname) 
     612        String fname 
     613         
     614        String path = "entry:sample:thickness"   
     615        return(V_getRealValueFromHDF5(fname,path)) 
     616end 
     617 
     618//Sample Rotation Angle is at byte 170 
     619Function V_getSampleRotationAngle(fname) 
     620        String fname 
     621         
     622        String path = "entry:sample:rotation_angle"      
     623        return(V_getRealValueFromHDF5(fname,path)) 
     624end 
     625 
     626//Sample position in changer 
     627Function V_getSamplePosition(fname) 
     628        String fname 
     629         
     630        String path = "entry:sample:changer_position"    
     631        return(V_getRealValueFromHDF5(fname,path)) 
     632end 
     633 
     634 
     635 
     636 
     637 
     638///////// REDUCTION 
     639///////// REDUCTION 
     640///////// REDUCTION 
     641 
     642 
     643//box counts 
     644Function V_getBoxCounts(fname) 
     645        String fname 
     646         
     647        String path = "entry:reduction:box_count"        
     648        return(V_getRealValueFromHDF5(fname,path)) 
     649end 
     650 
     651//box counts error 
     652Function V_getBoxCountsError(fname) 
     653        String fname 
     654         
     655        String path = "entry:reduction:box_count_error"  
     656        return(V_getRealValueFromHDF5(fname,path)) 
     657end 
     658 
     659 
     660//whole detector trasmission 
     661Function V_getSampleTransWholeDetector(fname) 
     662        String fname 
     663         
     664        String path = "entry:reduction:whole_trans"      
     665        return(V_getRealValueFromHDF5(fname,path)) 
     666end 
     667 
     668//whole detector trasmission error 
     669Function V_getSampleTransWholeDetErr(fname) 
     670        String fname 
     671         
     672        String path = "entry:reduction:whole_trans_error"        
     673        return(V_getRealValueFromHDF5(fname,path)) 
     674end 
     675 
    442676 
    443677 
     
    460694 
    461695 
     696////////////////////////////// 
     697////////////////////////////// 
    462698////////////////////////////// 
    463699 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_TubeAdjustments.ipf

    r964 r965  
    3232//      FillMatrix_Pix_Center(ind) 
    3333// 
     34// 
     35// -or- (note that the pack_image wave that is generated here is for display ONLY) 
     36// --since it is interpolated 
     37// 
     38// Interpolate_mm_tubes() 
     39 
    3440 
    3541// The function most used externally is: 
     
    414420 
    415421 
    416  
    417  
    418  
    419  
    420  
     422// set the (linear) range of the y-axis of the matrix to be the 
     423// range of the 1st tube. This is completely arbitrary 
     424// 
     425Proc Interpolate_mm_tubes() 
     426 
     427        Duplicate/O pack pack_image 
     428 
     429        Variable ii,numTubes=8 
     430        Variable p1,p2 
     431        p1 = tube1_mm[0] 
     432        p2 = tube1_mm[numpnts(tube1_mm)-1] 
     433         
     434        SetScale/I y p1,p2,"", pack_image 
     435         
     436        // then make a temporary 1D wave to help with the interpolation 
     437        Duplicate/O tube1_mm lin_mm,lin_val 
     438        SetScale/I x p1,p2,"", lin_mm 
     439        lin_mm = x                      //fill with the linear mm spacing 
     440        lin_val=0 
     441         
     442        ii=1 
     443        do 
     444                lin_val = interp(lin_mm, $("tube"+num2str(ii)+"_mm"), $("tube"+num2str(ii))) 
     445                pack_image[ii-1][] = lin_val[q] 
     446                 
     447                ii+=1 
     448        while(ii<=numTubes) 
     449         
     450        display;appendimage pack_image 
     451        ModifyImage pack_image ctab= {*,*,ColdWarm,0} 
     452         
     453End 
    421454 
    422455 
Note: See TracChangeset for help on using the changeset viewer.