Skip to content
Snippets Groups Projects
Commit fb69129f authored by Clayton, Brandon Scott's avatar Clayton, Brandon Scott
Browse files

add abstract class to read in all files

parent 6f1db0b6
No related branches found
No related tags found
2 merge requests!128Production Release | nshmp-ws-static,!127Resolves - Handle Multiple NetCDF Files for AASHTO Service
package gov.usgs.earthquake.nshmp.netcdf;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import gov.usgs.earthquake.nshmp.gmm.NehrpSiteClass;
/**
* Read in all NetCDF files associated with a {@link NetcdfDataType},
* holds {@link Netcdf} objects associated with each NetCDF file.
*
* @author U.S. Geological Survey
*/
public abstract class NetcdfDataFiles<T extends Netcdf<?>> extends ArrayList<T> {
private final Path netcdfPath;
private final NetcdfDataType dataType;
public NetcdfDataFiles(Path netcdfPath, NetcdfDataType dataType) {
super();
this.netcdfPath = netcdfPath;
this.dataType = dataType;
}
/**
* Returns the path to the directory where all NetCDF files are.
*/
public Path netcdfPath() {
return netcdfPath;
}
/**
* Returns the data type of the NetCDF files.
*/
public NetcdfDataType dataType() {
return dataType;
}
/**
* Returns the set of NEHRP site classes for all data files.
*/
public Set<NehrpSiteClass> siteClasses() {
return stream()
.flatMap(netcdf -> netcdf.netcdfData().siteClasses().stream())
.sorted()
.collect(Collectors.toSet());
}
/**
* Find NetCDF files (.nc) with specific {@link NetcdfDataType}.
*
* @param netcdfPath Path to NetCDF files
* @param dataType The data type to filter by
* @throws IOException
*/
protected Stream<Path> walkFiles(Path netcdfPath, NetcdfDataType dataType) throws IOException {
return Files.walk(netcdfPath)
.filter(file -> file.getFileName().toString().endsWith(".nc"))
.filter(file -> NetcdfDataType.getDataType(file) == dataType);
}
/**
* Returns the list of {@link Netcdf} objects associated with a NetCDF file
* and {@link NetcdfDataType}.
*
* @param netcdfPath The path to NetCDF files
* @param dataType The data type to read in
* @throws IOException
*/
protected abstract List<T> readFiles(Path netcdfPath, NetcdfDataType dataType);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment