@Disabled @Test void CmipPrecipImport(){ String inFile = new File("D:/data/CMIP/Extraction_pr.nc").toString(); DataReader reader = DataReader.builder() .path(inFile) .variable("pr") .build(); VortexData vortexData = reader.getDto(0); VortexGrid vortexGrid = (VortexGrid) vortexData; float[] data = vortexGrid.data(); List<Double> values = new ArrayList<>(); for (int i = 1; i < data.length; i++) { if (!Float.isNaN(data[i])) { values.add((double) data[i]); } } double max = Collections.max(values); double min = Collections.min(values); assertEquals(66.21134185791016, max, 1E-5); assertEquals(0.04108993336558342, min, 1E-5); }
@Override public VortexData getDto(int idx) { try (NetcdfDataset ncd = NetcdfDatasets.openDataset(path); Formatter errlog = new Formatter()) { FeatureDataset dataset = FeatureDatasetFactoryManager.wrap(FeatureType.GRID, ncd, null, errlog); if (dataset != null) { FeatureType ftype = dataset.getFeatureType(); if (ftype == FeatureType.GRID) { assert (dataset instanceof GridDataset); GridDataset gridDataset = (GridDataset) dataset; return getData(gridDataset, variableName, idx); } } else { List<Variable> variables = ncd.getVariables(); for (Variable variable : variables){ if (variable.getShortName().equals(variableName) && variable instanceof VariableDS) { VariableDS variableDS = (VariableDS) variable; List<CoordinateSystem> coordinateSystems = variableDS.getCoordinateSystems(); if (!coordinateSystems.isEmpty()) { VariableDsReader reader = VariableDsReader.builder() .setNetcdfFile(ncd) .setVariableName(variableName) .build(); return reader.read(idx); } } } } } catch (IOException e) { logger.log(Level.SEVERE, e, e::getMessage); } return null; }
NetcdfDataReader extends DataReader { @Override public VortexData getDto(int idx) { try (NetcdfDataset ncd = NetcdfDatasets.openDataset(path); Formatter errlog = new Formatter()) { FeatureDataset dataset = FeatureDatasetFactoryManager.wrap(FeatureType.GRID, ncd, null, errlog); if (dataset != null) { FeatureType ftype = dataset.getFeatureType(); if (ftype == FeatureType.GRID) { assert (dataset instanceof GridDataset); GridDataset gridDataset = (GridDataset) dataset; return getData(gridDataset, variableName, idx); } } else { List<Variable> variables = ncd.getVariables(); for (Variable variable : variables){ if (variable.getShortName().equals(variableName) && variable instanceof VariableDS) { VariableDS variableDS = (VariableDS) variable; List<CoordinateSystem> coordinateSystems = variableDS.getCoordinateSystems(); if (!coordinateSystems.isEmpty()) { VariableDsReader reader = VariableDsReader.builder() .setNetcdfFile(ncd) .setVariableName(variableName) .build(); return reader.read(idx); } } } } } catch (IOException e) { logger.log(Level.SEVERE, e, e::getMessage); } return null; } }
NetcdfDataReader extends DataReader { @Override public VortexData getDto(int idx) { try (NetcdfDataset ncd = NetcdfDatasets.openDataset(path); Formatter errlog = new Formatter()) { FeatureDataset dataset = FeatureDatasetFactoryManager.wrap(FeatureType.GRID, ncd, null, errlog); if (dataset != null) { FeatureType ftype = dataset.getFeatureType(); if (ftype == FeatureType.GRID) { assert (dataset instanceof GridDataset); GridDataset gridDataset = (GridDataset) dataset; return getData(gridDataset, variableName, idx); } } else { List<Variable> variables = ncd.getVariables(); for (Variable variable : variables){ if (variable.getShortName().equals(variableName) && variable instanceof VariableDS) { VariableDS variableDS = (VariableDS) variable; List<CoordinateSystem> coordinateSystems = variableDS.getCoordinateSystems(); if (!coordinateSystems.isEmpty()) { VariableDsReader reader = VariableDsReader.builder() .setNetcdfFile(ncd) .setVariableName(variableName) .build(); return reader.read(idx); } } } } } catch (IOException e) { logger.log(Level.SEVERE, e, e::getMessage); } return null; } NetcdfDataReader(DataReaderBuilder builder); }
NetcdfDataReader extends DataReader { @Override public VortexData getDto(int idx) { try (NetcdfDataset ncd = NetcdfDatasets.openDataset(path); Formatter errlog = new Formatter()) { FeatureDataset dataset = FeatureDatasetFactoryManager.wrap(FeatureType.GRID, ncd, null, errlog); if (dataset != null) { FeatureType ftype = dataset.getFeatureType(); if (ftype == FeatureType.GRID) { assert (dataset instanceof GridDataset); GridDataset gridDataset = (GridDataset) dataset; return getData(gridDataset, variableName, idx); } } else { List<Variable> variables = ncd.getVariables(); for (Variable variable : variables){ if (variable.getShortName().equals(variableName) && variable instanceof VariableDS) { VariableDS variableDS = (VariableDS) variable; List<CoordinateSystem> coordinateSystems = variableDS.getCoordinateSystems(); if (!coordinateSystems.isEmpty()) { VariableDsReader reader = VariableDsReader.builder() .setNetcdfFile(ncd) .setVariableName(variableName) .build(); return reader.read(idx); } } } } } catch (IOException e) { logger.log(Level.SEVERE, e, e::getMessage); } return null; } NetcdfDataReader(DataReaderBuilder builder); @Override List<VortexData> getDtos(); @Override VortexData getDto(int idx); @Override int getDtoCount(); static Set<String> getVariables(String path); }
NetcdfDataReader extends DataReader { @Override public VortexData getDto(int idx) { try (NetcdfDataset ncd = NetcdfDatasets.openDataset(path); Formatter errlog = new Formatter()) { FeatureDataset dataset = FeatureDatasetFactoryManager.wrap(FeatureType.GRID, ncd, null, errlog); if (dataset != null) { FeatureType ftype = dataset.getFeatureType(); if (ftype == FeatureType.GRID) { assert (dataset instanceof GridDataset); GridDataset gridDataset = (GridDataset) dataset; return getData(gridDataset, variableName, idx); } } else { List<Variable> variables = ncd.getVariables(); for (Variable variable : variables){ if (variable.getShortName().equals(variableName) && variable instanceof VariableDS) { VariableDS variableDS = (VariableDS) variable; List<CoordinateSystem> coordinateSystems = variableDS.getCoordinateSystems(); if (!coordinateSystems.isEmpty()) { VariableDsReader reader = VariableDsReader.builder() .setNetcdfFile(ncd) .setVariableName(variableName) .build(); return reader.read(idx); } } } } } catch (IOException e) { logger.log(Level.SEVERE, e, e::getMessage); } return null; } NetcdfDataReader(DataReaderBuilder builder); @Override List<VortexData> getDtos(); @Override VortexData getDto(int idx); @Override int getDtoCount(); static Set<String> getVariables(String path);  }