Search in sources :

Example 6 with MathTransform1D

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;
}
Also used : MathTransform1D(org.opengis.referencing.operation.MathTransform1D)

Example 7 with MathTransform1D

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);
}
Also used : MathTransform1D(org.opengis.referencing.operation.MathTransform1D) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 8 with MathTransform1D

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);
}
Also used : MathTransform1D(org.opengis.referencing.operation.MathTransform1D) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 9 with MathTransform1D

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);
}
Also used : MathTransform1D(org.opengis.referencing.operation.MathTransform1D) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 10 with MathTransform1D

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());
    }
}
Also used : NoninvertibleTransformException(org.opengis.referencing.operation.NoninvertibleTransformException) MathTransform1D(org.opengis.referencing.operation.MathTransform1D) Test(org.junit.Test)

Aggregations

MathTransform1D (org.opengis.referencing.operation.MathTransform1D)13 Test (org.junit.Test)5 DependsOnMethod (org.apache.sis.test.DependsOnMethod)3 MathTransform2D (org.opengis.referencing.operation.MathTransform2D)2 NoninvertibleTransformException (org.opengis.referencing.operation.NoninvertibleTransformException)2 Random (java.util.Random)1 Matrix2 (org.apache.sis.referencing.operation.matrix.Matrix2)1 After (org.junit.After)1 MismatchedDimensionException (org.opengis.geometry.MismatchedDimensionException)1 MathTransform (org.opengis.referencing.operation.MathTransform)1 Matrix (org.opengis.referencing.operation.Matrix)1 TransformException (org.opengis.referencing.operation.TransformException)1 FactoryException (org.opengis.util.FactoryException)1