Omaha #4931 Fix gather derived parameter.

Former-commit-id: 2ff11f33c19e0ae5c22771ed351761a2cc6b2871
This commit is contained in:
Ben Steffensmeier 2015-10-09 11:39:14 -05:00 committed by Gerrit Code Review
parent 79ad314965
commit 2501a15c92
20 changed files with 112 additions and 36 deletions

View file

@ -20,37 +20,45 @@
package com.raytheon.viz.grid.inv;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.raytheon.uf.common.inventory.data.AbstractRequestableData;
import com.raytheon.uf.common.inventory.data.AggregateRequestableData;
import com.raytheon.uf.common.inventory.exception.DataCubeException;
import com.raytheon.uf.common.inventory.TimeAndSpace;
import com.raytheon.uf.common.inventory.tree.AbstractRequestableNode;
import com.raytheon.uf.common.dataplugin.grid.GridConstants;
import com.raytheon.uf.common.dataplugin.level.Level;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
import com.raytheon.uf.common.derivparam.inv.AvailabilityContainer;
import com.raytheon.uf.common.derivparam.inv.MetadataContainer;
import com.raytheon.uf.common.derivparam.library.DerivParamDesc;
import com.raytheon.uf.common.derivparam.library.DerivParamMethod;
import com.raytheon.uf.common.derivparam.tree.AbstractAliasLevelNode;
import com.raytheon.uf.common.inventory.TimeAndSpace;
import com.raytheon.uf.common.inventory.data.AbstractRequestableData;
import com.raytheon.uf.common.inventory.data.AggregateRequestableData;
import com.raytheon.uf.common.inventory.exception.DataCubeException;
import com.raytheon.uf.common.inventory.tree.AbstractRequestableNode;
import com.raytheon.uf.viz.core.exception.VizException;
/**
*
* Builds AggregateRecords which contain all perturbations for a given record
* Builds AggregateRecords which contain all perturbations for a specific
* parameter/level of an ensemble model.
*
* <pre>
*
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 26, 2010 bsteffen Initial creation
* Date Ticket# Engineer Description
* ------------- -------- --------- --------------------------
* Feb 26, 2010 bsteffen Initial creation
* Oct 09, 2015 4931 bsteffen Do separate requests each distinct
* ensemble_id
*
* </pre>
*
* @author bsteffen
* @version 1.0
*/
public class GatherLevelNode extends AbstractAliasLevelNode {
@ -64,20 +72,56 @@ public class GatherLevelNode extends AbstractAliasLevelNode {
super(sourceNode, desc, method, modelName, level);
}
@Override
public Map<AbstractRequestableNode, Set<TimeAndSpace>> getDataDependency(
Set<TimeAndSpace> times, AvailabilityContainer container) {
/*
* The MetadataContainer cannot handle the dependencies because we must
* add an ensemble_id constraint so return that there is no dependency
* and instead request needed data in getData()
*/
return Collections.emptyMap();
}
@Override
public Set<AbstractRequestableData> getData(
Set<TimeAndSpace> availability,
Map<AbstractRequestableNode, Set<AbstractRequestableData>> dependencyData)
throws DataCubeException {
return gatherData(availability, getRequestConstraints());
}
/**
* This method can be used in place of {@link #getData(Set, Map)} to
* retrieve the data for this node. Since this node must perform separate
* request for each distinct ensemble_id that is being gathered, the
* dependency data that is normally passed to getData is unnecessary. This
* method takes in some original constraints which will be passed along in
* case the original query had additional constraints not handled normally
* by derived parameters(For example Secondary Id)
*/
public Set<AbstractRequestableData> gatherData(
Set<TimeAndSpace> availability,
Map<String, RequestConstraint> originalConstraints)
throws DataCubeException {
Map<TimeAndSpace, List<AbstractRequestableData>> availMap = new HashMap<TimeAndSpace, List<AbstractRequestableData>>();
for (AbstractRequestableData data : dependencyData.get(sourceNode)) {
TimeAndSpace ast = data.getTimeAndSpace();
List<AbstractRequestableData> avail = availMap.get(ast);
if (avail == null) {
avail = new ArrayList<AbstractRequestableData>();
availMap.put(ast, avail);
for (String member : getSourceEnsembles()) {
Map<String, RequestConstraint> constraints = new HashMap<>(
originalConstraints);
constraints.put(GridConstants.ENSEMBLE_ID, new RequestConstraint(
member));
MetadataContainer container = new GridMetadataContainer(
constraints, new AvailabilityContainer(constraints));
for (AbstractRequestableData data : container.getData(sourceNode,
availability)) {
TimeAndSpace ast = data.getTimeAndSpace();
List<AbstractRequestableData> avail = availMap.get(ast);
if (avail == null) {
avail = new ArrayList<AbstractRequestableData>();
availMap.put(ast, avail);
}
avail.add(data);
}
avail.add(data);
}
Set<AbstractRequestableData> result = new HashSet<AbstractRequestableData>();
for (List<AbstractRequestableData> records : availMap.values()) {
@ -89,6 +133,38 @@ public class GatherLevelNode extends AbstractAliasLevelNode {
return result;
}
/**
* @return the {@link List} of ensemble_ids that this node is gathering.
*/
protected List<String> getSourceEnsembles() throws DataCubeException {
try {
return GridInventory.getEnsembles(sourceNode);
} catch (VizException e) {
throw new DataCubeException(e);
}
}
/**
* @return the request constraint map that can be used for requesting all
* data for this node.
*/
protected Map<String, RequestConstraint> getRequestConstraints() {
Map<String, RequestConstraint> constraints = new HashMap<>();
constraints.put(GridConstants.PLUGIN_NAME, new RequestConstraint(
GridConstants.GRID));
constraints.put(GridConstants.DATASET_ID, new RequestConstraint(
getModelName()));
constraints.put(GridConstants.PARAMETER_ABBREVIATION,
new RequestConstraint(getDesc().getAbbreviation()));
constraints.put(GridConstants.MASTER_LEVEL_NAME, new RequestConstraint(
getLevel().getMasterLevel().getName()));
constraints.put(GridConstants.LEVEL_ONE, new RequestConstraint(
getLevel().getLevelOneValueAsString()));
constraints.put(GridConstants.LEVEL_TWO, new RequestConstraint(
getLevel().getLevelTwoValueAsString()));
return constraints;
}
@Override
public GatherLevelNode clone() {
return new GatherLevelNode(this);

View file

@ -18,7 +18,7 @@
See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for
further_licensing_information.
-->
<DerivedParameter abbreviation="GH_perts" name="Height Perturbations" unit="m">
<DerivedParameter abbreviation="GH_perts" name="Height Perturbations" unit="m" internal="true">
<Method name="Gather">
<Field abbreviation="GH"/>
</Method>

View file

@ -18,7 +18,7 @@
See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for
further_licensing_information.
-->
<DerivedParameter abbreviation="MnT_perts" name="Min Temp Perturbations" unit="K">
<DerivedParameter abbreviation="MnT_perts" name="Min Temp Perturbations" unit="K" internal="true" >
<Method name="Gather">
<Field abbreviation="MnT"/>
</Method>

View file

@ -18,7 +18,7 @@
See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for
further_licensing_information.
-->
<DerivedParameter abbreviation="MxT_perts" name="Max Temp Perturbations" unit="K">
<DerivedParameter abbreviation="MxT_perts" name="Max Temp Perturbations" unit="K" internal="true" >
<Method name="Gather">
<Field abbreviation="MxT"/>
</Method>

View file

@ -19,7 +19,7 @@
AWIPS II NEW FILE - RH_001_perts.xml
-->
<DerivedParameter name="Prob of RH Grtn 70 percent Perts" abbreviation="RH_001_perts" xmlns:ns2="group" xmlns:ns3="http://www.example.org/productType">
<DerivedParameter name="Prob of RH Grtn 70 percent Perts" abbreviation="RH_001_perts" internal="true" ">
<Method name="Gather">
<Field abbreviation="RH_001_bin"/>
</Method>

View file

@ -19,7 +19,7 @@
AWIPS II NEW FILE - RH_002_perts.xml
-->
<DerivedParameter name="Prob of RH Grtn 90 percent Perts" abbreviation="RH_002_perts" xmlns:ns2="group" xmlns:ns3="http://www.example.org/productType">
<DerivedParameter name="Prob of RH Grtn 90 percent Perts" abbreviation="RH_002_perts" internal="true" >
<Method name="Gather">
<Field abbreviation="RH_002_bin"/>
</Method>

View file

@ -18,7 +18,7 @@
See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for
further_licensing_information.
-->
<DerivedParameter abbreviation="RH_perts" name="Rel Humidity Perturbations" unit="%">
<DerivedParameter abbreviation="RH_perts" name="Rel Humidity Perturbations" unit="%" internal="true" >
<Method name="Gather">
<Field abbreviation="RH"/>
</Method>

View file

@ -23,7 +23,7 @@
AWIPS II NEW FILE - TP24hr_perts.xml
-->
<DerivedParameter unit="mm" name="24hr Precip Perturbations" abbreviation="TP24hr_perts" xmlns:ns2="group" xmlns:ns3="http://www.example.org/productType">
<DerivedParameter unit="mm" name="24hr Precip Perturbations" abbreviation="TP24hr_perts" internal="true" >
<Method name="Gather">
<Field abbreviation="TP24hr"/>
</Method>

View file

@ -18,7 +18,7 @@
AWIPS II NEW FILE - TP6hr_perts.xml
-->
<DerivedParameter unit="mm" name="6hr Precip Perturbations" abbreviation="TP6hr_perts" xmlns:ns2="group" xmlns:ns3="http://www.example.org/productType">
<DerivedParameter unit="mm" name="6hr Precip Perturbations" abbreviation="TP6hr_perts" internal="true" >
<Method name="Gather">
<Field abbreviation="TP6hr"/>
</Method>

View file

@ -18,7 +18,7 @@
See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for
further_licensing_information.
-->
<DerivedParameter abbreviation="TP_perts" name="Precip Perturbations" unit="mm">
<DerivedParameter abbreviation="TP_perts" name="Precip Perturbations" unit="mm" internal="true" >
<Method name="Gather">
<Field abbreviation="TP"/>
</Method>

View file

@ -18,7 +18,7 @@
See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for
further_licensing_information.
-->
<DerivedParameter abbreviation="TPrun_perts" name="Accum Precip Perturbations" unit="mm">
<DerivedParameter abbreviation="TPrun_perts" name="Accum Precip Perturbations" unit="mm" internal="true" >
<Method name="Gather">
<Field abbreviation="TPrun"/>
</Method>

View file

@ -15,7 +15,7 @@
NEW FILE - T_001_perts.xml
-->
<DerivedParameter name="Prob of Temp Lstn 0C Perturbations" abbreviation="T_001_perts" xmlns:ns2="group" xmlns:ns3="http://www.example.org/productType">
<DerivedParameter name="Prob of Temp Lstn 0C Perturbations" abbreviation="T_001_perts" internal="true" >
<Method name="Gather">
<Field abbreviation="T_001_bin"/>
</Method>

View file

@ -18,7 +18,7 @@
See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for
further_licensing_information.
-->
<DerivedParameter abbreviation="T_perts" name="Temperature Perturbations" unit="K">
<DerivedParameter abbreviation="T_perts" name="Temperature Perturbations" unit="K" internal="true">
<Method name="Gather">
<Field abbreviation="T"/>
</Method>

View file

@ -18,7 +18,7 @@
See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for
further_licensing_information.
-->
<DerivedParameter abbreviation="Wind_perts" name="Wind Perturbations" unit="m/s">
<DerivedParameter abbreviation="Wind_perts" name="Wind Perturbations" unit="m/s" internal="true" >
<Method name="Gather">
<Field abbreviation="Wind"/>
</Method>

View file

@ -18,7 +18,7 @@
See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for
further_licensing_information.
-->
<DerivedParameter abbreviation="msl-P_perts" name="MSL Press Perturbations" unit="hPa">
<DerivedParameter abbreviation="msl-P_perts" name="MSL Press Perturbations" unit="hPa" internal="true" >
<Method name="Gather">
<Field abbreviation="msl-P"/>
</Method>

View file

@ -19,7 +19,7 @@
AWIPS II NEW FILE - wSp_001_perts.xml
-->
<DerivedParameter name="Prob of Wind Grtn 40kts Perts" abbreviation="wSp_001_perts" xmlns:ns2="group" xmlns:ns3="http://www.example.org/productType">
<DerivedParameter name="Prob of Wind Grtn 40kts Perts" abbreviation="wSp_001_perts" internal="true" >
<Method name="Gather">
<Field abbreviation="wSp_001_bin"/>
</Method>

View file

@ -21,7 +21,7 @@
AWIPS II NEW FILE - wSp_002_perts.xml
-->
<DerivedParameter name="Prob of Wind Grtn 50kts Perts" abbreviation="wSp_002_perts" xmlns:ns2="group" xmlns:ns3="http://www.example.org/productType">
<DerivedParameter name="Prob of Wind Grtn 50kts Perts" abbreviation="wSp_002_perts" internal="true" >
<Method name="Gather">
<Field abbreviation="wSp_002_bin"/>
</Method>

View file

@ -19,7 +19,7 @@
AWIPS II NEW FILE - wSp_003_perts.xml
-->
<DerivedParameter name="Prob of Wind Grtn 60kts Perts" abbreviation="wSp_003_perts" xmlns:ns2="group" xmlns:ns3="http://www.example.org/productType">
<DerivedParameter name="Prob of Wind Grtn 60kts Perts" abbreviation="wSp_003_perts" internal="true" >
<Method name="Gather">
<Field abbreviation="wSp_003_bin"/>
</Method>

View file

@ -19,7 +19,7 @@
AWIPS II NEW FILE - wSp_004_perts.xml
-->
<DerivedParameter name="Prob of Wind Grtn 30kts Perts" abbreviation="wSp_004_perts" xmlns:ns2="group" xmlns:ns3="http://www.example.org/productType">
<DerivedParameter name="Prob of Wind Grtn 30kts Perts" abbreviation="wSp_004_perts" internal="true" >
<Method name="Gather">
<Field abbreviation="wSp_004_bin"/>
</Method>

View file

@ -18,7 +18,7 @@
See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for
further_licensing_information.
-->
<DerivedParameter abbreviation="wSp_perts" name="Windspeed Perturbations" unit="m/s">
<DerivedParameter abbreviation="wSp_perts" name="Windspeed Perturbations" unit="m/s" internal="true" >
<Method name="Gather">
<Field abbreviation="wSp"/>
</Method>