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();
}
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();
}
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();
}
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);
}
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);
}
Aggregations