Displaying differences for changeset
 
display as  

src/java/m/oms/ages/V1_0.java

@@ -26,6 +26,7 @@
 import oms.utils.Utils.PBIAS;
 import oms.utils.Utils.NSLOG;
 import oms.utils.Utils.NSLOG1P;
+import oms.utils.Utils.NS2LOGOP;
 import oms3.ObjectiveFunction;
 
 /**
@@ -44,210 +45,207 @@
 @Resource(file = "${csip.dir}/bin/ages/simulation/ages.sim", type = REFERENCE, id = KEY_SCRIPT)
 public class V1_0 extends ModelDataService {
 
-  public static final String KEY_SCRIPT = "ages.sim";
-  public static final String RUN_INC = "run.inc";
+    public static final String KEY_SCRIPT = "ages.sim";
+    public static final String RUN_INC = "run.inc";
 
-  public static final String PAR_STARTTIME = "startTime";
-  public static final String PAR_ENDTIME = "endTime";
+    public static final String PAR_STARTTIME = "startTime";
+    public static final String PAR_ENDTIME = "endTime";
 
-  static final Map<String, ObjectiveFunction> OF = new HashMap<>();
+    static final Map<String, ObjectiveFunction> OF = new HashMap<>();
 
-
-  static {
-    OF.put("kge", new KGE());
-    OF.put("ns", new NS());
-    OF.put("nslog", new NSLOG());
-    OF.put("nslog1p", new NSLOG1P());
-    OF.put("rmse", new RMSE());
-    OF.put("trmse", new TRMSE());
-    OF.put("pbias", new PBIAS());
-  }
-
-  // required parameter
-  String[] reqParams = {
-    PAR_STARTTIME,
-    PAR_ENDTIME
-  };
-
-  // optional parameter
-  String[] optParams = {
-    "ACAdaptation",
-    "BetaW",
-    "Beta_min",
-    "Beta_rsd",
-    "FCAdaptation",
-    "Ksink",
-    "LExCoef",
-    "N_delay_RG1",
-    "N_delay_RG2",
-    "a_rain",
-    "a_snow",
-    "angstrom_a",
-    "angstrom_b",
-    "baseTemp",
-    "calib_clat_fact",
-    "ccf_factor",
-    "defaultCO2",
-    "denitfac",
-    "delayNitrification",
-    "denitrificationRateCoefficient",
-    "denitrificationSoilSaturationThreshold",
-    "depdr",
-    "deposition_factor",
-    "drrad",
-    "drspac",
-    "f1",
-    "f12",
-    "f13",
-    "f14",
-    "f15",
-    "f16",
-    "f17",
-    "f18",
-    "f19",
-    "f2",
-    "f3",
-    "f4",
-    "f5",
-    "f6",
-    "f7",
-    "f8",
-    "flowRouteTA",
-    "fmt_date",
-    "fmt_double",
-    "g_factor",
-    "geoMaxPerc",
-    "gwCapRise",
-    "gwRG1Fact",
-    "gwRG1RG2dist",
-    "gwRG2Fact",
-    "halflife_RG1",
-    "halflife_RG2",
-    "infil_conc_factor",
-    "initLPS",
-    "initMPS",
-    "initN_concRG1",
-    "initN_concRG2",
-    "initRG1",
-    "initRG2",
-    "kdiff_layer",
-    "kf_calib",
-    "lagSurfaceRunoff",
-    "lagInterflow",
-    "locGrw",
-    "longTZ",
-    "nitri_delay",
-    "nitrificationSoilTemperatureThreshold",
-    "nitrificationSurfaceTemperatureThreshold",
-    "opti",
-    "piadin",
-    "r_factor",
-    "rootfactor",
-    "sceno",
-    "skipRegression",
-    "snowCritDens",
-    "snowDensConst",
-    "snowFactorA",
-    "snowFactorB",
-    "snowFactorC",
-    "snow_trans",
-    "snow_trs",
-    "soilDiffMPSLPS",
-    "soilDistMPSLPS",
-    "soilImpGT80",
-    "soilImpLT80",
-    "soilLatVertLPS",
-    "soilLinRed",
-    "soilMaxDPS",
-    "soilMaxInfSnow",
-    "soilMaxInfSummer",
-    "soilMaxInfWinter",
-    "soilMaxPerc",
-    "soilOutLPS",
-    "soilPolRed",
-    "t_factor",
-    "tempRes",
-    "temp_lag"
-  };
-
-  // simulation flags
-  String[] flags = {
-    "flagParallel",
-    "flagRegionalization",
-    "flagHRURouting",
-    "flagReachRouting",
-    "flagSort",
-    "flagSplit",
-    "flagInfiltration",
-    "flagTillage",
-    "flagTileDrain",
-    "flagUPGM",
-    "parallelismFactor",
-    "parallelismThreads",
-    "flagSaveState",
-    "flagLoadState",
-    "flagWB"
-  };
-
-
-  @Override
-  public void doProcess() throws Exception {
-    String dsl = parameter().getString(KEY_SCRIPT,
-        resources().getFile(KEY_SCRIPT).toString());
-
-    // pass request param to model runtime parameter -> run.inc
-    Map<String, String> agesParam = new LinkedHashMap<>();
-    Utils.passReqQuotedParam(agesParam, parameter(), reqParams);
-
-    // scalar parameter
-    Utils.passOptParam(agesParam, parameter(), optParams);
-
-    // optional flags
-    Utils.passOptQuotedParam(agesParam, parameter(), flags);
-
-    // create parameter include file
-    Utils.createParamInclude(agesParam, getWorkspaceFile(RUN_INC));
-
-    String start = parameter().getString(PAR_STARTTIME);
-    String end = parameter().getString(PAR_ENDTIME);
-
-    File d = new File(dsl);
-    if (!(d.isAbsolute() && d.exists())) {
-      d = getWorkspaceFile(dsl);
+    static {
+        OF.put("kge", new KGE());
+        OF.put("ns", new NS());
+        OF.put("nslog", new NSLOG());
+        OF.put("nslog1p", new NSLOG1P());
+        OF.put("nslogop", new NS2LOGOP());
+        OF.put("rmse", new RMSE());
+        OF.put("trmse", new TRMSE());
+        OF.put("pbias", new PBIAS());
     }
 
-    getWorkspaceFile("output").mkdirs();
-    getWorkspaceFile("logs").mkdirs();
+    // required parameter
+    String[] reqParams = {
+        PAR_STARTTIME,
+        PAR_ENDTIME
+    };
 
-    Utils.runAges(d, getWorkspaceDir(), parameter(), resources(), LOG);
+    // optional parameter
+    String[] optParams = {
+        "ACAdaptation",
+        "BetaW",
+        "Beta_min",
+        "Beta_rsd",
+        "FCAdaptation",
+        "Ksink",
+        "LExCoef",
+        "N_delay_RG1",
+        "N_delay_RG2",
+        "a_rain",
+        "a_snow",
+        "angstrom_a",
+        "angstrom_b",
+        "baseTemp",
+        "calib_clat_fact",
+        "ccf_factor",
+        "defaultCO2",
+        "denitfac",
+        "delayNitrification",
+        "denitrificationRateCoefficient",
+        "denitrificationSoilSaturationThreshold",
+        "depdr",
+        "deposition_factor",
+        "drrad",
+        "drspac",
+        "f1",
+        "f12",
+        "f13",
+        "f14",
+        "f15",
+        "f16",
+        "f17",
+        "f18",
+        "f19",
+        "f2",
+        "f3",
+        "f4",
+        "f5",
+        "f6",
+        "f7",
+        "f8",
+        "flowRouteTA",
+        "fmt_date",
+        "fmt_double",
+        "g_factor",
+        "geoMaxPerc",
+        "gwCapRise",
+        "gwRG1Fact",
+        "gwRG1RG2dist",
+        "gwRG2Fact",
+        "halflife_RG1",
+        "halflife_RG2",
+        "infil_conc_factor",
+        "initLPS",
+        "initMPS",
+        "initN_concRG1",
+        "initN_concRG2",
+        "initRG1",
+        "initRG2",
+        "kdiff_layer",
+        "kf_calib",
+        "lagSurfaceRunoff",
+        "lagInterflow",
+        "locGrw",
+        "longTZ",
+        "nitri_delay",
+        "nitrificationSoilTemperatureThreshold",
+        "nitrificationSurfaceTemperatureThreshold",
+        "opti",
+        "piadin",
+        "r_factor",
+        "rootfactor",
+        "sceno",
+        "skipRegression",
+        "snowCritDens",
+        "snowDensConst",
+        "snowFactorA",
+        "snowFactorB",
+        "snowFactorC",
+        "snow_trans",
+        "snow_trs",
+        "soilDiffMPSLPS",
+        "soilDistMPSLPS",
+        "soilImpGT80",
+        "soilImpLT80",
+        "soilLatVertLPS",
+        "soilLinRed",
+        "soilMaxDPS",
+        "soilMaxInfSnow",
+        "soilMaxInfSummer",
+        "soilMaxInfWinter",
+        "soilMaxPerc",
+        "soilOutLPS",
+        "soilPolRed",
+        "t_factor",
+        "tempRes",
+        "temp_lag"
+    };
 
-    for (String ofName : getRequestedObjfunc(OF.keySet())) {
-      String[] data = parameter().getStringArray(ofName);
-      double v = calc_of(OF.get(ofName), data[0], data[1], start, end);
-      results().put(ofName, v);
+    // simulation flags
+    String[] flags = {
+        "flagParallel",
+        "flagRegionalization",
+        "flagHRURouting",
+        "flagReachRouting",
+        "flagSort",
+        "flagSplit",
+        "flagInfiltration",
+        "flagTillage",
+        "flagTileDrain",
+        "flagUPGM",
+        "parallelismFactor",
+        "parallelismThreads",
+        "flagSaveState",
+        "flagLoadState",
+        "flagWB"
+    };
+
+    @Override
+    public void doProcess() throws Exception {
+        String dsl = parameter().getString(KEY_SCRIPT,
+                resources().getFile(KEY_SCRIPT).toString());
+
+        // pass request param to model runtime parameter -> run.inc
+        Map<String, String> agesParam = new LinkedHashMap<>();
+        Utils.passReqQuotedParam(agesParam, parameter(), reqParams);
+
+        // scalar parameter
+        Utils.passOptParam(agesParam, parameter(), optParams);
+
+        // optional flags
+        Utils.passOptQuotedParam(agesParam, parameter(), flags);
+
+        // create parameter include file
+        Utils.createParamInclude(agesParam, getWorkspaceFile(RUN_INC));
+
+        String start = parameter().getString(PAR_STARTTIME);
+        String end = parameter().getString(PAR_ENDTIME);
+
+        File d = new File(dsl);
+        if (!(d.isAbsolute() && d.exists())) {
+            d = getWorkspaceFile(dsl);
+        }
+
+        getWorkspaceFile("output").mkdirs();
+        getWorkspaceFile("logs").mkdirs();
+
+        Utils.runAges(d, getWorkspaceDir(), parameter(), resources(), LOG);
+
+        for (String ofName : getRequestedObjfunc(OF.keySet())) {
+            String[] data = parameter().getStringArray(ofName);
+            double v = calc_of(OF.get(ofName), data[0], data[1], start, end);
+            results().put(ofName, v);
+        }
+//  results().put(getWorkspaceFile("output"));
     }
-//  results().put(getWorkspaceFile("output"));
-  }
 
+    private List<String> getRequestedObjfunc(Set<String> names) {
+        List<String> l = new ArrayList<>();
+        for (String ofName : names) {
+            if (parameter().has(ofName)) {
+                l.add(ofName);
+            }
+        }
+        return l;
+    }
 
-  private List<String> getRequestedObjfunc(Set<String> names) {
-    List<String> l = new ArrayList<>();
-    for (String ofName : names) {
-      if (parameter().has(ofName)) {
-        l.add(ofName);
-      }
+    private double calc_of(ObjectiveFunction of, String obs,
+            String sim, String start, String end) throws IOException, ServiceException {
+        // e.g. obs_data02_14.csv/obs/orun[1]
+        double[] obsData = Utils.getData(obs, getWorkspaceDir(), start, end);
+        // e.g. output/csip_run/out/Outlet.csv/output/catchmentSimRunoff
+        double[] simData = Utils.getData(sim, getWorkspaceDir(), start, end);
+        return of.calculate(obsData, simData, parameter().getDouble("missing", -9999d));
     }
-    return l;
-  }
-
-
-  private double calc_of(ObjectiveFunction of, String obs,
-      String sim, String start, String end) throws IOException, ServiceException {
-    // e.g. obs_data02_14.csv/obs/orun[1]
-    double[] obsData = Utils.getData(obs, getWorkspaceDir(), start, end);
-    // e.g. output/csip_run/out/Outlet.csv/output/catchmentSimRunoff
-    double[] simData = Utils.getData(sim, getWorkspaceDir(), start, end);
-    return of.calculate(obsData, simData, parameter().getDouble("missing", -9999d));
-  }
 
 }

src/java/oms/utils/Utils.java

@@ -214,7 +214,7 @@
     /**
      *
      */
-    public static class NS2LOG_OPTAS implements ObjectiveFunction {
+    public static class NS2LOGOP implements ObjectiveFunction {
 
         @Override
         public double calculate(double m[], double s[], double missing) {
@@ -222,15 +222,17 @@
             double rsme = 0;
             double var = 0;
             double avg = 0;
+            double count = 0;
             for (int i = 0; i < m.length; i++) {
-                if (m[i] > 0) {
+                if (m[i] > 0 && m[i] != missing) {
                     avg += Math.log(m[i]);
+                    count += 1;
                 }
             }
-            avg /= m.length;
+            avg /= count;
 
             for (int i = 0; i < m.length; i++) {
-                if (m[i] > 0 & s[i] > 0) {
+                if (m[i] > 0 && s[i] > 0 && m[i] != missing) {
                     rsme += Math.pow(Math.abs(Math.log(m[i]) - Math.log(s[i])), pow);
                     var += Math.pow(Math.abs(Math.log(m[i]) - avg), pow);
                 }