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

Netcdf data files for hazard curves class

parent aac6d4ee
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.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import gov.usgs.earthquake.nshmp.gmm.Imt;
/**
* Read in and parse all hazard NetCDF data files.
*
* @author U.S. Geological Survey
*/
public class NetcdfDataFilesHazardCurves extends NetcdfDataFiles<NetcdfHazardCurves> {
public NetcdfDataFilesHazardCurves(Path netcdfPath) {
super(netcdfPath, NetcdfDataType.HAZARD_CURVES);
addAll(readFiles(netcdfPath, dataType()));
}
/**
* Returns the set of NEHRP site classes for all data files.
*/
public Set<Imt> imts() {
return stream()
.flatMap(netcdf -> netcdf.netcdfData().imts().stream())
.sorted()
.collect(Collectors.toSet());
}
/**
* Returns the Netcdf object associated with a location.
*
* @param location The location to find the NetCDF object
* @throws IllegalArgumentException If no location is contained in a Netcdf
* object.
*/
public NetcdfHazardCurves netcdf(Nshm nshm) {
return stream()
.filter(netcdf -> netcdf.nshm() == nshm)
.findFirst()
.orElseThrow(() -> new IllegalArgumentException(
String.format("NSHM %s not found in data sets.", nshm)));
}
/**
* Returns the {@link Nshm NSHMs} associated with the data sets read in.
*/
public Set<Nshm> nshms() {
return stream()
.map(netcdf -> netcdf.nshm())
.sorted()
.collect(Collectors.toSet());
}
@Override
protected List<NetcdfHazardCurves> readFiles(Path netcdfPath, NetcdfDataType dataType) {
try {
List<NetcdfHazardCurves> data = walkFiles(netcdfPath, dataType)
.map(NetcdfHazardCurves::new)
.collect(Collectors.toList());
if (data.isEmpty()) {
throw new FileNotFoundException("Failed to find hazard NetCDF files");
}
return List.copyOf(data);
} catch (IOException e) {
throw new RuntimeException("Failed to read NetCDF directory " + netcdfPath, e);
}
}
}
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