Search in sources :

Example 1 with QuantifiedValue

use of org.tensorics.core.quantity.QuantifiedValue in project tensorics-core by tensorics.

the class FakeMeteoDataImporter method importFromPastCorrupted.

public static Tensor<QuantifiedValue<Double>> importFromPastCorrupted() {
    Set<Class<?>> dimensions = ImmutableSet.of(Time.class, Longitude.class, Latitude.class);
    Builder<QuantifiedValue<Double>> tensorBuilder = ImmutableTensor.<QuantifiedValue<Double>>builder(dimensions);
    Random rand = new Random();
    for (int x = 0; x < 10; x++) {
        for (int y = 0; y < 10; y++) {
            for (int t = 0; t < 10; t++) {
                if (y != 5) {
                    QuantifiedValue<Double> entryValue = ImmutableQuantifiedValue.<Double>of(rand.nextDouble(), JScienceUnit.of(SI.CELSIUS));
                    tensorBuilder.put(Position.of(new Time(t), new Longitude(x), new Latitude(y)), entryValue);
                }
            }
        }
    }
    return tensorBuilder.build();
}
Also used : Random(java.util.Random) Time(org.tensorics.core.examples.meteo.domain.coordinates.Time) Latitude(org.tensorics.core.examples.meteo.domain.coordinates.Latitude) Longitude(org.tensorics.core.examples.meteo.domain.coordinates.Longitude) QuantifiedValue(org.tensorics.core.quantity.QuantifiedValue) ImmutableQuantifiedValue(org.tensorics.core.quantity.ImmutableQuantifiedValue)

Example 2 with QuantifiedValue

use of org.tensorics.core.quantity.QuantifiedValue in project tensorics-core by tensorics.

the class MeteoDataImporterTest method testAverageTemperatureByTime.

@Test
public void testAverageTemperatureByTime() {
    Tensor<QuantifiedValue<Double>> importFromPast = FakeMeteoDataImporter.importFromPast();
    Tensor<Double> byAveragingIn = from(QuantityTensors.valuesOf(importFromPast)).reduce(Time.class).byAveragingIn(Structures.doubles());
    System.out.println("Averaged over time " + byAveragingIn);
    Tensor<Double> tempAtTime4 = from(QuantityTensors.valuesOf(importFromPast)).extract(new Time(4));
    System.out.println("Sliced on time = 4 " + tempAtTime4);
}
Also used : Time(org.tensorics.core.examples.meteo.domain.coordinates.Time) QuantifiedValue(org.tensorics.core.quantity.QuantifiedValue) Test(org.junit.Test)

Example 3 with QuantifiedValue

use of org.tensorics.core.quantity.QuantifiedValue in project tensorics-core by tensorics.

the class WeatherHistoryInEurope method calculate.

// tag::import[]
/*
     * calculate an average monthly temperature at the ROME Latitude like cities
     */
@SuppressWarnings("unused")
public void calculate() {
    Tensor<QuantifiedValue<Double>> importedData = importDataForCities();
    Latitude romeLatitude = EuropeanCapital.ROMA.getLatitude();
    Tensor<QuantifiedValue<Double>> sliceAtTropicCancerAndRome = from(importedData).extract(romeLatitude);
    Temperature temperature = new Temperature(importedData);
    Tensor<QuantifiedValue<Double>> elementTimes = calculateQ(importedData).elementTimes(importedData);
    Temperature elementTimes2 = calculateQ(temperature).elementTimes(temperature);
    /* dimension will be reduced to only Longitude and Time */
    sliceAtTropicCancerAndRome.shape().dimensionSet();
    // 
    // from(sliceAtTropicCancerAndRome).reduce(Time.class).byAveragingIn(field)
    TensoricSupport<Double> fullTensoricSupport = Tensorics.using(Structures.doubles());
}
Also used : Temperature(org.tensorics.core.examples.meteo.domain.Temperature) Latitude(org.tensorics.core.examples.meteo.domain.coordinates.Latitude) QuantifiedValue(org.tensorics.core.quantity.QuantifiedValue)

Example 4 with QuantifiedValue

use of org.tensorics.core.quantity.QuantifiedValue in project tensorics-core by tensorics.

the class TensorCalculationsTest method profileQuantifiedRepetitiveTensor.

@Ignore
@Test
public void profileQuantifiedRepetitiveTensor() {
    final Unit unit = JScienceUnit.of(SI.METER);
    CoordinateRange range = CoordinateRange.fromSize(TensorSize.ofXYZ(100, 1000, 1));
    List<ProfileResult> results = profileTensorCreationNTimes(10, range, new ValueFactory<QuantifiedValue<Double>>() {

        @Override
        public QuantifiedValue<Double> create(int x, int y, int z) {
            return Tensorics.quantityOf(valueForBig(x, y, z, 2.0), unit).withError(0.0);
        }
    });
    printProfileResult(results);
}
Also used : Unit(org.tensorics.core.units.Unit) JScienceUnit(org.tensorics.core.units.JScienceUnit) QuantifiedValue(org.tensorics.core.quantity.QuantifiedValue) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with QuantifiedValue

use of org.tensorics.core.quantity.QuantifiedValue in project tensorics-core by tensorics.

the class FakeMeteoDataImporter method importFromPast.

public static Tensor<QuantifiedValue<Double>> importFromPast() {
    Set<Class<?>> dimensions = ImmutableSet.of(Time.class, Longitude.class, Latitude.class);
    Builder<QuantifiedValue<Double>> tensorBuilder = ImmutableTensor.<QuantifiedValue<Double>>builder(dimensions);
    Random rand = new Random();
    for (int x = 0; x < 10; x++) {
        for (int y = 0; y < 10; y++) {
            for (int t = 0; t < 10; t++) {
                QuantifiedValue<Double> entryValue = ImmutableQuantifiedValue.<Double>of(rand.nextDouble(), JScienceUnit.of(SI.CELSIUS));
                tensorBuilder.put(Position.of(new Time(t), new Longitude(x), new Latitude(y)), entryValue);
            }
        }
    }
    return tensorBuilder.build();
}
Also used : Random(java.util.Random) Time(org.tensorics.core.examples.meteo.domain.coordinates.Time) Latitude(org.tensorics.core.examples.meteo.domain.coordinates.Latitude) Longitude(org.tensorics.core.examples.meteo.domain.coordinates.Longitude) QuantifiedValue(org.tensorics.core.quantity.QuantifiedValue) ImmutableQuantifiedValue(org.tensorics.core.quantity.ImmutableQuantifiedValue)

Aggregations

QuantifiedValue (org.tensorics.core.quantity.QuantifiedValue)6 Latitude (org.tensorics.core.examples.meteo.domain.coordinates.Latitude)4 Time (org.tensorics.core.examples.meteo.domain.coordinates.Time)4 Random (java.util.Random)3 Longitude (org.tensorics.core.examples.meteo.domain.coordinates.Longitude)3 ImmutableQuantifiedValue (org.tensorics.core.quantity.ImmutableQuantifiedValue)3 Test (org.junit.Test)2 Ignore (org.junit.Ignore)1 Temperature (org.tensorics.core.examples.meteo.domain.Temperature)1 MeteoCoordinate (org.tensorics.core.examples.meteo.domain.coordinates.MeteoCoordinate)1 JScienceUnit (org.tensorics.core.units.JScienceUnit)1 Unit (org.tensorics.core.units.Unit)1