Default Seadas User 8 лет назад
Родитель
Сommit
f6cca72b47
3 измененных файлов с 261 добавлено и 85 удалено
  1. 95 0
      LOG_KdNeuralNetwork_test.c
  2. 147 85
      class_KdJamet.py
  3. 19 0
      test_class_KdNN.py

+ 95 - 0
LOG_KdNeuralNetwork_test.c

@@ -0,0 +1,95 @@
+/*
+  Short code to test Jamet C. Neural Network Kd inversion.
+
+  C coding version :
+  2012-03-15 D. Dessailly david.dessailly@univ-littoral.fr
+
+  LOG (Laboratoire d'Oceanoligie et Geoscience)
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <memory.h>
+#include <math.h>
+#include "iop_Rrs_neuron.h"
+#include "neuron_switch160715.h"
+
+#define PI 3.14159265
+#define NBWL 6
+#define NBNE 7
+
+/* neuron_kd_1cc.c functions*/
+extern void neuron_lect_LUTswitch(int idCap, char *path);
+extern float rsupOL_neuron_passe_avant(float x[rsupOL_NE+1]); /* Neural network Kd computation switch SeaWiFS */
+extern float rinfOL_neuron_passe_avant(float x[rinfOL_NE]);
+// extern float rsupMO_neuron_passe_avant(float x[rsupMO_NE+1]); /* Neural network Kd computation switch MODIS */
+// extern float rinfMO_neuron_passe_avant(float x[rinfMO_NE]);
+// extern float rsupOL_neuron_passe_avant(float x[rsupOL_NE+1]);  /* Neural network Kd computation switch MERIS / OLCI */
+// extern float rinfOL_neuron_passe_avant(float input[rinfOL_NE]);
+//
+float LO[NBWL] = {413.,443.,490.,510.,560.,665.};
+
+int main (argc, argv)
+int argc;
+char *argv[];
+{
+  FILE *fic, *out;
+  int i, status;
+  char nomfic[500];
+
+  float RRS[NBNE];  /* inputs */
+  float KD[NBWL]; /* outputs */
+  float s2RRS[rinfOL_NE], rap;
+
+  if(argc != 3){
+    printf("launch with arguments : \n");
+    printf("  - input file name [file with %d columns for SeaWiFS Wave-length : 412.,443.,490.,510.,550.,670.]\n",(int)NBWL);
+    printf("  - output filename\n");
+  }
+
+  /*## Kd LUTs initialization ##*/
+  neuron_lect_LUTswitch(idMERIS, "../LUTS");
+
+  /* input file */
+  if( (fic=fopen(argv[1],"r")) == NULL ) {perror(argv[1]); exit(-1);}
+  fgets(nomfic,500,fic);
+  /* foutput file */
+  if( (out=fopen(argv[2],"w")) == NULL ) {perror(argv[3]); exit(-1);}
+  for(i=0; i<NBLO; i++)
+    fprintf(out,"Kd%g ",LO[i]);
+  fprintf(out,"\n");
+
+  while( (status = fscanf(fic,"%f",&RRS[0])) == 1){
+    for(i=1; i<NBWL; i++)
+      fscanf(fic,"%f",&RRS[i]);
+    /* Choix du reseau a utiliser en fonction du rapport 490/555 */
+    rap = RRS[2]/RRS[4];
+    if( rap >= .85 )
+      for(i=0; i<rsupOL_NE-1; i++)
+        s2RRS[i] = RRS[i+1];
+    else
+      for(i=0; i<rinfOL_NE-1; i++)
+        s2RRS[i] = RRS[i+1];
+
+    for(i=0; i<NBWL; i++){
+      if( rap >= .85 ){
+        s2RRS[rsupOL_NE-1] = LO[i];
+        KD[i] = rsupOL_neuron_passe_avant(s2RRS);
+      }
+      else{
+        s2RRS[rinfOL_NE-1] = LO[i];
+        KD[i] = rinfOL_neuron_passe_avant(s2RRS);
+      }
+    }
+
+    for(i=0; i<NBLO; i++)
+      fprintf(out,"%g ", KD[i]);
+    fprintf(out,"\b\n");
+  }
+
+  fclose(fic);
+  fclose(out);
+  return(0);
+}

+ 147 - 85
class_KdJamet.py

@@ -5,100 +5,125 @@ import numpy as np
 import sys
 import os
 
-Sensor = {'idSEAWIFS' = 0, 'idMODIS' = 1, 'idMERIS' = 2}
+Sensor = {'idSEAWIFS' : 0, 'idMODIS' : 1, 'idMERIS' : 2}
+NBWL = 6
 
-class Kd_Jamet:
+class KdJamet:
+  #
+  # Input :
+  # idSensor : valid values -> [idSEAWIFS, idMODIS, idMERIS]
+  #
   def __init__(self, idSensor):
+    self.sensor = idSensor
     try:
-      self.lutpath = os.getenv('KD_LUT_PATH')
+      self.lutpath = os.getenv('KD_LUTS_PATH')
     except:
-      print "KD_LUT_PATH not set, add it to your environement variables"
+      print "KD_LUT_PATH not set, add it to your environment variables"
       sys.exit()
-      
+    
     if Sensor.has_key(idSensor):
-      self.init_variables(Sensor[idSensor])
+      self.init_variables()
       try:
-        self.read_LUTs_Kd(Sensor[idSensor])
+        self.read_LUTs_Kd()
       except:
-        print "Failed to read %s LUTs" % (idSensor)
+        print "Failed to read %s LUTs" % (idSensor[2:])
+        raise
         sys.exit()
+    else:
+      print "invalid Sensor ID : %s" % (idSensor)
   
-  # -
+  # - METHODE init_variables ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   # Perceptron parameters setting and array initialization for each Sensor
-  # -
-  def init_variables(self, idSensor):
+  # --
+  def init_variables(self):
+    print "class KdJamet.init_variables Method"
     # =======================================================================================================
     # MERIS / OLCI 
     # =======================================================================================================
-    if idSensor == Sensor['idMERIS']:
+    if self.sensor == 'idMERIS':
+      self.WL = np.array([413, 443, 490, 510, 560, 665])
       # Variables definiton for network Rrs490/Rrs555 >= .85 -------------------------------------------------
       # hidden layer number 
-      self.rsup_NC 2
+      self.rsup_NC=2
       # input data number
-      self.rsup_NE 5
+      self.rsup_NE=5
       # number of neuron in the first hidden layer 
-      self.rsup_NC1 7
+      self.rsup_NC1=7
       # number of neuron in the second hidden layer
-      self.rsup_NC2 4
+      self.rsup_NC2=4
       # nb output
-      self.rsup_NS 1
+      self.rsup_NS=1
       # nb input + nb output*/
-      self.rsup_NES 6
+      self.rsup_NES=6
       # LUTs file names 
-      self.rsup_LUT_POIDS "KdOLCI_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_555_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_7_4_switch_110416.sn"
-      self.rsupLUT_MOY "Moy_KdOLCI_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_ss_620.dat"
-      self.rsup_LUT_ECART "Ecart_KdOLCI_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_ss_620.dat"
+      self.rsup_LUT_POIDS = "KdOLCI_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_555_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_7_4_switch_110416.sn"
+      self.rsup_LUT_MOY = "Moy_KdOLCI_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_ss_620.dat"
+      self.rsup_LUT_ECART = "Ecart_KdOLCI_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_ss_620.dat"
 
       # Variables definiton for network Variables definiton for network < .85 -----------------------------------
       # nombre de couches cachees - hidden layer number
-      self.rinf_NC 2
+      self.rinf_NC=2
       # input data number*/
-      self.rinf_NE 6
+      self.rinf_NE=6
       # number of neuron in the first hidden layer
-      self.rinf_NC1 5
+      self.rinf_NC1=5
       # number of neuron in the second hidden layer
-      self.rinf_NC2 5
+      self.rinf_NC2=5
       # nb output
-      self.rinf_NS 1
+      self.rinf_NS=1
       # nb input + nb output
-      self.rinf_NES 7
+      self.rinf_NES=7
       #LUTs file names
-      self.rinf_LUT_POIDS "KdOLCI_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_5_5_switch_110416.sn"
-      self.rinf_LUT_MOY "Moy_KdOLCI_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_ss_620.dat"
-      self.rinf_LUT_ECART "Ecart_KdOLCI_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_ss_620.dat"
+      self.rinf_LUT_POIDS = "KdOLCI_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_5_5_switch_110416.sn"
+      self.rinf_LUT_MOY = "Moy_KdOLCI_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_ss_620.dat"
+      self.rinf_LUT_ECART = "Ecart_KdOLCI_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_ss_620.dat"
 
     #LUTs arrays definition
-    self.rsup_b1 = np.zeros((rsup_NC1), dtype=np.float32) 
-    self.rsup_b2 = np.zeros((rsup_NC2), dtype=np.float32) 
+    self.rsup_b1 = np.zeros((self.rsup_NC1), dtype=np.float64) 
+    self.rsup_b2 = np.zeros((self.rsup_NC2), dtype=np.float64) 
     self.rsup_b3 = 0.
-    self.rsup_w1 = np.zeros((rsup_NE,rsup_NC1), dtype=np.float32)
-    self.rsup_w2 = np.zeros((rsup_NC1,rsup_NC2), dtype=np.float32)
-    self.rsup_w3 = np.zeros((rsup_NC2), dtype=np.float32)
-    self.rsup_moy = np.zeros((rsup_NES), dtype=np.float32)
-    self.rsup_ecart = np.zeros((rsup_NES), dtype=np.float32)
+    self.rsup_w1 = np.zeros((self.rsup_NE,self.rsup_NC1), dtype=np.float64)
+    self.rsup_w2 = np.zeros((self.rsup_NC1,self.rsup_NC2), dtype=np.float64)
+    self.rsup_w3 = np.zeros((self.rsup_NC2), dtype=np.float64)
+    self.rsup_moy = np.zeros((self.rsup_NES), dtype=np.float64)
+    self.rsup_ecart = np.zeros((self.rsup_NES), dtype=np.float64)
 
-    self.rinf_b1 = np.zeros((rinf_NC1), dtype=np.float32)
-    self.rinf_b2 = np.zeros((rinf_NC2), dtype=np.float32)
+    self.rinf_b1 = np.zeros((self.rinf_NC1), dtype=np.float64)
+    self.rinf_b2 = np.zeros((self.rinf_NC2), dtype=np.float64)
     self.rinf_b3 = 0.
-    self.rinf_w1 = np.zeros((rinf_NE,rinf_NC1), dtype=np.float32)
-    self.rinf_w2 = np.zeros((rinf_NC1,rinf_NC2), dtype=np.float32)
-    self.rinf_w3 = np.zeros((rinf_NC2), dtype=np.float32)
-    self.rinf_moy = np.zeros((rinf_NES), dtype=np.float32)
-    self.rinf_ecart = np.zeros((rinf_NES), dtype=np.float32)
+    self.rinf_w1 = np.zeros((self.rinf_NE,self.rinf_NC1), dtype=np.float64)
+    self.rinf_w2 = np.zeros((self.rinf_NC1,self.rinf_NC2), dtype=np.float64)
+    self.rinf_w3 = np.zeros((self.rinf_NC2), dtype=np.float64)
+    self.rinf_moy = np.zeros((self.rinf_NES), dtype=np.float64)
+    self.rinf_ecart = np.zeros((self.rinf_NES), dtype=np.float64)
+    
+    # =======================================================================================================
+    # MODIS
+    # =======================================================================================================
+    if self.sensor == 'idMODIS':
+      self.WL = np.array([412, 443, 488, 531, 547, 667])
+    # =======================================================================================================
+    # SEAWIFS
+    # =======================================================================================================
+    if self.sensor == 'idSEAWIFS':
+      self.WL = np.array([412, 443, 490, 510, 555, 670])
   
-  # -
-  # perceptron weights LUT reading
-  # -
+  # -- METHODE read_LUTs_Kd ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  # perceptron weights LUTs reading
+  # LUTS are expected to be located in environment variable : $KD_LUTS_PATH
+  # --
   def read_LUTs_Kd(self):
+    print "class KdJamet.read_LUTs_Kd Method"
     # ----------------------------------------------------------------------------------
     #  < .85 weights settings
-    weights = numpy.loadtxt( "%s/%s" % (self.lutpath, self.rinf_LUT_POIDS), skiprows=1)
+    print "  class KdJamet.read_LUTs_Kd : read weights file for Rrs%d/Rrs%d < .85: %s/%s" % (self.WL[2], self.WL[4],self.lutpath, self.rinf_LUT_POIDS)
+    weights = np.loadtxt( "%s/%s" % (self.lutpath, self.rinf_LUT_POIDS), skiprows=1)
     base = 0
     self.rinf_b1 = weights[base:base+self.rinf_NC1,2]
     base = base+self.rinf_NC1
-    self.rsup_b2 = weights[base:base+self.rinf_NC2,2]
+    self.rinf_b2 = weights[base:base+self.rinf_NC2,2]
     base = base+self.rinf_NC2
-    self.rsup_b3 = weights[base:base+self.rinf_NS,2]
+    self.rinf_b3 = weights[base:base+self.rinf_NS,2]
     base = base+self.rinf_NS
     for i in range(self.rinf_NE):
       self.rinf_w1[i,:] = weights[base:base+self.rinf_NC1,2]
@@ -106,19 +131,22 @@ class Kd_Jamet:
     for i in range(self.rinf_NC1):
       self.rinf_w2[i,:] = weights[base:base+self.rinf_NC2,2]
       base = base+self.rinf_NC2
-    self.rinf_w3 = weights[base:base+self.rinf_NC3,2]
+    self.rinf_w3 = weights[base:base+self.rinf_NC2,2]
     
     usedData = np.array([1,2,3,4,5,6,8])
-    if idSensor == Sensor['idMODIS']:
+    if self.sensor == 'idMODIS':
       usedData = np.array([1,2,3,4,6,7,9])
-    moy = numpy.loadtxt( "%s/%s" % (self.lutpath, self.rinf_LUT_MOY))
+    print "  class KdJamet.read_LUTs_Kd : read mean file : %s/%s" % (self.lutpath, self.rinf_LUT_MOY)
+    moy = np.loadtxt( "%s/%s" % (self.lutpath, self.rinf_LUT_MOY))
     self.rinf_moy = moy[usedData]
-    ecart = numpy.loadtxt( "%s/%s" % (self.lutpath, self.rinf_LUT_ECART))
+    print "  class KdJamet.read_LUTs_Kd : read ecart file : %s/%s" % (self.lutpath, self.rinf_LUT_ECART)
+    ecart = np.loadtxt( "%s/%s" % (self.lutpath, self.rinf_LUT_ECART))
     self.rinf_ecart = ecart[usedData]
     
     # ----------------------------------------------------------------------------------
     #  >= .85 weights settings
-    weights = numpy.loadtxt( "%s/%s" % (self.lutpath, self.rsup_LUT_POIDS), skiprows=1)
+    print "  class KdJamet.read_LUTs_Kd : read weights file for Rrs%d/Rrs%d >= .85: %s/%s" % (self.WL[2], self.WL[4], self.lutpath, self.rsup_LUT_POIDS)
+    weights = np.loadtxt( "%s/%s" % (self.lutpath, self.rsup_LUT_POIDS), skiprows=1)
     base = 0
     self.rsup_b1 = weights[base:base+self.rsup_NC1,2]
     base = base+self.rsup_NC1
@@ -132,64 +160,98 @@ class Kd_Jamet:
     for i in range(self.rsup_NC1):
       self.rsup_w2[i,:] = weights[base:base+self.rsup_NC2,2]
       base = base+self.rsup_NC2
-    self.rsup_w3 = weights[base:base+self.rsup_NC3,2]
+    self.rsup_w3 = weights[base:base+self.rsup_NC2,2]
     
     usedData = np.array([1,2,3,4,6,8])
-    if idSensor == Sensor['idMODIS']:
+    if self.sensor == 'idMODIS':
       usedData = np.array([1,2,3,4,7,9])
-    moy = numpy.loadtxt( "%s/%s" % (self.lutpath, self.rsup_LUT_MOY))
+    moy = np.loadtxt( "%s/%s" % (self.lutpath, self.rsup_LUT_MOY))
     self.rsup_moy = moy[usedData]
-    ecart = numpy.loadtxt( "%s/%s" % (self.lutpath, self.rsup_LUT_ECART))
+    ecart = np.loadtxt( "%s/%s" % (self.lutpath, self.rsup_LUT_ECART))
     self.rsup_ecart = ecart[usedData]
     
-  # -
-  # Kd computing   < .85
-  # input = nRrs + output Lambda
-  # -
+  # -- METHODE compute_allKd ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  # Kd computing at all Sensor used WaveLength
+  # Inputs -
+  # - indata : array[] [ Rrs443, Rrs490, Rrs510, Rrs55, Rrs665 ]
+  # Output -
+  # - return Kd[] at Sensor Wave Length
+  # --
+  def compute_allKd(self, inRrs):
+    outKd  = np.zeros(NBWL,dtype=np.float32)
+    if inRrs[2] / inRrs[4] < .85 :
+      indata = np.zeros(self.rinf_NE,dtype=np.float32)
+      indata[0:self.rinf_NE-1] = inRrs[1:self.rinf_NE]
+      idLambda = self.rinf_NE-1
+      FLAGinf = True
+    else:
+      indata = np.zeros(self.rsup_NE,dtype=np.float32)
+      indata[0:self.rsup_NE-1] = inRrs[1:self.rsup_NE]
+      idLambda = self.rsup_NE-1
+      FLAGinf = False
+    inc = 0
+    for wl in self.WL:
+      indata[idLambda] = wl
+      if FLAGinf == True:
+        outKd[inc] = self.passe_avant_inf(indata)
+      else:
+        outKd[inc] = self.passe_avant_sup(indata)
+      inc = inc+1
+    return outKd
+    
+  # --  METHODE passe_avant_sup ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  # Kd computing  for Rrs490/Rrs55 >= .85 at ONE WaveLength
+  # Inputs -
+  # - indata : array[rinf_NE] [ Rrs443, Rrs490, Rrs510, Rrs55, Lambda ]
+  # Output -
+  # - return y (Kd) at indata Wave Length
+  # --
   def passe_avant_sup(self, indata):
     # Normalization
-    x = ((2/3.) * indata[:] - self.rsup_moy[:]) / self.rsup_ecart[:]
-    
-    a = np.zeros(self.rsup_NC1,dtype=np.float32)
+    x = ((2/3.) * (indata[:] - self.rsup_moy[0:self.rsup_NE])) / self.rsup_ecart[0:self.rsup_NE]
+
+    a = np.zeros(self.rsup_NC1,dtype=np.float64)
     for i in range(self.rsup_NC1):
       for j in range(self.rsup_NE):
         a[i] = a[i] + x[j] * self.rsup_w1[j][i]
-    a[:] = 1.715905*np.tanh((2./3.)*(a[:] + self.rsupSW_b1[:]))
+    a[:] = 1.715905*np.tanh((2./3.)*(a[:] + self.rsup_b1[:]))
 
-    b = np.zeros[self.rsup_NC2,dtype=np.float32]
+    b = np.zeros(self.rsup_NC2,dtype=np.float64)
     for i in range(self.rsup_NC2):
       for j in range(self.rsup_NC1):
         b[i] = b[i] + a[j] * self.rsup_w2[j][i]
-    b[:] = 1.715905*np.tanh((2./3.)*(b[:] + self.rsupSW_b2[:]))
-    
-    y = np.sum(b[:] * self.rsupSW_w3[:])
+    b[:] = 1.715905*np.tanh((2./3.)*(b[:] + self.rsup_b2[:]))
+
+    y = np.sum(b[:] * self.rsup_w3[:])
     # Denormalisation 
-    y = 1.5*(y + self.rsupSW_b3)*self.rsupSW_ecart[self.rsupSW_NES-1] + self.rsupSW_moy[self.rsupSW_NES-1]
+    y = 1.5*(y + self.rsup_b3)*self.rsup_ecart[self.rsup_NES-1] + self.rsup_moy[self.rsup_NES-1]
     y = 10.**y
     return(y)
   
-  # -
-  # Kd computing  >= .85 
-  # input = nRrs + output Lambda
-  # -
+  # --   METHODE passe_avant_inf ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  # Kd computing  for Rrs490/Rrs55 < .85 at ONE WaveLength
+  # Inputs 
+  # - indata : array[rinf_NE] [ Rrs443, Rrs490, Rrs510, Rrs55, Rrs665, Lambda ]
+  # Output -
+  # - return y (Kd) at indata Wave Length
+  # --
   def passe_avant_inf(self, indata):
     # Normalization
-    x = ((2/3.) * indata[:] - self.rinf_moy[:]) / self.rinf_ecart[:]
-    
-    a = np.zeros(self.rinf_NC1,dtype=np.float32)
+    x = ((2/3.) * (indata[:] - self.rinf_moy[0:self.rinf_NE])) / self.rinf_ecart[0:self.rinf_NE]
+    a = np.zeros(self.rinf_NC1,dtype=np.float64)
     for i in range(self.rinf_NC1):
       for j in range(self.rinf_NE):
         a[i] = a[i] + x[j] * self.rinf_w1[j][i]
-    a[:] = 1.715905*np.tanh((2./3.)*(a[:] + self.rinfSW_b1[:]))
+    a[:] = 1.715905*np.tanh((2./3.)*(a[:] + self.rinf_b1[:]))
 
-    b = np.zeros[self.rinf_NC2,dtype=np.float32]
+    b = np.zeros(self.rinf_NC2,dtype=np.float64)
     for i in range(self.rinf_NC2):
       for j in range(self.rinf_NC1):
         b[i] = b[i] + a[j] * self.rinf_w2[j][i]
-    b[:] = 1.715905*np.tanh((2./3.)*(b[:] + self.rinfSW_b2[:]))
-    
-    y = np.sum(b[:] * self.rinfSW_w3[:])
+    b[:] = 1.715905*np.tanh((2./3.)*(b[:] + self.rinf_b2[:]))
+
+    y = np.sum(b[:] * self.rinf_w3[:])
     # Denormalisation 
-    y = 1.5*(y + self.rinfSW_b3)*self.rinfSW_ecart[self.rinfSW_NES-1] + self.rinfSW_moy[self.rinfSW_NES-1]
+    y = 1.5*(y + self.rinf_b3)*self.rinf_ecart[self.rinf_NES-1] + self.rinf_moy[self.rinf_NES-1]
     y = 10.**y
     return(y)

+ 19 - 0
test_class_KdNN.py

@@ -0,0 +1,19 @@
+#!/usr/bin/python
+import class_KdJamet as kdj
+import numpy as np
+import sys
+if len(sys.argv) != 3:
+  print "test_class_KdNN.py   must be launch with two arguments:"
+  print " $ test_class_KdNN.py LOG_KdNeuralNetwork_TestCase_Input.csv your_output.csv"
+  sys.exit(-1)
+  
+K = kdj.KdJamet('idMERIS')
+tab = np.loadtxt(sys.argv[1], skiprows=1)
+
+KDs = np.zeros(tab.shape,dtype=np.float32)
+for i in range(tab.shape[0]):
+  KDs[i,:] = K.compute_allKd(tab[i,:])
+  
+np.savetxt(sys.argv[2],KDs,fmt='%.7f',header="Kd%d Kd%d Kd%d Kd%d Kd%d Kd%d" %(K.WL[0],K.WL[1],K.WL[2],K.WL[3],K.WL[4],K.WL[5]))
+  
+