[GRASS-SVN] r42747 - grass/trunk/imagery/i.atcorr

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jul 9 16:52:00 EDT 2010


Author: aghisla
Date: 2010-07-09 20:52:00 +0000 (Fri, 09 Jul 2010)
New Revision: 42747

Modified:
   grass/trunk/imagery/i.atcorr/create_iwave.py
Log:
Output of converter is closer to cpp format.

Modified: grass/trunk/imagery/i.atcorr/create_iwave.py
===================================================================
--- grass/trunk/imagery/i.atcorr/create_iwave.py	2010-07-09 18:01:05 UTC (rev 42746)
+++ grass/trunk/imagery/i.atcorr/create_iwave.py	2010-07-09 20:52:00 UTC (rev 42747)
@@ -43,7 +43,7 @@
 
 def read_input(csvfile):
     """
-    Func to read input file
+    Function to read input file
     return number of bands and array of values for each band
     should be a .csv file with the values
     of the filter function for each band in the sensor
@@ -52,7 +52,7 @@
     first column is wavelength
     """
     infile = open(csvfile, 'r')
-    
+        
     # get number of bands and band names
     bands = infile.readline().split(',')
     bands.remove(bands[0])
@@ -66,10 +66,9 @@
     for b in range(len(bands)):
         conv[b+1] = lambda s: float(s or -99)
     
-    
     values = np.loadtxt(csvfile, delimiter=',', skiprows=1, converters = conv)
     
-    return(bands, values)
+    return (bands, values)
 
 def interpolate_band(values):
     """
@@ -79,7 +78,7 @@
     and min, max wl values
     values must be numpy array with 2 columns
     """
-    
+    # These 2 lines select the subarray 
     # remove nodata (-99) lines in values array
     # where response is nodata?
     w = values[:,1] >= 0
@@ -90,7 +89,11 @@
     
     filter_f = f(np.arange(response[0,0], response[-1,0], 2.5))
     
-    return(filter_f, (response[0,0], response[-1,0]))
+    # converts limits from nanometers to micrometers
+    lowerlimit = response[0,0]/1000
+    upperlimit = response[-1,0]/1000
+    
+    return(filter_f, (lowerlimit, upperlimit))
 
 def plot_filter(values):
     """Plot wl response values and interpolated
@@ -122,25 +125,27 @@
         for l in range(nlines):
             for i in range(8):
                 if l == nlines-1 and i == 7: # last value
-                    pstring = pstring+' %.2f };\n' % (filter_f[l*8+i])
+                    pstring = pstring+' %.4f \n' % (filter_f[l*8+i])
+                    pstring = pstring+'    };'
                 else:
-                    pstring = pstring+' %.2f,' % (filter_f[l*8+i])
+                    pstring = pstring+' %.4f,' % (filter_f[l*8+i])
             pstring = pstring+'\n    '
     else:
         for l in range(nlines):
             for i in range(8):
-                pstring = pstring+'    %.2f,' % (filter_f[l*8+i])
+                pstring = pstring+' %.4f,' % (filter_f[l*8+i])
             pstring = pstring+'\n    '
         # adding rest of values in filter_f
         for i in range(rest):
             if i == rest-1: # last value
-                pstring = pstring+'    %.2f };\n' % (filter_f[nlines*7+i])
+                pstring = pstring+' %.4f \n' % (filter_f[nlines*8+i])
+                pstring = pstring+'    };'
             else:
-                pstring = pstring+'    %.2f,' % (filter_f[nlines*7+i])
+                pstring = pstring+' %.4f,' % (filter_f[nlines*8+i])
     
     return pstring
 
-def write_cpp(bands, values, sensor):
+def write_cpp(bands, values, sensor, folder):
     """
     from bands, values and sensor name
     create output file in cpp style
@@ -160,7 +165,7 @@
             limits.append(li)
     
     # writing...
-    outfile = open(sensor+"_cpp_template.txt", 'w')
+    outfile = open(os.path.join(folder, sensor+"_cpp_template.txt"), 'w')
     outfile.write('/* Following filter function created using create_iwave.py */\n\n')
     
     if len(bands) == 1:
@@ -239,8 +244,8 @@
     # getting data from file
     bands, values = read_input(inputfile)
     
-    # writing file
-    write_cpp(bands, values, sensor)
+    # writing file in same folder of input file
+    write_cpp(bands, values, sensor, os.path.dirname(inputfile))
     
     print "Filter function written to %s" % (sensor+"_cpp_template.txt")
     print "Please check file for possible errors before inserting into IWave.cpp"



More information about the grass-commit mailing list