Changeset 969 for sans


Ignore:
Timestamp:
Nov 13, 2015 4:03:38 PM (7 years ago)
Author:
srkline
Message:

more additions to the R/W functions to access VSANS data files

Location:
sans/Dev/trunk/NCNR_User_Procedures/Reduction
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/EventModeProcessing.ipf

    r942 r969  
    20652065//      IndexForHistogram(data1,data2,myhist) 
    20662066//      Wave index=SavedIndex 
    2067 //      JointHistogram(data1,data2,myHist,index) 
     2067//      EV_JointHistogram(data1,data2,myHist,index) 
    20682068//      NewImage myHist 
    20692069//       
     
    20732073 
    20742074 
    2075 Function JointHistogram(w0,w1,hist,index) 
     2075Function EV_JointHistogram(w0,w1,hist,index) 
    20762076        wave w0,w1,hist,index 
    20772077  
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/VC_HDF5_VSANS_Utils.ipf

    r961 r969  
    22 
    33// 
    4 // This file has lots of utility procedures to be able to read/write 
    5 // test HDF5 files for SANS and VSANS in Nexus format 
    6 // 
    7 // It doesn't have the NICE logs, but has everything that I  
    8 // can think of here. 
    9 // 
     4// This file has utility procedures to be able to read/write 
     5// test HDF5 (from Igor) for SANS and VSANS in Nexus format 
     6// 
     7// It is predominantly to be able to WRITE a full Nexus file from Igor 
     8// -- this is only necessary to be able to write out "fake" VSANS files from VCALC 
     9//    since I need a "template" of the Nexus folder structure to start from and fill in 
     10// 
     11// It doesn't reproduce the NICE logs, but will leave a spece for them if 
     12// it is read in and is part of the xref. 
     13// 
     14// It may be easier to hard-wire my own folder definition (NewDataFolder) 
     15// that is MY Nexus file to write out and use that as the base case 
     16// rather than rely on Pete's code, which is terribly slow for writing. 
     17// Attributes are the issue, but it may be unimportant if they are missing. 
     18// 
     19 
     20 
    1021 
    1122// 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_HDF5_RW_Utils.ipf

    r967 r969  
    11#pragma rtGlobals=3             // Use modern global access method and strict wave access. 
    22 
    3  
    4  
    5 // 
    6 // Start to build up and test the r/w accessors for VSANS 
    7 // (SANS has a template, VSANS does not, so just start from scratch here, since the  
    8 // file structure will be different) 
    9 // 
    10 // 
     3// 
     4// The base functions for R/W from HDF5 files. 
     5// All of the specific "get" and "write" functions call these base functions which are responsible 
     6// for all of the open/close mechanics. 
     7// 
     8// These VSANS file-specific functions are in: 
     9// V_HDF5_Read.ipf 
     10//               and 
     11// V_HDF5_Write.ipf 
     12// 
     13 
    1114 
    1215 
    1316// thought this would be useful, but the file name (folder) is stuck in the middle... 
    14 Strconstant ksPathPrefix = "root:(folder):entry:entry1:" 
     17//Strconstant ksPathPrefix = "root:(folder):entry:entry1:" 
    1518 
    1619 
     
    152155End 
    153156 
     157// Returns a wave reference, not just a single value 
     158// ---then you pick what you need from the wave 
     159//  
     160// - fname passed in is the full path to the file on disk 
     161// - path is the path to the value in the HDF tree 
     162// 
     163// check to see if the value exists (It will be a wave) 
     164// -- if it does, return the value from the local folder 
     165// -- if not, read the file in, then return the value 
     166// 
     167Function/WAVE V_getTextWaveFromHDF5(fname,path) 
     168        String fname,path 
     169 
     170        String folderStr="" 
     171        Variable valExists=0 
     172         
     173        folderStr = V_RemoveDotExtension(V_GetFileNameFromPathNoSemi(fname)) 
     174         
     175        if(Exists("root:"+folderStr+":"+path)) 
     176                valExists=1 
     177        endif 
     178         
     179        if(!valExists) 
     180                //then read in the file 
     181                V_LoadHDF5_NoAtt(fname) 
     182        endif 
     183 
     184// this should exist now - if not, I need to see the error 
     185        Wave/T wOut = $("root:"+folderStr+":"+path) 
     186         
     187        return wOut 
     188         
     189End 
     190 
     191 
    154192// 
    155193//   TODO 
     
    159197// 
    160198// truncate to integer before returning?? 
     199// 
     200//  TODO 
     201// write a "getIntegerWave" function?? 
    161202// 
    162203//////  integer values 
     
    390431        return err 
    391432end 
     433 
     434////////////////////////////// 
     435////////////////////////////// 
     436////////////////////////////// 
     437 
     438Function V_KillNamedDataFolder(fname) 
     439        String fname 
     440         
     441        Variable err=0 
     442         
     443        String folderStr = V_GetFileNameFromPathNoSemi(fname) 
     444        folderStr = V_RemoveDotExtension(folderStr) 
     445         
     446        KillDataFolder/Z $("root:"+folderStr) 
     447        err = V_flag 
     448         
     449        return(err) 
     450end 
     451 
     452//given a filename of a SANS data filename of the form 
     453// name.anything 
     454//returns the name as a string without the ".fbdfasga" extension 
     455// 
     456// returns the input string if a"." can't be found (maybe it wasn't there" 
     457Function/S V_RemoveDotExtension(item) 
     458        String item 
     459        String invalid = item   // 
     460        Variable num=-1 
     461         
     462        //find the "dot" 
     463        String runStr="" 
     464        Variable pos = strsearch(item,".",0) 
     465        if(pos == -1) 
     466                //"dot" not found 
     467                return (invalid) 
     468        else 
     469                //found, get all of the characters preceeding it 
     470                runStr = item[0,pos-1] 
     471                return (runStr) 
     472        Endif 
     473End 
     474 
     475//returns a string containing filename (WITHOUT the ;vers) 
     476//the input string is a full path to the file (Mac-style, still works on Win in IGOR) 
     477//with the folders separated by colons 
     478// 
     479// called by MaskUtils.ipf, ProtocolAsPanel.ipf, WriteQIS.ipf 
     480// 
     481Function/S V_GetFileNameFromPathNoSemi(fullPath) 
     482        String fullPath 
     483         
     484        Variable offset1,offset2 
     485        String filename="" 
     486        //String PartialPath 
     487        offset1 = 0 
     488        do 
     489                offset2 = StrSearch(fullPath, ":", offset1) 
     490                if (offset2 == -1)                              // no more colons ? 
     491                        fileName = FullPath[offset1,strlen(FullPath) ] 
     492                        //PartialPath = FullPath[0, offset1-1] 
     493                        break 
     494                endif 
     495                offset1 = offset2+1 
     496        while (1) 
     497         
     498        //remove version number from name, if it's there - format should be: filename;N 
     499        filename =  StringFromList(0,filename,";")              //returns null if error 
     500         
     501        Return filename 
     502End 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_HDF5_Read.ipf

    r967 r969  
    10801080// so the FHWM will be different in each direction. May need to return 
    10811081// "dummy" value for "B" detector if pixels there are square 
    1082 Function V_getDet_PixelFWHM(fname,detStr) 
    1083         String fname,detStr 
    1084  
    1085         String path = "entry:instrument:detector_"+detStr+":PixelFWHM" 
     1082Function V_getDet_PixelFWHM_X(fname,detStr) 
     1083        String fname,detStr 
     1084 
     1085        String path = "entry:instrument:detector_"+detStr+":PixelFWHM_X" 
    10861086 
    10871087// TODO -- different behavior for "B" 
     
    10931093End 
    10941094 
     1095// TODO -- write and X and Y version of this. Pixels are not square 
     1096// so the FHWM will be different in each direction. May need to return 
     1097// "dummy" value for "B" detector if pixels there are square 
     1098Function V_getDet_PixelFWHM_Y(fname,detStr) 
     1099        String fname,detStr 
     1100 
     1101        String path = "entry:instrument:detector_"+detStr+":PixelFWHM_Y" 
     1102 
     1103// TODO -- different behavior for "B" 
     1104        if(cmpstr(detStr,"B") == 0) 
     1105                return(V_getRealValueFromHDF5(fname,path)) 
     1106        else 
     1107                return(V_getRealValueFromHDF5(fname,path)) 
     1108        endif 
     1109End 
     1110 
    10951111Function V_getDet_PixelNumX(fname,detStr) 
    10961112        String fname,detStr 
     
    14681484 
    14691485        String path = "entry:instrument:sample_aperture:shape:size" 
     1486        WAVE w = V_getRealWaveFromHDF5(fname,path) 
     1487 
     1488        outW = w 
     1489        return(0) 
     1490End              
     1491 
     1492///////  sample_aperture_2 (data folder) 
     1493 
     1494Function/S V_getSampleAp2_Description(fname) 
     1495        String fname 
     1496 
     1497        String path = "entry:instrument:sample_aperture_2:description" 
     1498        Variable num=60 
     1499        return(V_getStringFromHDF5(fname,path,num)) 
     1500End 
     1501 
     1502Function V_getSampleAp2_distance(fname) 
     1503        String fname 
     1504 
     1505        String path = "entry:instrument:sample_aperture_2:distance" 
     1506        return(V_getRealValueFromHDF5(fname,path)) 
     1507End 
     1508//      shape (data folder) 
     1509 
     1510Function/S V_getSampleAp2_shape(fname) 
     1511        String fname 
     1512 
     1513        String path = "entry:instrument:sample_aperture_2:shape:shape" 
     1514        Variable num=60 
     1515        return(V_getStringFromHDF5(fname,path,num)) 
     1516End 
     1517 
     1518// TODO -- this needs to return a WAVE, since the shape may be circle, or rectangle 
     1519// and will need to return more than a single dimension 
     1520// TODO -- be careful of the UNITS 
     1521Function V_getSampleAp2_size(fname,outW) 
     1522        String fname 
     1523        Wave outW 
     1524 
     1525        String path = "entry:instrument:sample_aperture_2:shape:size" 
    14701526        WAVE w = V_getRealWaveFromHDF5(fname,path) 
    14711527 
     
    16131669 
    16141670 
    1615 Function V_getSample_rotationAngle(fname) 
    1616         String fname 
    1617          
    1618         String path = "entry:sample:rotation_angle"      
    1619         return(V_getRealValueFromHDF5(fname,path)) 
    1620 end 
    1621  
    1622  
    16231671//Sample Rotation Angle 
    16241672Function V_getSampleRotationAngle(fname) 
     
    16661714 
    16671715 
    1668  
    1669  
    1670  
    1671 // sample label 
    1672 // 
    1673 // TODO 
    1674 // limit to 60 characters?? do I need to do this with HDF5? 
    1675 // 
    1676 // do I need to pad to 60 characters? 
    1677 // 
    1678 Function V_WriteSamLabelToHeader(fname,str) 
    1679         String fname,str 
    1680          
    1681 //      if(strlen(str) > 60) 
    1682 //              str = str[0,59] 
    1683 //      endif    
    1684          
    1685         Make/O/T/N=1 tmpTW 
    1686         String groupName = "/sample"    //      /entry is automatically prepended -- so just explicitly state the group 
    1687         String varName = "description" 
    1688         tmpTW[0] = str // 
    1689  
    1690         variable err 
    1691         err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW) 
    1692         if(err) 
    1693                 Print "HDF write err = ",err 
    1694         endif 
    1695          
    1696         // now be sure to kill the data folder to force a re-read of the data next time this file is read in 
    1697         err = V_KillNamedDataFolder(fname) 
    1698         if(err) 
    1699                 Print "DataFolder kill err = ",err 
    1700         endif 
    1701                  
    1702         return(err) 
    1703 End 
    1704  
    1705 // sample transmission 
    1706 Function V_WriteTransmissionToHeader(fname,trans) 
    1707         String fname 
    1708         Variable trans 
    1709          
    1710         Make/O/D/N=1 wTmpWrite 
    1711         String groupName = "/sample"    //      skip "entry" - /entry/sample becomes groupName /entry/entry/sample 
    1712         String varName = "transmission" 
    1713 //      Make/O/R/N=1 wTmpWrite 
    1714 //      String groupName = "/data"      //      skip "entry" - /entry/sample becomes groupName /entry/entry/sample 
    1715 //      String varName = "Transmission" 
    1716         wTmpWrite[0] = trans // 
    1717  
    1718         variable err 
    1719         err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite) 
    1720         if(err) 
    1721                 Print "HDF write err = ",err 
    1722         endif 
    1723         // now be sure to kill the data folder to force a re-read of the data next time this file is read in 
    1724         err = V_KillNamedDataFolder(fname) 
    1725         if(err) 
    1726                 Print "DataFolder kill err = ",err 
    1727         endif 
    1728         return(err) 
    1729 End 
    17301716 
    17311717 
     
    19051891End 
    19061892 
     1893Function/S V_getTransmissionFileName(fname) 
     1894        String fname 
     1895 
     1896        String path = "entry:reduction:transmission_file_name"   
     1897        Variable num=60 
     1898        return(V_getStringFromHDF5(fname,path,num)) 
     1899End 
     1900 
     1901Function/S V_getEmptyBeamFileName(fname) 
     1902        String fname 
     1903 
     1904        String path = "entry:reduction:empty_beam_file_name"     
     1905        Variable num=60 
     1906        return(V_getStringFromHDF5(fname,path,num)) 
     1907End 
     1908 
    19071909 
    19081910//whole detector trasmission 
     
    20002002 
    20012003 
    2002 ////////////////////////////// 
    2003 ////////////////////////////// 
    2004 ////////////////////////////// 
    2005  
    2006 Function V_KillNamedDataFolder(fname) 
    2007         String fname 
    2008          
    2009         Variable err=0 
    2010          
    2011         String folderStr = V_GetFileNameFromPathNoSemi(fname) 
    2012         folderStr = V_RemoveDotExtension(folderStr) 
    2013          
    2014         KillDataFolder/Z $("root:"+folderStr) 
    2015         err = V_flag 
    2016          
    2017         return(err) 
    2018 end 
    2019  
    2020 //given a filename of a SANS data filename of the form 
    2021 // name.anything 
    2022 //returns the name as a string without the ".fbdfasga" extension 
    2023 // 
    2024 // returns the input string if a"." can't be found (maybe it wasn't there" 
    2025 Function/S V_RemoveDotExtension(item) 
    2026         String item 
    2027         String invalid = item   // 
    2028         Variable num=-1 
    2029          
    2030         //find the "dot" 
    2031         String runStr="" 
    2032         Variable pos = strsearch(item,".",0) 
    2033         if(pos == -1) 
    2034                 //"dot" not found 
    2035                 return (invalid) 
    2036         else 
    2037                 //found, get all of the characters preceeding it 
    2038                 runStr = item[0,pos-1] 
    2039                 return (runStr) 
    2040         Endif 
    2041 End 
    2042  
    2043 //returns a string containing filename (WITHOUT the ;vers) 
    2044 //the input string is a full path to the file (Mac-style, still works on Win in IGOR) 
    2045 //with the folders separated by colons 
    2046 // 
    2047 // called by MaskUtils.ipf, ProtocolAsPanel.ipf, WriteQIS.ipf 
    2048 // 
    2049 Function/S V_GetFileNameFromPathNoSemi(fullPath) 
    2050         String fullPath 
    2051          
    2052         Variable offset1,offset2 
    2053         String filename="" 
    2054         //String PartialPath 
    2055         offset1 = 0 
    2056         do 
    2057                 offset2 = StrSearch(fullPath, ":", offset1) 
    2058                 if (offset2 == -1)                              // no more colons ? 
    2059                         fileName = FullPath[offset1,strlen(FullPath) ] 
    2060                         //PartialPath = FullPath[0, offset1-1] 
    2061                         break 
    2062                 endif 
    2063                 offset1 = offset2+1 
    2064         while (1) 
    2065          
    2066         //remove version number from name, if it's there - format should be: filename;N 
    2067         filename =  StringFromList(0,filename,";")              //returns null if error 
    2068          
    2069         Return filename 
    2070 End 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_HDF5_Write.ipf

    r967 r969  
    30123012// so the FHWM will be different in each direction. May need to return 
    30133013// "dummy" value for "B" detector if pixels there are square 
    3014 Function V_writeDet_PixelFWHM(fname,detStr) 
     3014Function V_writeDet_PixelFWHM_X(fname,detStr,val) 
    30153015        String fname,detStr 
    3016  
    3017         String path = "entry:instrument:detector_"+detStr+":PixelFWHM" 
    3018  
    3019 // TODO -- different behavior for "B" 
    3020         if(cmpstr(detStr,"B") == 0) 
    3021 //              return(V_writeRealValueFromHDF5(fname,path)) 
    3022                 return(-99999) 
    3023         else 
    3024 //              return(V_writeRealValueFromHDF5(fname,path)) 
    3025                 return(-99999) 
    3026         endif 
    3027 End 
     3016        Variable val 
     3017 
     3018//      String path = "entry:instrument:detector_"+detStr+":PixelFWHM_X" 
     3019         
     3020        Make/O/D/N=1 wTmpWrite 
     3021//      Make/O/R/N=1 wTmpWrite 
     3022        String groupName = "/entry/instrument/detector_"+detStr  
     3023        String varName = "PixelFWHM_X" 
     3024        wTmpWrite[0] = val 
     3025 
     3026        variable err 
     3027        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite) 
     3028        if(err) 
     3029                Print "HDF write err = ",err 
     3030        endif 
     3031        // now be sure to kill the data folder to force a re-read of the data next time this file is read in 
     3032        err = V_KillNamedDataFolder(fname) 
     3033        if(err) 
     3034                Print "DataFolder kill err = ",err 
     3035        endif 
     3036        return(err) 
     3037End 
     3038 
     3039 
     3040// TODO -- write and X and Y version of this. Pixels are not square 
     3041// so the FHWM will be different in each direction. May need to return 
     3042// "dummy" value for "B" detector if pixels there are square 
     3043Function V_writeDet_PixelFWHM_Y(fname,detStr,val) 
     3044        String fname,detStr 
     3045        Variable val 
     3046 
     3047//      String path = "entry:instrument:detector_"+detStr+":PixelFWHM_Y" 
     3048         
     3049        Make/O/D/N=1 wTmpWrite 
     3050//      Make/O/R/N=1 wTmpWrite 
     3051        String groupName = "/entry/instrument/detector_"+detStr  
     3052        String varName = "PixelFWHM_Y" 
     3053        wTmpWrite[0] = val 
     3054 
     3055        variable err 
     3056        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite) 
     3057        if(err) 
     3058                Print "HDF write err = ",err 
     3059        endif 
     3060        // now be sure to kill the data folder to force a re-read of the data next time this file is read in 
     3061        err = V_KillNamedDataFolder(fname) 
     3062        if(err) 
     3063                Print "DataFolder kill err = ",err 
     3064        endif 
     3065        return(err) 
     3066End 
     3067 
    30283068 
    30293069Function V_writeDet_PixelNumX(fname,detStr,val) 
     
    50705110End 
    50715111 
     5112Function V_writeTransmissionFileName(fname,str) 
     5113        String fname,str 
     5114 
     5115//      String path = "entry:reduction:transmission_file_name"   
     5116 
     5117        Make/O/T/N=1 tmpTW 
     5118        String groupName = "/entry/reduction" 
     5119        String varName = "transmission_file_name" 
     5120        tmpTW[0] = str // 
     5121 
     5122        variable err 
     5123        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW) 
     5124        if(err) 
     5125                Print "HDF write err = ",err 
     5126        endif 
     5127         
     5128        // now be sure to kill the data folder to force a re-read of the data next time this file is read in 
     5129        err = V_KillNamedDataFolder(fname) 
     5130        if(err) 
     5131                Print "DataFolder kill err = ",err 
     5132        endif 
     5133                 
     5134        return(err) 
     5135End 
     5136 
     5137Function V_writeEmptyBeamFileName(fname,str) 
     5138        String fname,str 
     5139 
     5140//      String path = "entry:reduction:empty_beam_file_name"     
     5141 
     5142        Make/O/T/N=1 tmpTW 
     5143        String groupName = "/entry/reduction" 
     5144        String varName = "empty_beam_file_name" 
     5145        tmpTW[0] = str // 
     5146 
     5147        variable err 
     5148        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW) 
     5149        if(err) 
     5150                Print "HDF write err = ",err 
     5151        endif 
     5152         
     5153        // now be sure to kill the data folder to force a re-read of the data next time this file is read in 
     5154        err = V_KillNamedDataFolder(fname) 
     5155        if(err) 
     5156                Print "DataFolder kill err = ",err 
     5157        endif 
     5158                 
     5159        return(err) 
     5160End 
     5161 
    50725162 
    50735163//whole detector transmission 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_NexusFromIgor.ipf

    r963 r969  
    55////////////////////////////// 
    66//  
    7 // THIS IS DEPRICATED -- LOAD A NEXUS FILE INSTEAD AS A TEMPLATE 
     7// This is not really used anymore - but may still be used in the future. I need somenthing like this 
     8// to be able to write a full Nexus file from Igor, but I still don't know the best way to  
     9// do the setup to match the "real" NICE-generated file structure. Modifying the DataFolderTree.ipf 
     10// to generate the NewDataFolder and Make statements may be a reliable way to reproduce the correct 
     11// structure from NICE, with the exception that NOT EVERY field is written out from NICE, depending 
     12// on the experiment setup!!! 
    813// 
    914// AUG 2015 
     15// NOV 2015 
    1016// 
    1117////////////////////////////// 
Note: See TracChangeset for help on using the changeset viewer.