Search in sources :

Example 76 with Array

use of org.openmuc.openiec61850.Array in project rosetta by Unidata.

the class SingleProfileTest method convertCtd.

@Test
public void convertCtd() throws IOException, RosettaDataException {
    Path datafile = Paths.get(TestUtils.getTestDataDirStr(), "singleProfile", "CTD", "JD206_2149_AML_CTD.csv");
    Path templatefile = Paths.get(TestUtils.getTestDataDirStr(), "singleProfile", "CTD", "rosetta.template");
    // read template
    Template template = TemplateFactory.makeTemplateFromJsonFile(templatefile);
    // get converter
    NetcdfFileManager dsgWriter = new SingleProfile();
    // hardcode delimiter as comma.
    ctdNetcdfFile = dsgWriter.createNetcdfFile(datafile, template, ",");
    NetcdfFile ncf = NetcdfFile.open(ctdNetcdfFile);
    Assert.assertNotNull(ncf);
    List<RosettaGlobalAttribute> templateGlobalMetadata = template.getGlobalMetadata();
    List<Attribute> actualGlobalMetadata = ncf.getGlobalAttributes();
    // should be more global medata in the netCDF file
    Assert.assertTrue(actualGlobalMetadata.size() > templateGlobalMetadata.size());
    // check that template global metadata are in the netCDF file
    for (RosettaGlobalAttribute rga : templateGlobalMetadata) {
        Attribute ncAttr = ncf.findGlobalAttribute(rga.getName());
        Assert.assertNotNull(ncAttr);
    }
    // check latitude
    Variable lat = ncf.findVariable("latitude");
    Array arr = lat.read();
    Number expected = ncf.findGlobalAttributeIgnoreCase("geospatial_lat_start").getNumericValue();
    Assert.assertEquals(expected.doubleValue(), arr.getDouble(0), 0.0001);
    // check longitude
    Variable lon = ncf.findVariable("longitude");
    arr = lon.read();
    expected = ncf.findGlobalAttributeIgnoreCase("geospatial_lon_start").getNumericValue();
    Assert.assertEquals(expected.doubleValue(), arr.getDouble(0), 0.0001);
    ncf.close();
}
Also used : Path(java.nio.file.Path) NetcdfFile(ucar.nc2.NetcdfFile) Array(ucar.ma2.Array) RosettaGlobalAttribute(edu.ucar.unidata.rosetta.domain.RosettaGlobalAttribute) Variable(ucar.nc2.Variable) Attribute(ucar.nc2.Attribute) RosettaGlobalAttribute(edu.ucar.unidata.rosetta.domain.RosettaGlobalAttribute) Template(edu.ucar.unidata.rosetta.domain.Template) Test(org.junit.Test)

Example 77 with Array

use of org.openmuc.openiec61850.Array in project rosetta by Unidata.

the class SingleProfileTest2 method convertCtd.

@Test
public void convertCtd() throws IOException, RosettaDataException, InvalidRangeException {
    Path datafile = Paths.get(TestUtils.getTestDataDirStr(), "singleProfile", "axctd", "OMG_09132016160633_Ch12_333.edf");
    Path templatefile = Paths.get(TestUtils.getTestDataDirStr(), "singleProfile", "axctd", "rosetta.template");
    // read template
    template = TemplateFactory.makeTemplateFromJsonFile(templatefile);
    // get converter
    NetcdfFileManager dsgWriter = new SingleProfile();
    // hardcode delimiter as comma.
    ctdNetcdfFile = dsgWriter.createNetcdfFile(datafile, template, "\\s+");
    ncf = NetcdfFile.open(ctdNetcdfFile);
    // test not empty
    Assert.assertNotNull(ncf);
    // check global metadata
    List<RosettaGlobalAttribute> templateGlobalMetadata = template.getGlobalMetadata();
    List<Attribute> actualGlobalMetadata = ncf.getGlobalAttributes();
    // should be more global medata in the netCDF file
    Assert.assertTrue(actualGlobalMetadata.size() > templateGlobalMetadata.size());
    // check that template global metadata are in the netCDF file
    for (RosettaGlobalAttribute rga : templateGlobalMetadata) {
        Attribute ncAttr = ncf.findGlobalAttribute(rga.getName());
        Assert.assertNotNull(ncAttr);
    }
    // check latitude
    Variable lat = ncf.findVariable("latitude");
    Array arr = lat.read();
    Number expected = ncf.findGlobalAttributeIgnoreCase("geospatial_lat_start").getNumericValue();
    Assert.assertEquals(expected.doubleValue(), arr.getDouble(0), 0.0001);
    // check longitude
    Variable lon = ncf.findVariable("longitude");
    arr = lon.read();
    expected = ncf.findGlobalAttributeIgnoreCase("geospatial_lon_start").getNumericValue();
    Assert.assertEquals(expected.doubleValue(), arr.getDouble(0), 0.0001);
    // check that status variable was actually written (string / char check)
    Variable status = ncf.findVariable("status");
    int[] origin;
    int[] shape = new int[] { 1, 4 };
    int numVals = status.getShape()[0];
    // all of the status values in this file are "good", or "0000"
    for (int i = 0; i < numVals; i++) {
        origin = new int[] { i, 0 };
        String val = status.read(origin, shape).toString();
        Assert.assertEquals("0000", val);
    }
    // check max/min on a variable
    Variable temperature = ncf.findVariable("temperature");
    Attribute missingValueAttr = temperature.findAttributeIgnoreCase("missing_value");
    Attribute expectedMinAttr = temperature.findAttributeIgnoreCase("valid_min");
    Attribute expectedMaxAttr = temperature.findAttributeIgnoreCase("valid_max");
    float missingValue = (float) missingValueAttr.getValue(0);
    double expectedMin = (double) expectedMinAttr.getValue(0);
    double expectedMax = (double) expectedMaxAttr.getValue(0);
    Array data = temperature.read();
    IndexIterator ii = data.getIndexIterator();
    while (ii.hasNext()) {
        double thisVal = ii.getDoubleNext();
        if (thisVal != missingValue) {
            Assert.assertTrue(thisVal >= expectedMin);
            Assert.assertTrue(thisVal <= expectedMax);
        }
    }
    ncf.close();
}
Also used : Path(java.nio.file.Path) RosettaGlobalAttribute(edu.ucar.unidata.rosetta.domain.RosettaGlobalAttribute) Variable(ucar.nc2.Variable) Attribute(ucar.nc2.Attribute) RosettaGlobalAttribute(edu.ucar.unidata.rosetta.domain.RosettaGlobalAttribute) IndexIterator(ucar.ma2.IndexIterator) Array(ucar.ma2.Array) Test(org.junit.Test)

Example 78 with Array

use of org.openmuc.openiec61850.Array in project rosetta by Unidata.

the class SingleTimeSeriesTest method convertStationXls.

@Test
public void convertStationXls() throws IOException, RosettaDataException, RosettaFileException {
    Path xlsfile = Paths.get(TestUtils.getTestDataDirStr(), "singleStationTimeSeries", "StationSoilTemp", "ilu01_07_10_small.xls");
    tsCsvFile = Paths.get(TestUtils.getTestDataDirStr(), "singleStationTimeSeries", "StationSoilTemp", "ilu01_07_10_small.csv");
    Path templatefile = Paths.get(TestUtils.getTestDataDirStr(), "singleStationTimeSeries", "StationSoilTemp", "rosetta.template");
    // make datafile
    Assert.assertTrue(XlsToCsvUtil.convert(xlsfile.toString(), null));
    // read template
    Template template = TemplateFactory.makeTemplateFromJsonFile(templatefile);
    // get converter
    NetcdfFileManager dsgWriter = new SingleTimeSeries();
    // hardcode delimiter as comma.
    tsNetcdfFile = dsgWriter.createNetcdfFile(tsCsvFile, template, ",");
    NetcdfFile ncf = NetcdfFile.open(tsNetcdfFile);
    Assert.assertNotNull(ncf);
    List<RosettaGlobalAttribute> templateGlobalMetadata = template.getGlobalMetadata();
    List<Attribute> actualGlobalMetadata = ncf.getGlobalAttributes();
    // should be more global medata in the netCDF file
    Assert.assertTrue(actualGlobalMetadata.size() > templateGlobalMetadata.size());
    // check that template global metadata are in the netCDF file
    for (RosettaGlobalAttribute rga : templateGlobalMetadata) {
        Attribute ncAttr = ncf.findGlobalAttribute(rga.getName());
        Assert.assertNotNull(ncAttr);
    }
    // check latitude
    Variable lat = ncf.findVariable("latitude");
    Array arr = lat.read();
    Number expected = ncf.findGlobalAttributeIgnoreCase("geospatial_lat_start").getNumericValue();
    Assert.assertEquals(expected.doubleValue(), arr.getDouble(0), 0.0001);
    // check longitude
    Variable lon = ncf.findVariable("longitude");
    arr = lon.read();
    expected = ncf.findGlobalAttributeIgnoreCase("geospatial_lon_start").getNumericValue();
    Assert.assertEquals(expected.doubleValue(), arr.getDouble(0), 0.0001);
    ncf.close();
}
Also used : Path(java.nio.file.Path) NetcdfFile(ucar.nc2.NetcdfFile) Array(ucar.ma2.Array) RosettaGlobalAttribute(edu.ucar.unidata.rosetta.domain.RosettaGlobalAttribute) Variable(ucar.nc2.Variable) Attribute(ucar.nc2.Attribute) RosettaGlobalAttribute(edu.ucar.unidata.rosetta.domain.RosettaGlobalAttribute) Template(edu.ucar.unidata.rosetta.domain.Template) Test(org.junit.Test)

Example 79 with Array

use of org.openmuc.openiec61850.Array in project rosetta by Unidata.

the class TestTagUniversalFileFormatOneLocManyOb method testNoMatchup.

@Test
public void testNoMatchup() throws IOException {
    // for this date and ob:
    // "2005-04-15 21:33:00",6,23.30,"temperature","Celsius"
    // there is no lat/lon matchup
    // this tests makes sure it is matched with a location, as
    // we are doing a many ob to one loc matchup
    CalendarDate findTimeCd = CalendarDate.parseISOformat("gregorian", "2005-04-15 21:33:00");
    long findTime = findTimeCd.toDate().getTime() / 1000;
    Variable time = ncd.findVariable("time");
    Array timeVals = time.read();
    boolean found = false;
    int foundIndex = 0;
    for (int i = 0; i < timeVals.getSize(); i++) {
        long checkTime = timeVals.getLong(i);
        if (checkTime == findTime) {
            found = true;
            foundIndex = i;
        }
    }
    assertTrue(found);
    // check that temperature value is as expected
    Variable temp = ncd.findVariable("temperature");
    Array tempVals = temp.read();
    assertEquals(23.30, tempVals.getFloat(foundIndex), 0.001);
}
Also used : Array(ucar.ma2.Array) CalendarDate(ucar.nc2.time.CalendarDate) Variable(ucar.nc2.Variable) Test(org.junit.Test)

Example 80 with Array

use of org.openmuc.openiec61850.Array in project rosetta by Unidata.

the class TestTagUniversalFileFormatOneLocOneOb method testNoMatchup.

@Test
public void testNoMatchup() throws IOException {
    // for this date and ob:
    // "2005-04-15 21:33:00",6,23.30,"temperature","Celsius"
    // there is no lat/lon matchup
    CalendarDate findTimeCd = CalendarDate.parseISOformat("gregorian", "2005-04-15 21:33:00");
    long findTime = findTimeCd.toDate().getTime() / 1000;
    Variable time = ncd.findVariable("time");
    Array timeVals = time.read();
    boolean found = false;
    for (int i = 0; i < timeVals.getSize(); i++) {
        long checkTime = timeVals.getLong(i);
        if (checkTime == findTime) {
            found = true;
        }
    }
    assertFalse(found);
}
Also used : Array(ucar.ma2.Array) CalendarDate(ucar.nc2.time.CalendarDate) Variable(ucar.nc2.Variable) Test(org.junit.Test)

Aggregations

Array (ucar.ma2.Array)72 Variable (ucar.nc2.Variable)41 IOException (java.io.IOException)36 Attribute (ucar.nc2.Attribute)29 InvalidRangeException (ucar.ma2.InvalidRangeException)20 Index (ucar.ma2.Index)18 ArrayList (java.util.ArrayList)17 Dimension (ucar.nc2.Dimension)15 NetcdfFile (ucar.nc2.NetcdfFile)15 ArrayFloat (ucar.ma2.ArrayFloat)13 File (java.io.File)12 RosettaGlobalAttribute (edu.ucar.unidata.rosetta.domain.RosettaGlobalAttribute)9 Test (org.junit.Test)9 ArrayDouble (ucar.ma2.ArrayDouble)9 DataType (ucar.ma2.DataType)9 WritableRaster (java.awt.image.WritableRaster)8 ProcedureTree (org.geotoolkit.observation.model.ExtractionResult.ProcedureTree)8 GeoSpatialBound (org.geotoolkit.observation.model.GeoSpatialBound)8 Process (org.geotoolkit.observation.xml.Process)8 NetcdfFileWriteable (ucar.nc2.NetcdfFileWriteable)8