Commit a7d8f2a7 authored by Purves, Murray's avatar Purves, Murray
Browse files

Adding bindings for interpolate_to_other_base_values

parent 4ec904f3
Pipeline #27636 failed with stages
in 1 minute and 21 seconds
......@@ -27,9 +27,45 @@ static PyObject* interpolate_values(PyObject* self, PyObject* args)
pyObjectToDoubleVector(valuesToInterpObj);
// Carry out the interpolation
std::vector<double> interpolatedValuesVec = radix::interpolateValues(
baseValuesVec, valuesToInterpVec, circular, missingValue
);
std::vector<double> interpolatedValuesVec =
radix::interpolateValues(baseValuesVec, valuesToInterpVec, circular,
missingValue);
// Convert the result back into a Python object
PyObject* interpolatedValuesObj =
doubleVectorToListPyObject(interpolatedValuesVec);
return interpolatedValuesObj;
}
static PyObject* interpolate_to_other_base_values(PyObject* self,
PyObject* args)
{
PyObject* baseValuesObj;
PyObject* newBaseValuesObj;
PyObject* valuesToInterpObj;
bool circular;
double missingValue;
// Get the arguments from the call
if (!PyArg_ParseTuple(args, "OOOpd", &baseValuesObj, &newBaseValuesObj,
&valuesToInterpObj, &circular, &missingValue))
{
return NULL;
}
// Parse the vector arguments
std::vector<double> baseValuesVec = pyObjectToDoubleVector(baseValuesObj);
std::vector<double> newBaseValuesVec =
pyObjectToDoubleVector(newBaseValuesObj);
std::vector<double> valuesToInterpVec =
pyObjectToDoubleVector(valuesToInterpObj);
// Carry out the interpolation
std::vector<double> interpolatedValuesVec =
radix::interpolateToOtherBaseValues(baseValuesVec, newBaseValuesVec,
valuesToInterpVec, circular,
missingValue);
// Convert the result back into a Python object
PyObject* interpolatedValuesObj =
......@@ -52,7 +88,10 @@ static PyObject* interpolate_values(PyObject* self, PyObject* args)
// }
static PyMethodDef interpolate_methods[] = {
{"interpolate_values", interpolate_values, METH_VARARGS, "Interpolate/extrapolate missing values from a data vector"},
{"interpolate_values", interpolate_values, METH_VARARGS,
"Interpolate/extrapolate missing values from a data vector"},
{"interpolate_to_other_base_values", interpolate_to_other_base_values,
METH_VARARGS, "Interpolate/extrapolate missing values from a data vector to a new set of base values"},
{NULL, NULL, 0, NULL},
};
......
......@@ -4,16 +4,35 @@ missing_value = -9999.0
tolerance = 0.0001
circular = False
# Basic test of interpolate_values
print("Testing interpolate_values...")
base_values = [10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0]
interp_values = [1.0, missing_value, 3.0, missing_value, 6.0, missing_value,
1.0]
expect_values = [1.0, 2.0, 3.0, 4.5, 6.0, 3.5, 1.0]
print("Base values: ", str(base_values))
print("Before interpolation: ", str(interp_values))
print(" Base values: ", str(base_values))
print(" Before interpolation: ", str(interp_values))
test_values = interpolate.interpolate_values(base_values, interp_values,
circular, missing_value)
print("After interpolation: ", str(interp_values))
print("Expected values: ", str(expect_values))
print(" After interpolation: ", str(test_values))
print(" Expected values: ", str(expect_values))
print("Testing interpolate_to_other_base_values")
base_values = [1000.0, 2000.0, 3000.0]
new_base_values = [500.0, 1500.0, 2500.0, 3500.0]
interp_values = [10.5, missing_value, 30.5]
expect_values = [10.5, 15.5, 25.5, 30.5]
print(" Base values: ", str(base_values))
print(" Before interpolation: ", str(interp_values))
test_values = interpolate.interpolate_to_other_base_values(
base_values, new_base_values, interp_values, circular, missing_value
)
print(" New base values: ", str(new_base_values))
print(" After interpolation: ", str(test_values))
print(" Expected values: ", str(expect_values))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment