use of org.opengis.referencing.operation.MathTransform1D in project sis by apache.
the class TransferFunction method setTransform.
/**
* Sets the transform from sample values to geophysics values.
* This method infers the {@linkplain #getBase() base}, {@linkplain #getScale() scale} and
* {@linkplain #getOffset() offset} values from the given transform.
*
* @param function the transform to set.
* @throws IllegalArgumentException if this method does not recognize the given transform.
*/
public void setTransform(final MathTransform1D function) throws IllegalArgumentException {
ArgumentChecks.ensureNonNull("function", function);
if (function instanceof LinearTransform) {
setLinearTerms((LinearTransform) function);
type = TransferFunctionType.LINEAR;
} else if (function instanceof ExponentialTransform1D) {
final ExponentialTransform1D f = (ExponentialTransform1D) function;
type = TransferFunctionType.EXPONENTIAL;
base = f.base;
scale = f.scale;
offset = 0;
} else if (function instanceof LogarithmicTransform1D) {
final LogarithmicTransform1D f = (LogarithmicTransform1D) function;
type = TransferFunctionType.LOGARITHMIC;
base = f.base();
offset = f.offset();
scale = 1;
} else {
/*
* If we did not recognized one of the known types, maybe the given function
* is the result of some concatenation. Try to concatenate a logarithmic or
* exponential transform and see if the result is linear.
*/
final LogarithmicTransform1D log = LogarithmicTransform1D.Base10.INSTANCE;
MathTransform1D f = MathTransforms.concatenate(function, log);
if (f instanceof LinearTransform) {
setLinearTerms((LinearTransform) f);
type = TransferFunctionType.EXPONENTIAL;
base = 10;
} else {
f = MathTransforms.concatenate(log.inverse(), function);
if (f instanceof LinearTransform) {
setLinearTerms((LinearTransform) f);
type = TransferFunctionType.LOGARITHMIC;
base = 10;
} else {
throw new IllegalArgumentException(Errors.format(Errors.Keys.UnknownType_1, function.getClass()));
}
}
}
transform = function;
}
use of org.opengis.referencing.operation.MathTransform1D in project sis by apache.
the class TransferFunctionTest method testExponential.
/**
* Tests the creation of an exponential transfer function.
*/
@Test
@DependsOnMethod("testLinear")
public void testExponential() {
final TransferFunction f = new TransferFunction();
f.setType(TransferFunctionType.EXPONENTIAL);
f.setScale(0.15);
assertEquals("base", 10, f.getBase(), STRICT);
assertEquals("toString", "y = 0.15⋅10ˣ", f.toString());
final MathTransform1D transform = f.getTransform();
assertInstanceOf("transform", ExponentialTransform1D.class, transform);
/*
* Get back the coefficients.
*/
final TransferFunction b = new TransferFunction();
b.setTransform(transform);
assertEquals("type", TransferFunctionType.EXPONENTIAL, b.getType());
assertEquals("base", 10, b.getBase(), STRICT);
assertEquals("scale", 0.15, b.getScale(), STRICT);
assertEquals("offset", 0, b.getOffset(), STRICT);
}
use of org.opengis.referencing.operation.MathTransform1D in project sis by apache.
the class TransferFunctionTest method testConcatenated.
/**
* Tests the creation of a concatenated transfer function.
*/
@Test
@DependsOnMethod("testLogarithmic")
public void testConcatenated() {
final TransferFunction f = new TransferFunction();
f.setType(TransferFunctionType.LOGARITHMIC);
f.setScale(0.15);
f.setOffset(-2);
assertEquals("toString", "y = 0.15⋅㏒⒳ − 2", f.toString());
final MathTransform1D transform = f.getTransform();
assertInstanceOf("transform", ConcatenatedTransformDirect1D.class, transform);
/*
* Get back the coefficients.
*/
final TransferFunction b = new TransferFunction();
b.setTransform(transform);
assertEquals("type", TransferFunctionType.LOGARITHMIC, b.getType());
assertEquals("base", 10, b.getBase(), STRICT);
assertEquals("scale", 0.15, b.getScale(), 1E-16);
assertEquals("offset", -2, b.getOffset(), 1E-16);
}
use of org.opengis.referencing.operation.MathTransform1D in project sis by apache.
the class TransferFunctionTest method testLogarithmic.
/**
* Tests the creation of a logarithmic transfer function.
*/
@Test
@DependsOnMethod("testLinear")
public void testLogarithmic() {
final TransferFunction f = new TransferFunction();
f.setType(TransferFunctionType.LOGARITHMIC);
f.setOffset(-2);
assertEquals("base", 10, f.getBase(), STRICT);
assertEquals("toString", "y = ㏒⒳ − 2", f.toString());
final MathTransform1D transform = f.getTransform();
assertInstanceOf("transform", LogarithmicTransform1D.class, transform);
/*
* Get back the coefficients.
*/
final TransferFunction b = new TransferFunction();
b.setTransform(transform);
assertEquals("type", TransferFunctionType.LOGARITHMIC, b.getType());
assertEquals("base", 10, b.getBase(), STRICT);
assertEquals("scale", 1, b.getScale(), STRICT);
assertEquals("offset", -2, b.getOffset(), STRICT);
}
use of org.opengis.referencing.operation.MathTransform1D in project sis by apache.
the class LinearInterpolator1DTest method testArgumentChecks.
/**
* Verifies that the factory method does not accept invalid arguments.
*/
@Test
public void testArgumentChecks() {
// Non-monotonic sequence.
preimage = new double[] { -43, 7, -19, 105 };
values = new double[] { 1017, 525, 24, 12 };
try {
LinearInterpolator1D.create(preimage, values);
fail("Should not have accepted the x inputs.");
} catch (IllegalArgumentException e) {
final String message = e.getMessage();
assertTrue(message, message.contains("preimage"));
}
preimage = new double[] { 1017, 525, 24, 12 };
values = new double[] { -43, 7, -19, 105 };
MathTransform1D mt = LinearInterpolator1D.create(preimage, values);
try {
mt.inverse();
fail("Should not have accepted the inverse that transform.");
} catch (NoninvertibleTransformException e) {
final String message = e.getMessage();
assertFalse(message, message.isEmpty());
}
// Mismatched array length.
preimage = new double[] { 1017, 525, 24, 12, 45 };
values = new double[] { -43, 7, -19, 105 };
try {
LinearInterpolator1D.create(preimage, values);
fail("Should not have accepted the x inputs.");
} catch (IllegalArgumentException e) {
final String message = e.getMessage();
assertFalse(message, message.isEmpty());
}
}
Aggregations