Skip to content

Commit

Permalink
Version 0.7.0
Browse files Browse the repository at this point in the history
NcAnimate:
- Fixed bug with arrowVariable overwrites not applied properly.
- Added extraAmountOutOfRangeLow and extraAmountOutOfRangeHigh properties to NcAnimateLegendBean.
- Added ColourSchemeType.ARROW_THRESHOLDS
- Added arrowColour and arrowThresholds properties to NcAnimateNetCDFVariableBean.
  • Loading branch information
gaellafond committed Nov 3, 2022
1 parent 45484e3 commit 54734a8
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 62 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>au.gov.aims</groupId>
<artifactId>ereefs-database</artifactId>
<version>0.6.26</version>
<version>0.7.0</version>

<!--
*** IMPORTANT ***
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public class NcAnimateLegendBean extends AbstractNcAnimateBean {
private Integer colourBandHeight;
private Integer colourBandColourCount; // Number of colours used to render the layer and the legend

// Add extra space at the top and bottom of the colour band
private Float extraAmountOutOfRangeLow;
private Float extraAmountOutOfRangeHigh;

private Integer majorTickMarkLength;
private Integer minorTickMarkLength;

Expand Down Expand Up @@ -143,6 +147,9 @@ protected void parse(JSONWrapperObject jsonLegend) throws Exception {
this.colourBandHeight = jsonLegend.get(Integer.class, "colourBandHeight");
this.colourBandColourCount = jsonLegend.get(Integer.class, "colourBandColourCount");

this.extraAmountOutOfRangeLow = jsonLegend.get(Float.class, "extraAmountOutOfRangeLow");
this.extraAmountOutOfRangeHigh = jsonLegend.get(Float.class, "extraAmountOutOfRangeHigh");

this.majorTickMarkLength = jsonLegend.get(Integer.class, "majorTickMarkLength");
this.minorTickMarkLength = jsonLegend.get(Integer.class, "minorTickMarkLength");
}
Expand Down Expand Up @@ -297,6 +304,14 @@ public Integer getColourBandColourCount() {
return this.colourBandColourCount;
}

public Float getExtraAmountOutOfRangeLow() {
return this.extraAmountOutOfRangeLow;
}

public Float getExtraAmountOutOfRangeHigh() {
return this.extraAmountOutOfRangeHigh;
}

/**
* Returns the length of the major tick marks in the legend, in pixels.
* @return the length of the major tick marks in the legend, in pixels.
Expand Down Expand Up @@ -347,6 +362,9 @@ public JSONObject toJSON() {
json.put("colourBandHeight", this.colourBandHeight);
json.put("colourBandColourCount", this.colourBandColourCount);

json.put("extraAmountOutOfRangeLow", this.extraAmountOutOfRangeLow);
json.put("extraAmountOutOfRangeHigh", this.extraAmountOutOfRangeHigh);

json.put("majorTickMarkLength", this.majorTickMarkLength);
json.put("minorTickMarkLength", this.minorTickMarkLength);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.InvalidClassException;
import java.util.ArrayList;
import java.util.List;

/**
* NcAnimate {@code NetCDF} variable bean part.
Expand Down Expand Up @@ -43,21 +45,22 @@
* }</pre>
*/
public class NcAnimateNetCDFVariableBean extends AbstractNcAnimateBean {

public enum ColourSchemeType {
SCALE(),
THRESHOLDS()
SCALE,
THRESHOLDS,
ARROW_THRESHOLDS,
}

private String variableId;
private String colourPaletteName;
private Boolean logarithmic;

private ColourSchemeType colourSchemeType;

private Float scaleMin;
private Float scaleMax;

private ArrayList<Float> thresholds;

// Used with direction variable
Expand All @@ -73,7 +76,7 @@ public enum ColourSchemeType {
// For radian:
// directionTurns = 6.2831853 // 2*PI
// See: https://en.wikipedia.org/wiki/Angular_unit
// NOTE: For counter clockwise angle, use a negative directionTurns
// NOTE: For counter-clockwise angle, use a negative directionTurns
// directionTurns = 360:
// North: 0
// East: 90
Expand All @@ -90,6 +93,15 @@ public enum ColourSchemeType {
// Legend
private NcAnimateLegendBean legend;

private String arrowColour;

// Arrow thresholds.
// Each value is formatted this way:
// Threshold value:Hex colour
// Example:
// "8.1:#009900"
private List<String> arrowThresholds;

/**
* Create a NcAnimate NetCDF layer variable bean part from a {@code JSONWrapperObject}.
*
Expand Down Expand Up @@ -151,20 +163,31 @@ protected void parse(JSONWrapperObject jsonVariable) throws Exception {
if (jsonVariable != null) {
this.variableId = jsonVariable.get(String.class, "variableId");
this.colourPaletteName = jsonVariable.get(String.class, "colourPaletteName");

this.setColourSchemeType(jsonVariable.get(String.class, "colourSchemeType"));

this.scaleMax = jsonVariable.get(Float.class, "scaleMax");
this.scaleMin = jsonVariable.get(Float.class, "scaleMin");

this.setThresholds(jsonVariable.get(JSONWrapperArray.class, "thresholds"));

this.northAngle = jsonVariable.get(Float.class, "northAngle");
this.directionTurns = jsonVariable.get(Float.class, "directionTurns");

this.logarithmic = jsonVariable.get(Boolean.class, "logarithmic");

this.setLegend(jsonVariable.get(JSONWrapperObject.class, "legend"));

this.arrowColour = jsonVariable.get(String.class, "arrowColour");

this.arrowThresholds = null;
Class arrowThresholdsClass = jsonVariable.getClass("arrowThresholds");
if (arrowThresholdsClass != null) {
if (JSONWrapperArray.class.equals(arrowThresholdsClass)) {
this.setArrowThresholds(
jsonVariable.get(JSONWrapperArray.class, "arrowThresholds"));
}
}
}
}

Expand All @@ -176,6 +199,17 @@ private void setLegend(JSONWrapperObject jsonLegend) throws Exception {
}
}

private void setArrowThresholds(JSONWrapperArray jsonArrowThresholds) throws InvalidClassException {
this.arrowThresholds = null;

if (jsonArrowThresholds != null) {
this.arrowThresholds = new ArrayList<String>();
for (int i=0; i<jsonArrowThresholds.length(); i++) {
this.arrowThresholds.add(jsonArrowThresholds.get(String.class, i));
}
}
}

/**
* Returns the variable ID, as defined in the NetCDF file.
* @return the variable ID.
Expand All @@ -190,11 +224,14 @@ public String getVariableId() {
*/
public void setColourSchemeType(String typeString) {
this.colourSchemeType = null;

if (typeString != null) {
if (typeString.equalsIgnoreCase(ColourSchemeType.THRESHOLDS.toString())) {
this.colourSchemeType = ColourSchemeType.THRESHOLDS;
}
else if (typeString.equalsIgnoreCase(ColourSchemeType.ARROW_THRESHOLDS.toString())) {
this.colourSchemeType = ColourSchemeType.ARROW_THRESHOLDS;
}
else if (typeString.equalsIgnoreCase(ColourSchemeType.SCALE.toString())) {
this.colourSchemeType = ColourSchemeType.SCALE;
}
Expand Down Expand Up @@ -242,7 +279,7 @@ public void setThresholds(JSONWrapperArray thresholdsWrapperArray) throws Except
this.thresholds = null;

if (thresholdsWrapperArray != null && thresholdsWrapperArray.length() > 0) {
this.thresholds = new ArrayList<>();
this.thresholds = new ArrayList<Float>();

for (int i = 0; i < thresholdsWrapperArray.length(); i++) {
this.thresholds.add(thresholdsWrapperArray.get(Float.class, i));
Expand Down Expand Up @@ -304,6 +341,23 @@ public void setLegend(NcAnimateLegendBean legend) {
this.legend = legend;
}

/**
* Returns the colour of the arrows, in hexadecimal format.
* @return the colour of the arrows.
*/
public String getArrowColour() {
return this.arrowColour;
}

/**
* Returns the list of arrow threshold colours.
* Used with {@link NcAnimateLayerBean.LayerType#NETCDF} and {@link NcAnimateLayerBean.LayerType#GRIB2}.
* @return the list of arrow threshold colours.
*/
public List<String> getArrowThresholds() {
return arrowThresholds;
}

// NOTE: equals and hashcode are defined in AbstractNcAnimateBean

/**
Expand All @@ -318,7 +372,7 @@ public JSONObject toJSON() {
json.put("colourPaletteName", this.colourPaletteName);

json.put("colourSchemeType", this.colourSchemeType);

json.put("scaleMax", this.scaleMax);
json.put("scaleMin", this.scaleMin);

Expand All @@ -335,6 +389,16 @@ public JSONObject toJSON() {
json.put("legend", this.legend.toJSON());
}

json.put("arrowColour", this.arrowColour);

if (this.arrowThresholds != null) {
JSONArray jsonArrowThresholds = new JSONArray();
for (String arrowThreshold : this.arrowThresholds) {
jsonArrowThresholds.put(arrowThreshold);
}
json.put("arrowThresholds", jsonArrowThresholds);
}

return json.isEmpty() ? null : json;
}
}
102 changes: 54 additions & 48 deletions src/main/java/au/gov/aims/ereefs/helper/NcAnimateConfigHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ private NcAnimateConfigBean combineParts(NcAnimateConfigBean config) throws Exce
}

private void combineLegendParts(NcAnimateConfigBean config, NcAnimateLegendBean legend) throws Exception {
// If "defaults.legend" refer to a legend ID, find that legend from the DB
// and put that object in "defaults.legend".
// The legend overwrite in layers appends in "combinePanelParts".
if (legend != null) {
// Legend part
NcAnimateIdBean legendId = legend.getId();
Expand Down Expand Up @@ -501,60 +504,63 @@ private void combineLayerParts(NcAnimateConfigBean config, NcAnimateLayerBean la

// Variable
NcAnimateNetCDFVariableBean variableOverwrites = layer.getVariable();
if (variableOverwrites != null) {
NcAnimateIdBean variableId = variableOverwrites.getId();
if (variableId != null) {
String variableIdStr = variableId.getValue();
if (variableIdStr != null && !variableIdStr.isEmpty()) {
JSONObject jsonVariable = this.configPartManager.select(ConfigPartManager.Datatype.VARIABLE, variableIdStr);
if (jsonVariable != null) {
NcAnimateNetCDFVariableBean variable = new NcAnimateNetCDFVariableBean(new JSONWrapperObject(jsonVariable));
variableOverwrites.overwrite(variable, variableOverwrites);

layer.addAllNeverVisited("variable["+variableIdStr+"]", variable.getNeverVisited());
config.addLastModifiedConfigPart(variable);
} else {
LOGGER.error(String.format("Layer variable ID \"%s\" could not be found in the database. Using variable config found in NcAnimate config:%n%s",
variableIdStr, variableOverwrites));
}
}
}
this.applyVariableOverwrites(config, layer, variableOverwrites, "variable", defaultLegend);

if (defaultLegend != null) {
NcAnimateLegendBean legendConfOverwrite = variableOverwrites.getLegend();
if (legendConfOverwrite == null) {
legendConfOverwrite = defaultLegend;
this.combineLegendParts(config, legendConfOverwrite);
variableOverwrites.setLegend(legendConfOverwrite);
} else {
this.combineLegendParts(config, legendConfOverwrite);
legendConfOverwrite.overwrite(defaultLegend, legendConfOverwrite);
}
// Arrow variable
NcAnimateNetCDFVariableBean arrowVariableOverwrites = layer.getArrowVariable();
this.applyVariableOverwrites(config, layer, arrowVariableOverwrites, "arrowVariable", defaultLegend);
}
}
}

variableOverwrites.addAllNeverVisited("legend", legendConfOverwrite.getNeverVisited());
/**
* Private method used to apply variable overwrites
* and legend default values (found in "defaults.legend").
* @param config the {@link NcAnimateConfigBean} configuration document.
* @param layer the {@link NcAnimateLayerBean} layer containing the variable to overwrite.
* @param variableOverwrites the {@link NcAnimateNetCDFVariableBean} variable to overwrite.
* @param variableType "variable" or "arrowVariable", used with error messages.
* @param defaultLegend the {@link NcAnimateLegendBean} default values found in "defaults.legend".
* @throws Exception if the database is unreachable.
*/
private void applyVariableOverwrites(
NcAnimateConfigBean config,
NcAnimateLayerBean layer,
NcAnimateNetCDFVariableBean variableOverwrites,
String variableType, // "variable" or "arrowVariable"
NcAnimateLegendBean defaultLegend
) throws Exception {
if (variableOverwrites != null) {
NcAnimateIdBean variableId = variableOverwrites.getId();
if (variableId != null) {
String variableIdStr = variableId.getValue();
if (variableIdStr != null && !variableIdStr.isEmpty()) {
JSONObject jsonVariable = this.configPartManager.select(ConfigPartManager.Datatype.VARIABLE, variableIdStr);
if (jsonVariable != null) {
NcAnimateNetCDFVariableBean variable = new NcAnimateNetCDFVariableBean(new JSONWrapperObject(jsonVariable));
variableOverwrites.overwrite(variable, variableOverwrites);

layer.addAllNeverVisited(variableType+"["+variableIdStr+"]", variable.getNeverVisited());
config.addLastModifiedConfigPart(variable);
} else {
LOGGER.error(String.format("Layer %s ID \"%s\" could not be found in the database. Using variable config found in NcAnimate config:%n%s",
variableType, variableIdStr, variableOverwrites));
}
}
}

// Arrow variable
NcAnimateNetCDFVariableBean arrowVariableOverwrites = layer.getArrowVariable();
if (arrowVariableOverwrites != null) {
NcAnimateIdBean arrowVariableId = arrowVariableOverwrites.getId();
if (arrowVariableId != null) {
String arrowVariableIdStr = arrowVariableId.getValue();
if (arrowVariableIdStr != null && !arrowVariableIdStr.isEmpty()) {
JSONObject jsonArrowVariable = this.configPartManager.select(ConfigPartManager.Datatype.VARIABLE, arrowVariableIdStr);
if (jsonArrowVariable != null) {
NcAnimateNetCDFVariableBean arrowVariable = new NcAnimateNetCDFVariableBean(new JSONWrapperObject(jsonArrowVariable));
arrowVariableOverwrites.overwrite(arrowVariable, arrowVariableOverwrites);
layer.addAllNeverVisited("arrowVariable["+arrowVariableIdStr+"]", arrowVariable.getNeverVisited());
config.addLastModifiedConfigPart(arrowVariable);
} else {
LOGGER.error(String.format("Layer arrowVariable ID \"%s\" could not be found in the database. Using variable config found in NcAnimate config:%n%s",
arrowVariableIdStr, arrowVariableOverwrites));
}
}
}
if (defaultLegend != null) {
NcAnimateLegendBean legendConfOverwrite = variableOverwrites.getLegend();
if (legendConfOverwrite == null) {
legendConfOverwrite = defaultLegend;
this.combineLegendParts(config, legendConfOverwrite);
variableOverwrites.setLegend(legendConfOverwrite);
} else {
this.combineLegendParts(config, legendConfOverwrite);
legendConfOverwrite.overwrite(defaultLegend, legendConfOverwrite);
}

variableOverwrites.addAllNeverVisited("legend", legendConfOverwrite.getNeverVisited());
}
}
}
Expand Down

0 comments on commit 54734a8

Please sign in to comment.