Пример #1
0
METHOD get_default_method(void) {
	int i, Xset, Vgm_set;
/* 
 * no no prediction locations or no data:
 */
 	if (get_n_vars() == 0)
 		return NSP;
	if (valdata->id < 0 && gl_xvalid == 0 && data_area == NULL) {
		return UIF;
	}
/*
 * check on X variables
 */
	for (i = Xset = 0; i < get_n_vars(); i++)
		if (!(data[i]->n_X == 1 && data[i]->colX[0] == 0))
			Xset++;
/*
 * check on variograms
 */
	for (i = 0, Vgm_set = 0; i < get_n_vars(); i++)
		if (vgm[LTI(i,i)] != NULL && 
				(vgm[LTI(i,i)]->n_models > 0 || vgm[LTI(i,i)]->table != NULL)) 
					/* was: ->id >= 0*/
			Vgm_set++;
	if (!(Vgm_set == 0 || Vgm_set == get_n_vars()))
		ErrMsg(ER_SYNTAX, "set either all or no variograms");

	if (Vgm_set > 0) {
		if (get_n_beta_set() > 0)
			return SKR;
		else 
			return (Xset > 0 ? UKR : OKR);
	} else 
		return (Xset > 0 ? LSLM : IDW);
}
Пример #2
0
static void init_predictions(PRED_AT w) {
	int i;
	DPOINT *bp;
	DATA **d = NULL;
#ifdef WITH_SPIRAL
	DATA_GRIDMAP *grid;
#endif

	est = (double *) emalloc(get_n_outfile() * sizeof(double));
	bp = get_block_p();
	d = get_gstat_data();
	switch (w) {
	  case AT_POINTS:
		if (o_filename == NULL) 
			ErrMsg(ER_VARNOTSET, "please specify output file");
		write_points(o_filename, val_data, NULL, NULL, get_n_outfile());
		if (bp->x == -1.0) { /* set default */
			bp->x = bp->y = 1.0;
			pr_warning("default block size set to: dx=1, dy=1");
		}
		break;
	  case AT_GRIDMAP:
		/* open mask files: */
		get_maskX(NULL, NULL, 0, 0); /* re-initializes static arrays */
		masks = (GRIDMAP **) emalloc(get_n_masks() * sizeof(GRIDMAP *));
		for (i = 0; i < get_n_masks(); i++)
			masks[i] = check_open(get_mask_name(i), i); /* read as float */
		if (n_pred_locs > 0)
			strata_min = floor(masks[0]->cellmin);
		outmap = (GRIDMAP **) emalloc(get_n_outfile() * sizeof(GRIDMAP *));
		printlog("initializing maps ");
		for (i = 0; i < get_n_outfile(); i++) {
			if (get_outfile_namei(i) != NULL) {
				printlog("."); /* creating maps ..... */
				if (get_method() == ISI)
					masks[0]->celltype = CT_UINT8;
				outmap[i] = map_dup(get_outfile_namei(i), masks[0]);
			} else
				outmap[i] = NULL;
		}
		printlog("\n");
		if (bp->x == -1.0) { /* set default to map cellsize */
			bp->x = masks[0]->cellsizex;
			bp->y = masks[0]->cellsizey;
			pr_warning("default block size set to dx=%g, dy=%g", bp->x, bp->y);
		}
		for (i = 0; i < get_n_vars(); i++) {
 			if (d[i]->dummy) {
 				d[i]->minX = masks[0]->x_ul + 0.5 * masks[0]->cellsizex;
 				d[i]->maxX = masks[0]->x_ul + masks[0]->cellsizex * 
						(masks[0]->cols - 0.5);
 				d[i]->maxY = masks[0]->y_ul - 0.5 * masks[0]->cellsizey;
 				d[i]->minY = masks[0]->y_ul - masks[0]->cellsizey * 
						(masks[0]->rows - 0.5);
 				d[i]->minZ = d[i]->maxZ = 0.0;
 			} 
 			if (d[i]->togrid)
 				datagrid_rebuild(d[i], 1);
		}
		break;
	}
	if (gl_nsim > 1)
		init_simulations(d);
	if (is_simulation(get_method()) && get_n_beta_set() != get_n_vars())
		setup_beta(d, get_n_vars(), gl_nsim);
} /* init_predictions() */
Пример #3
0
void check_global_variables(void) {
/*
 * Purpose       : check internal variable consistency, add some parameters 
 * Created by    : Edzer J. Pebesma
 * Date          : april 13, 1992
 * Prerequisites : none
 * Returns       : -
 * Side effects  : none
 * also check Cauchy-Schwartz unequality on cross/variograms.
 */
	int i, j, nposX, n_merge = 0;
	METHOD m;
	VARIOGRAM *v_tmp;

	/* UK: check if n_masks equals total nr of unbiasedness cond. */
	if (gl_nblockdiscr < 2)
		ErrMsg(ER_RANGE, "nblockdiscr must be >= 2");
	if (method == UKR || method == LSLM) {
		nposX = 0;
		for (i = 0; i < get_n_vars(); i++)
			for (j = 0; j < data[i]->n_X; j++) {
				if (data[i]->colX[j] > 0)
					nposX++;
			}
	}
    
	if (method == SPREAD) {
		for (i = 0; i < get_n_vars(); i++)
			if (data[i]->sel_rad == DBL_MAX)
				data[i]->sel_rad *= 0.99; /* force distance calculation */
	}

	if (get_n_beta_set() != 0 && get_n_beta_set() != get_n_vars())
		ErrMsg(ER_SYNTAX, 
			"set sk_mean or beta either for all or for no variables");

	if (!(method == ISI || method == GSI)) {
		if (gl_nsim > 1)
			ErrMsg(ER_IMPOSVAL, "nsim only allowed for simulation");
	}

	if (method == ISI && max_block_dimension(0) > 0.0)
		ErrMsg(ER_IMPOSVAL, "indicator simulation only for points");
	/*
	 * check if both block and area are set
	 */
	if (data_area != NULL && (block.x > 0.0 || block.y > 0.0 || block.z > 0.0))
		ErrMsg(ER_IMPOSVAL, "both block and area set: choose one");
	/*
	 * check for equality of coordinate dimensions:
	 */
	for (i = 1; i < get_n_vars(); i++) {
		if ((data[i]->mode & V_BIT_SET) != (data[0]->mode & V_BIT_SET))  {
			message("data(%s) and data(%s):\n", name_identifier(0), 
				name_identifier(i));
			ErrMsg(ER_IMPOSVAL, "data have different coordinate dimensions");
		}
	}
	if (valdata->id > 0 && data[0]->dummy == 0 &&
			((data[0]->mode | (V_BIT_SET | S_BIT_SET)) !=
			 (valdata->mode | (V_BIT_SET | S_BIT_SET)))) {
		message("data() and data(%s):\n", name_identifier(0));
		ErrMsg(ER_IMPOSVAL, "data have different coordinate dimensions");
		for (i = 0; i < get_n_vars(); i++) {
			if (data[i]->dummy) {
				data[i]->mode = (valdata->mode | V_BIT_SET);
				data[i]->minX = valdata->minX;
				data[i]->minY = valdata->minY;
				data[i]->minZ = valdata->minZ;
				data[i]->maxX = valdata->maxX;
				data[i]->maxY = valdata->maxY;
				data[i]->maxZ = valdata->maxZ;
				set_norm_fns(data[i]);
			}
		}
	}

	for (i = 0; i < get_n_vars(); i++) {
		if (data[i]->fname == NULL && !data[i]->dummy) {
			message("file name for data(%s) not set\n", name_identifier(i));
			ErrMsg(ER_NULL, " ");
		}
		if (data[i]->id < 0) {
			message("data(%s) not set\n", name_identifier(i));
			ErrMsg(ER_NULL, " ");
		}
		if (data[i]->beta && data[i]->beta->size != data[i]->n_X) {
			pr_warning("beta dimension (%d) should equal n_X (%d)", 
				data[i]->beta->size, data[i]->n_X);
			ErrMsg(ER_IMPOSVAL, "sizes of beta and X don't match");
		}
		if (data[i]->sel_rad == DBL_MAX && data[i]->oct_max > 0)
			ErrMsg(ER_IMPOSVAL, 
				"define maximum search radius (rad) for octant search");
		if (data[i]->vdist && data[i]->sel_rad == DBL_MAX)
			ErrMsg(ER_IMPOSVAL, "when using vdist, radius should be set");
		if (! data[i]->dummy && ! (data[i]->mode & V_BIT_SET)) {
			message("no v attribute set for data(%s)\n", 
				name_identifier(data[i]->id));
			ErrMsg(ER_NULL, " ");
		}
		if (method != SEM && method != COV) {
			/* check neighbourhood settings */
			if (data[i]->sel_rad < 0.0 || data[i]->sel_min < 0 || 
				data[i]->sel_max < 0 || (data[i]->sel_min > data[i]->sel_max)) {
				message(
				"invalid neighbourhood selection: radius %g max %d min %d\n", 
				data[i]->sel_rad, data[i]->sel_max, data[i]->sel_min);
				ErrMsg(ER_IMPOSVAL, " ");
			}
		}
		if (data[i]->id > -1 && (method == OKR || method == SKR || 
				is_simulation(method) || method == UKR)) {
			if (vgm[LTI(i,i)] == NULL || vgm[LTI(i,i)]->id < 0) {
				message("variogram(%s) not set\n", name_identifier(i));
				ErrMsg(ER_VARNOTSET, "variogram()");
			}
		}
		n_merge += data[i]->n_merge;
	}
	if (n_merge && get_mode() != MULTIVARIABLE)
		ErrMsg(ER_IMPOSVAL, "merge only works in multivariable mode");
	if (mode == SIMPLE && get_method() != UIF) {  /* check if it's clean: */
		for (i = 0; i < get_n_vars(); i++)
			for (j = 0; j < i; j++)
				if (vgm[LTI(i,j)] != NULL && vgm[LTI(i,j)]->id > 0) {
					message("variogram(%s, %s) %s\n", name_identifier(i),
						name_identifier(j),
					"can only be set for ck, cs, uk, sk, ok, sem or cov");
					ErrMsg(ER_IMPOSVAL, "variogram()");
				}
	} 
	if ((m = get_default_method()) != get_method()) {
		if (m == UKR && (get_method() == OKR || get_method() == SKR))
			ErrMsg(ER_IMPOSVAL,
				"\nremove X=... settings for ordinary or simple kriging");
		if (m == OKR && get_method() == SKR)
			ErrMsg(ER_IMPOSVAL, "method: something's terribly wrong!");
		if (m == OKR && get_method() == UKR) {
			message("I would recommend:\n");
			message("Do not specify uk if ok is all you'll get\n");
		}
	}
	if (mode == MULTIVARIABLE && get_method() != UIF && get_method() != SEM
			&& get_method() != COV && n_variograms_set() > 0)
		check_variography((const VARIOGRAM **) vgm, get_n_vars());
	v_tmp = init_variogram(NULL);
	free_variogram(v_tmp);
} 
Пример #4
0
const char *method_string(METHOD i) {
#define MSTR_SIZE 100
	static char mstr[MSTR_SIZE];
	char *str, *co, *un, *gsum = "";

	if ((i == ISI || i == GSI) && gl_n_uk == DEF_n_uk &&
			get_n_beta_set() != get_n_vars())
		gsum = " with unknown means";

	str = (get_mode() == STRATIFY ? "stratified " : "");
	un = (get_n_vars() > 0 && data[0]->dummy ? "un" : "");
	co = (get_mode() == MULTIVARIABLE ? "co" : "");

	switch (i) {
		case NSP:
			snprintf(mstr, MSTR_SIZE, "exit");
			break;
		case TEST:
			snprintf(mstr, MSTR_SIZE, "Test Option");
			break;
		case UIF:
			snprintf(mstr, MSTR_SIZE, "starting interactive mode");
			break;
		case SEM:
			snprintf(mstr, MSTR_SIZE, "calculating sample variogram");
			break;
		case COV:
			snprintf(mstr, MSTR_SIZE, "calculating sample covariogram");
			break;
		case SPREAD:
			snprintf(mstr, MSTR_SIZE, "spread value (distance to nearest observation) on output");
			break;
		case IDW:
			snprintf(mstr, MSTR_SIZE, "%sinverse distance weighted interpolation", str);
			break;
		case MED:
			if (gl_quantile == 0.5)
				snprintf(mstr, MSTR_SIZE, "%smedian estimation", str);
			else
				snprintf(mstr, MSTR_SIZE, "%s%g-quantile estimation", str, gl_quantile);
			break;
		case NRS:
			snprintf(mstr, MSTR_SIZE, "(%s:) neighbourhood size on first output variable", str);
			break;
		case LSLM:
			if (n_variograms_set())
				snprintf(mstr, MSTR_SIZE, "%sgeneralized least squares trend estimation", str);
			else
				snprintf(mstr, MSTR_SIZE, "%sordinary or weighted least squares prediction", str);
			break;
		case OKR:
			snprintf(mstr, MSTR_SIZE, "using %sordinary %skriging", str, co);
			break;
		case SKR:
			snprintf(mstr, MSTR_SIZE, "using %ssimple %skriging", str, co);
			break;
		case UKR:
			snprintf(mstr, MSTR_SIZE, "using %suniversal %skriging", str, co);
			break;
		case GSI:
			snprintf(mstr, MSTR_SIZE, "using %s%sconditional Gaussian %ssimulation%s",
				str, un, co, gsum);
			break;
		case ISI:
			snprintf(mstr, MSTR_SIZE, "using %s%sconditional indicator %ssimulation",
				str, un, co);
			break;
		case DIV:
			snprintf(mstr, MSTR_SIZE, "within-neighbourhood diversity and modus");
			break;
		case SKEW:
			snprintf(mstr, MSTR_SIZE, "skewness and kurtosis");
			break;
		case LSEM:
			snprintf(mstr, MSTR_SIZE, "local semivariance or locally fitted semivariogram parameters");
			break;
	}
	return mstr;
}