diff --git a/src/hazard/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfServiceHazardCurves.java b/src/hazard/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfServiceHazardCurves.java index 831ccfc27c2c2ef6ee691fd0fe6891191bf463fe..85b162f32c4dc40e9545275a3f276c7c8349eee7 100644 --- a/src/hazard/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfServiceHazardCurves.java +++ b/src/hazard/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfServiceHazardCurves.java @@ -6,16 +6,18 @@ import java.util.stream.Collectors; import gov.usgs.earthquake.nshmp.data.XySequence; import gov.usgs.earthquake.nshmp.geo.Location; import gov.usgs.earthquake.nshmp.gmm.Imt; +import gov.usgs.earthquake.nshmp.netcdf.NetcdfDataFilesHazardCurves; import gov.usgs.earthquake.nshmp.netcdf.NetcdfHazardCurves; import gov.usgs.earthquake.nshmp.netcdf.NetcdfVersion; +import gov.usgs.earthquake.nshmp.netcdf.Nshm; import gov.usgs.earthquake.nshmp.netcdf.data.StaticData; import gov.usgs.earthquake.nshmp.netcdf.data.StaticDataHazardCurves; -import gov.usgs.earthquake.nshmp.netcdf.www.Metadata.HazardResponseMetadata; +import gov.usgs.earthquake.nshmp.netcdf.www.HazardMetadata.HazardResponseMetadata; import gov.usgs.earthquake.nshmp.netcdf.www.NetcdfWsUtils.Key; import gov.usgs.earthquake.nshmp.netcdf.www.Query.Service; -import gov.usgs.earthquake.nshmp.netcdf.www.Request.RequestData; -import gov.usgs.earthquake.nshmp.netcdf.www.Request.RequestDataImt; -import gov.usgs.earthquake.nshmp.netcdf.www.Request.RequestDataSiteClass; +import gov.usgs.earthquake.nshmp.netcdf.www.RequestHazardCurves.HazardRequestData; +import gov.usgs.earthquake.nshmp.netcdf.www.RequestHazardCurves.HazardRequestDataImt; +import gov.usgs.earthquake.nshmp.netcdf.www.RequestHazardCurves.HazardRequestDataSiteClass; import gov.usgs.earthquake.nshmp.www.ResponseBody; import gov.usgs.earthquake.nshmp.www.ResponseMetadata; import gov.usgs.earthquake.nshmp.www.WsUtils; @@ -35,8 +37,8 @@ public class NetcdfServiceHazardCurves extends NetcdfService<HazardQuery> { static final String X_LABEL = "Ground Motion (g)"; static final String Y_LABEL = "Annual Frequency of Exceedence"; - public NetcdfServiceHazardCurves(NetcdfHazardCurves netcdf) { - super(netcdf); + public NetcdfServiceHazardCurves(NetcdfDataFilesHazardCurves netcdfDataFiles) { + super(netcdfDataFiles); } @Override @@ -64,29 +66,40 @@ public class NetcdfServiceHazardCurves extends NetcdfService<HazardQuery> { @Override String getServiceName() { - return getSourceModel().name; + return "Static Hazard Curves for NSHMs"; } @Override - SourceModel getSourceModel() { - return new HazardSourceModel(); + List<SourceModel> getSourceModels() { + return netcdfDataFiles().stream() + .map(HazardSourceModel::new) + .collect(Collectors.toList()); } - @Override - NetcdfHazardCurves netcdf() { - return (NetcdfHazardCurves) netcdf; + /** + * Returns the {@link NetcdfHazardCurves} associated with a given {@link Nshm NSHM}. + * + * @param nshm The NSHM to get the NetCDF data + */ + NetcdfHazardCurves netcdf(Nshm nshm) { + return netcdfDataFiles().netcdf(nshm); } @Override - ResponseBody<RequestData, List<List<ResponseData<HazardResponseMetadata>>>> processCurves( - RequestData request, + NetcdfDataFilesHazardCurves netcdfDataFiles() { + return (NetcdfDataFilesHazardCurves) netcdfDataFiles; + } + + ResponseBody<HazardRequestData, List<List<ResponseData<HazardResponseMetadata>>>> processCurves( + HazardRequestData request, String url) { WsUtils.checkValue(Key.LATITUDE, request.latitude); WsUtils.checkValue(Key.LONGITUDE, request.longitude); - var curves = netcdf().staticData(request.site); + var curves = netcdf(request.nshm).staticData(request.site); var curvesAsList = toList(request, curves); - return ResponseBody.<RequestData, List<List<ResponseData<HazardResponseMetadata>>>> success() + return ResponseBody + .<HazardRequestData, List<List<ResponseData<HazardResponseMetadata>>>> success() .metadata(new ResponseMetadata(NetcdfVersion.appVersions())) .name(getServiceName()) .request(request) @@ -95,17 +108,17 @@ public class NetcdfServiceHazardCurves extends NetcdfService<HazardQuery> { .build(); } - @Override - ResponseBody<RequestDataSiteClass, List<ResponseData<HazardResponseMetadata>>> processCurvesSiteClass( - RequestDataSiteClass request, + ResponseBody<HazardRequestDataSiteClass, List<ResponseData<HazardResponseMetadata>>> processCurvesSiteClass( + HazardRequestDataSiteClass request, String url) { WsUtils.checkValue(Key.LATITUDE, request.latitude); WsUtils.checkValue(Key.LONGITUDE, request.longitude); WsUtils.checkValue(Key.SITE_CLASS, request.siteClass); - var curves = netcdf().staticData(request.site, request.siteClass); + var curves = netcdf(request.nshm).staticData(request.site, request.siteClass); var curvesAsList = toList(request, curves); - return ResponseBody.<RequestDataSiteClass, List<ResponseData<HazardResponseMetadata>>> success() + return ResponseBody + .<HazardRequestDataSiteClass, List<ResponseData<HazardResponseMetadata>>> success() .metadata(new ResponseMetadata(NetcdfVersion.appVersions())) .name(getServiceName()) .request(request) @@ -114,16 +127,16 @@ public class NetcdfServiceHazardCurves extends NetcdfService<HazardQuery> { .build(); } - ResponseBody<RequestDataSiteClass, ResponseData<HazardResponseMetadata>> processCurvesImt( - RequestDataImt request, + ResponseBody<HazardRequestDataSiteClass, ResponseData<HazardResponseMetadata>> processCurvesImt( + HazardRequestDataImt request, String url) { WsUtils.checkValue(Key.LATITUDE, request.latitude); WsUtils.checkValue(Key.LONGITUDE, request.longitude); WsUtils.checkValue(Key.SITE_CLASS, request.siteClass); WsUtils.checkValue(Key.IMT, request.imt); - var curves = netcdf().staticData(request.site, request.siteClass); + var curves = netcdf(request.nshm).staticData(request.site, request.siteClass); - return ResponseBody.<RequestDataSiteClass, ResponseData<HazardResponseMetadata>> success() + return ResponseBody.<HazardRequestDataSiteClass, ResponseData<HazardResponseMetadata>> success() .metadata(new ResponseMetadata(NetcdfVersion.appVersions())) .name(getServiceName()) .request(request) @@ -140,13 +153,15 @@ public class NetcdfServiceHazardCurves extends NetcdfService<HazardQuery> { switch (service) { case CURVES: - var requestData = new RequestData(site, query.format); + var requestData = new HazardRequestData(query.nshm, site, query.format); return toResponseFromListOfList(processCurves(requestData, url)); case CURVES_BY_SITE_CLASS: - var requestDataSiteClass = new RequestDataSiteClass(site, query.siteClass, query.format); + var requestDataSiteClass = + new HazardRequestDataSiteClass(query.nshm, site, query.siteClass, query.format); return toResponseFromList(processCurvesSiteClass(requestDataSiteClass, url)); case CURVES_BY_IMT: - var requestDataImt = new RequestDataImt(site, query.siteClass, query.imt, query.format); + var requestDataImt = + new HazardRequestDataImt(query.nshm, site, query.siteClass, query.imt, query.format); return toResponse(processCurvesImt(requestDataImt, url)); default: throw new RuntimeException("Netcdf service [" + service + "] not found"); @@ -154,7 +169,7 @@ public class NetcdfServiceHazardCurves extends NetcdfService<HazardQuery> { } private String toResponseFromListOfList( - ResponseBody<RequestData, List<List<ResponseData<HazardResponseMetadata>>>> serviceResponse) { + ResponseBody<HazardRequestData, List<List<ResponseData<HazardResponseMetadata>>>> serviceResponse) { if (serviceResponse.getRequest().format == ResponseFormat.CSV) { var csvResponse = toCsvFromListOfList(serviceResponse.getRequest(), serviceResponse.getResponse()); @@ -164,14 +179,14 @@ public class NetcdfServiceHazardCurves extends NetcdfService<HazardQuery> { } } - private String toCsvFromListOfList(RequestData requestData, + private String toCsvFromListOfList(HazardRequestData requestData, List<List<ResponseData<HazardResponseMetadata>>> responseData) { return responseData.stream().map(responses -> toCsvResponseFromList(requestData, responses)) .collect(Collectors.joining("\n\n")); } List<ResponseData<HazardResponseMetadata>> toList( - RequestDataSiteClass request, + HazardRequestDataSiteClass request, StaticDataHazardCurves curves) { return curves.entrySet().stream() .map((entry) -> toResponseData(request, entry.getKey(), entry.getValue())) @@ -179,32 +194,33 @@ public class NetcdfServiceHazardCurves extends NetcdfService<HazardQuery> { } List<List<ResponseData<HazardResponseMetadata>>> toList( - RequestData requestData, + HazardRequestData requestData, StaticData<StaticDataHazardCurves> curves) { return curves.entrySet().stream() .map(entry -> { var request = - new RequestDataSiteClass(requestData.site, entry.getKey(), requestData.format); + new HazardRequestDataSiteClass(requestData.nshm, requestData.site, entry.getKey(), + requestData.format); return toList(request, entry.getValue()); }) .collect(Collectors.toList()); } ResponseData<HazardResponseMetadata> toResponseData( - RequestDataSiteClass request, + HazardRequestDataSiteClass request, Imt imt, XySequence curves) { var metadata = - new HazardResponseMetadata(request.siteClass, imt, X_LABEL, Y_LABEL); + new HazardResponseMetadata(request.nshm, request.siteClass, imt, X_LABEL, Y_LABEL); return new ResponseData<>(metadata, curves); } - class HazardSourceModel extends SourceModel { + static class HazardSourceModel extends SourceModel { public final List<Imt> imts; - HazardSourceModel() { - super(netcdf()); - imts = netcdf().netcdfData().imts().stream().sorted().collect(Collectors.toList()); + HazardSourceModel(NetcdfHazardCurves netcdf) { + super(netcdf); + imts = netcdf.netcdfData().imts().stream().sorted().collect(Collectors.toList()); } } }