[GRASS-SVN] r69676 - grass-addons/grass7/vector/v.kriging
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Oct 4 12:59:10 PDT 2016
Author: evas
Date: 2016-10-04 12:59:10 -0700 (Tue, 04 Oct 2016)
New Revision: 69676
Modified:
grass-addons/grass7/vector/v.kriging/
grass-addons/grass7/vector/v.kriging/Makefile
grass-addons/grass7/vector/v.kriging/geostat.c
grass-addons/grass7/vector/v.kriging/getval.c
grass-addons/grass7/vector/v.kriging/main.c
grass-addons/grass7/vector/v.kriging/utils.c
grass-addons/grass7/vector/v.kriging/utils_kriging.c
grass-addons/grass7/vector/v.kriging/utils_write.c
Log:
v.kriging: fixed ticket #3115 (bug in missing report parameter and messy temporary files)
Property changes on: grass-addons/grass7/vector/v.kriging
___________________________________________________________________
Added: svn:ignore
+ OBJ.*
*.tmp.html
Modified: grass-addons/grass7/vector/v.kriging/Makefile
===================================================================
--- grass-addons/grass7/vector/v.kriging/Makefile 2016-10-04 16:58:17 UTC (rev 69675)
+++ grass-addons/grass7/vector/v.kriging/Makefile 2016-10-04 19:59:10 UTC (rev 69676)
@@ -7,8 +7,6 @@
EXTRA_INC = $(VECT_INC) $(PROJINC)
EXTRA_CFLAGS = $(VECT_CFLAGS)
-VPATH=%.png images
-
include $(MODULE_TOPDIR)/include/Make/Module.make
default: cmd
Modified: grass-addons/grass7/vector/v.kriging/geostat.c
===================================================================
--- grass-addons/grass7/vector/v.kriging/geostat.c 2016-10-04 16:58:17 UTC (rev 69675)
+++ grass-addons/grass7/vector/v.kriging/geostat.c 2016-10-04 19:59:10 UTC (rev 69676)
@@ -229,7 +229,7 @@
ddir1 = dir - tv; // difference between bearing and azimuth
ddir2 = (dir + PI) - tv;
- if (fabs(ddir1) <= td || fabs(ddir2) <= td) { // angle test: compare the diff with critical value
+ if (fabs(ddir1) <= td || fabs(ddir2) <= td) { // angle test: compare the diff with critical value
// test squared distance: vertical variogram => 0., ...
rv = type == 1 ? 0. : radius_hz_diff(dr); // ... otherwise horizontal distance
@@ -238,11 +238,11 @@
}
rvh = sqrt(rv) - *h; // the difference between distance and lag
- if (rv <= radius && fabs(rvh) <= lag) { // distance test: compare the distance with critical value and find out if the j-point is located within i-lag
+ if (rv <= radius && fabs(rvh) <= lag) { // distance test: compare the distance with critical value and find out if the j-point is located within i-lag
if (type == 2) { // vertical test for bivariate variogram:
rvh = *(dr + 2) - *vert; // compare vertical
- if (fabs(rvh) <= lag_vert) { // elevation test: vertical lag
+ if (fabs(rvh) <= lag_vert) { // elevation test: vertical lag
goto delta_V;
}
else {
@@ -490,6 +490,7 @@
struct points *pnts, struct var_par *pars,
struct output *out)
{
+ G_fatal_error(_("Interpolating values is currently under maintenance (optimization). Theoretical variogram of your data has been computed."));
// Local variables
int i3 = xD->i3;
double *vals = pnts->invals; // values to be used for interpolation
@@ -522,7 +523,7 @@
// Cell/voxel center coords (location of interpolated value)
r0 = (double *)G_malloc(3 * sizeof(double));
- if (report->write2file) { // report file available:
+ if (report->write2file) { // report file available:
time(&report->now);
fprintf(report->fp, "Interpolating values started on %s\n\n",
ctime(&report->now));
@@ -530,6 +531,7 @@
}
G_message(_("Interpolating unknown values..."));
+ G_fatal_error(_("... is currently under maintenance (optimization). Theoretical variogram of your data has been computed."));
if (percents) {
G_percent_reset();
}
@@ -544,7 +546,7 @@
var_par->GM = G_matrix_copy(GM); // copy matrix because of cross validation
// perform cross validation...
- if (crossvalid->write2file) { // ... if desired
+ if (crossvalid->write2file) { // ... if desired
crossvalidation(xD, pnts, var_par);
}
@@ -602,7 +604,7 @@
rslt_OK = vals[list->value[0] - 1]; // Estimated cell/voxel value rslt_OK = w x inputs
}
else if (list->n_values == 0) {
- if (report->write2file) { // report file available:
+ if (report->write2file) { // report file available:
fprintf(report->fp,
"Error (see standard output). Process killed...");
fclose(report->fp);
@@ -620,7 +622,7 @@
// write output to the (3D) raster layer
if (write2layer(xD, reg, out, col, row, dep, rslt_OK) == 0) {
- if (report->write2file) { // report file available
+ if (report->write2file) { // report file available
fprintf(report->fp,
"Error (see standard output). Process killed...");
fclose(report->fp); // close report file
Modified: grass-addons/grass7/vector/v.kriging/getval.c
===================================================================
--- grass-addons/grass7/vector/v.kriging/getval.c 2016-10-04 16:58:17 UTC (rev 69675)
+++ grass-addons/grass7/vector/v.kriging/getval.c 2016-10-04 19:59:10 UTC (rev 69676)
@@ -170,7 +170,7 @@
pnts->trend = T;
}
- if (xD->phase == 0 && xD->report.name) {
+ if (xD->report.write2file && xD->phase == 0) {
write2file_values(&xD->report, column);
test_normality(n, values, &xD->report);
}
@@ -368,7 +368,7 @@
G_message(_("Unused points: %d (out of region)"), out_reg);
}
- if (xD->phase == 0) { // initial phase:
+ if (xD->report.write2file == TRUE && xD->phase == 0) { // initial phase:
write2file_vector(xD, point); // describe properties
}
}
@@ -433,7 +433,8 @@
fp = fopen(file_name, "r");
if (fp == NULL) {
- G_fatal_error(_("Temporary file is missing, please repeat an initial phase..."));
+ G_fatal_error(_("Temporary file <%s> is missing, please repeat an initial phase..."),
+ file_name);
}
else { // file exists:
Modified: grass-addons/grass7/vector/v.kriging/main.c
===================================================================
--- grass-addons/grass7/vector/v.kriging/main.c 2016-10-04 16:58:17 UTC (rev 69675)
+++ grass-addons/grass7/vector/v.kriging/main.c 2016-10-04 19:59:10 UTC (rev 69676)
@@ -319,17 +319,27 @@
if (opt.report->answer) {
xD.report.write2file = TRUE;
xD.report.name = opt.report->answer;
- // Do not truncate existing report files
- // Some users might not change report file name after initial run
- // thus leading to loss of report content of initial run.
+
+ // initial phase: check if the file exists
+ if (xD.phase == 0 && access(xD.report.name, F_OK) != -1) {
+ G_fatal_error(_("Report file exists; please set up different name..."));
+ }
+
+ // middle / final phase: check if file does not exist
+ if (xD.phase != 0 && access(xD.report.name, F_OK) != 0) {
+ G_fatal_error(_("Report file does not exist; please check the name or repeat initial phase..."));
+ }
+
xD.report.fp = fopen(xD.report.name, "a");
time(&xD.report.now);
fprintf(xD.report.fp, "v.kriging started on %s\n\n",
ctime(&xD.report.now));
G_message(_("Report is being written to %s..."), xD.report.name);
}
- else
+ else {
xD.report.write2file = FALSE;
+ G_warning(_("The name of report file missing..."));
+ }
if (opt.crossvalid->answer) {
xD.crossvalid.write2file = TRUE;
@@ -349,7 +359,7 @@
if (opt.nL->answer) { // Test if nL have been set up (optional)
var_pars.hz.nLag = atoi(opt.nL->answer);
- if (var_pars.hz.nLag < 1) { // Invalid value
+ if (var_pars.hz.nLag < 1) { // Invalid value
G_message(_("Number of horizontal pieces must be at least 1. Default value will be used..."));
var_pars.hz.nLag = 20;
}
@@ -424,7 +434,6 @@
} // end if 3D interpolation
else { // 2D interpolation:
- G_warning(_("Not recommended to process for sparse or spatially heterogeneous data. The result can be inaccurate - trying to solve asap..."));
var_pars.vert.nLag = -1; // abs will be used in next steps
if (xD.v3 == TRUE) {
if (xD.report.write2file == TRUE) { // close report file
@@ -464,12 +473,19 @@
}
}
E_variogram(0, &xD, &pnts, &var_pars); // horizontal variogram (for both 2D and 3D interpolation)
- if (xD.i3 == TRUE) { // 3D interpolation:
- E_variogram(1, &xD, &pnts, &var_pars); // vertical variogram
- G_message(_("You may continue to computing theoretical variograms (middle phase)..."));
+
+ if (xD.report.write2file == FALSE) {
+ G_message(_("\nExperimental variogram of your data has been computed. To continue interpolation performance, please repeat initial phase with non-empty <report> parameter..."));
}
+
else {
- G_message(_("You may continue to computing theoretical variograms (final phase)..."));
+ if (xD.i3 == TRUE) { // 3D interpolation:
+ E_variogram(1, &xD, &pnts, &var_pars); // vertical variogram
+ G_message(_("\nExperimental variogram of your data has been computed. If you wish to continue with theoretical variograms computation (middle phase), please do not erase temporary files <dataE.dat> and <variogram_hz_tmp.txt> in your working directory. The files are required in the middle phase and they will be deleted automatically."));
+ }
+ else {
+ G_message(_("\nExperimental variogram of your data has been computed. If you wish to continue with theoretical variogram computation and interpolation (final phase), please do not erase temporary files <dataE.dat> and <variogram_hz_tmp.txt> in your working directory. The files are required in the final phase and they will be deleted automatically."));
+ }
}
goto end;
@@ -614,8 +630,6 @@
}
T_variogram(var_pars.fin.type, xD.i3, opt, &var_pars.fin, &xD.report); // compute theoretical variogram
-
- G_debug(0, "sill: %f", var_pars.fin.sill);
break;
}
Modified: grass-addons/grass7/vector/v.kriging/utils.c
===================================================================
--- grass-addons/grass7/vector/v.kriging/utils.c 2016-10-04 16:58:17 UTC (rev 69675)
+++ grass-addons/grass7/vector/v.kriging/utils.c 2016-10-04 19:59:10 UTC (rev 69676)
@@ -506,7 +506,7 @@
gamma = &gamma_M->vals[0]; // values of gamma matrix
- gp = fopen("dataE.dat", "w"); // open file to write experimental variogram
+ gp = fopen("dataE.dat", "w"); // open file to write experimental variogram (initial phase)
if (access("dataE.dat", W_OK) < 0) {
G_fatal_error(_("Something went wrong opening tmp file..."));
}
@@ -588,6 +588,7 @@
"splot 'dataE.dat' every ::1:1 matrix title \"experimental variogram\"\n");
}
+ // plot experimental variogram
else { // univariate variogram
char dim[6];
@@ -618,6 +619,10 @@
"plot 'dataE.dat' using 1:2 title \"experimental variogram\" pointtype 5\n");
}
fclose(gp);
+
+ if (xD->report.write2file == FALSE) {
+ remove("dataE.dat");
+ }
}
// plot experimental and theoretical variogram
Modified: grass-addons/grass7/vector/v.kriging/utils_kriging.c
===================================================================
--- grass-addons/grass7/vector/v.kriging/utils_kriging.c 2016-10-04 16:58:17 UTC (rev 69675)
+++ grass-addons/grass7/vector/v.kriging/utils_kriging.c 2016-10-04 19:59:10 UTC (rev 69676)
@@ -175,7 +175,7 @@
double diff_sill_05, diff_sill;
diff_sill_05 = sill_hz > sill_vert ? 0.05 * sill_hz : 0.05 * sill_vert; // critical value as 5% from bigger sill
- diff_sill = fabs(sill_hz - sill_vert); // difference between the sills
+ diff_sill = fabs(sill_hz - sill_vert); // difference between the sills
if (xD->bivar == TRUE || (!flg->univariate->answer && diff_sill > diff_sill_05)) { // zonal anisotropy
var_par->fin.type = 2; // code for bivariate variogram
@@ -665,7 +665,7 @@
//Create output
*norm = rslt_OK - *vals; // differences between input and interpolated values
- *av = fabs(*norm); // absolute values of the differences (quantile computation)
+ *av = fabs(*norm); // absolute values of the differences (quantile computation)
if (xD->i3 == TRUE) { // 3D interpolation:
fprintf(fp, "%d %.3f %.3f %.2f %f %f %f\n", i, *r, *(r + 1),
Modified: grass-addons/grass7/vector/v.kriging/utils_write.c
===================================================================
--- grass-addons/grass7/vector/v.kriging/utils_write.c 2016-10-04 16:58:17 UTC (rev 69675)
+++ grass-addons/grass7/vector/v.kriging/utils_write.c 2016-10-04 19:59:10 UTC (rev 69676)
@@ -234,7 +234,7 @@
switch (type) {
case 0: // horizontal variogram
fp = fopen("variogram_hz_tmp.txt", "w");
- if (xD->report.name) { // write name of report file
+ if (xD->report.write2file) { // write name of report file
file_length = strlen(xD->report.name);
if (file_length < 4) { // 4 types of variogram
G_fatal_error(_("File name must contain more than 2 characters...")); // todo: error
More information about the grass-commit
mailing list