Skip to content

Commit

Permalink
Fixed some CDM bugs(?)
Browse files Browse the repository at this point in the history
  • Loading branch information
guygriffiths committed Jan 23, 2024
1 parent 6e5ac1d commit e045b50
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# General
.DS_Store
target/
.classpath
.project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ private static final class WrappedArray extends Array4D<Number> {
private final boolean needsEnhance;
private final RangesList rangesList;

private final int tOffset;
private final int zOffset;

/*
* Used for caching in the case where we read in slices
*/
Expand All @@ -357,6 +360,9 @@ public WrappedArray(VariableDS var, Array arr, boolean needsEnhance, int[] shape
yAxisIndex = rangesList.getYAxisIndex();
zAxisIndex = rangesList.getZAxisIndex();
tAxisIndex = rangesList.getTAxisIndex();

zOffset = rangesList.getZRange() != null ? rangesList.getZRange().first() : 0;
tOffset = rangesList.getTRange() != null ? rangesList.getTRange().first() : 0;
}

@Override
Expand Down Expand Up @@ -404,8 +410,8 @@ public Number get(int... coords) {
/*
* Need to do a read on the underlying data
*/
rangesList.setTRange(t, t);
rangesList.setZRange(z, z);
rangesList.setTRange(tOffset+t, tOffset+t);
rangesList.setZRange(zOffset+z, zOffset+z);
try {
arrLocal = var.read(rangesList.getRanges());
if (this.needsEnhance) {
Expand Down
16 changes: 16 additions & 0 deletions cdm/src/main/java/uk/ac/rdg/resc/edal/dataset/cdm/RangesList.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,34 @@ public void setXRange(int xmin, int xmax) {
setRange(xAxisIndex, xmin, xmax);
}

public Range getXRange() {
return getRange(xAxisIndex);
}

public void setYRange(int ymin, int ymax) {
setRange(yAxisIndex, ymin, ymax);
}

public Range getYRange() {
return getRange(yAxisIndex);
}

public void setZRange(int zmin, int zmax) {
setRange(zAxisIndex, zmin, zmax);
}

public Range getZRange() {
return getRange(zAxisIndex);
}

public void setTRange(int tmin, int tmax) {
setRange(tAxisIndex, tmin, tmax);
}

public Range getTRange() {
return getRange(tAxisIndex);
}

private void setRange(int index, int min, int max) {
if (index >= 0 && min >= 0 && max >= 0) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,34 @@ public CdmTransformedGrid(GridCoordSystem coordSys) {
xAxis = CdmUtils.createReferenceableAxis((CoordinateAxis1D) coordSys.getXHorizAxis(),
xAxisIsLongitude);
yAxis = CdmUtils.createReferenceableAxis((CoordinateAxis1D) coordSys.getYHorizAxis());
LatLonRect latLonBoundingBox = coordSys.getLatLonBoundingBox();

List<HorizontalPosition> gridPoints = new ArrayList<>();
for(Double x : xAxis.getCoordinateValues()) {
for(Double y : yAxis.getCoordinateValues() ) {
LatLonPoint ll = proj.projToLatLon(x, y);
gridPoints.add(new HorizontalPosition(ll.getLongitude(), ll.getLatitude()));
}
}

BoundingBox latLonBoundingBox = GISUtils.getBoundingBox(gridPoints);
/*
* Some projections do not have a well-defined lat-lon bounding box and
* return NaNs. In these cases, we fall back to using global limits
*/
double lonMin = latLonBoundingBox.getLonMin();
double lonMax = latLonBoundingBox.getLonMax();
double latMin = latLonBoundingBox.getLatMin();
double latMax = latLonBoundingBox.getLatMax();
double lonMin = latLonBoundingBox.getMinX();
double lonMax = latLonBoundingBox.getMaxX();
double latMin = latLonBoundingBox.getMinY();
double latMax = latLonBoundingBox.getMaxY();
if (Double.isNaN(lonMin)) {
lonMin = -180.0;
}
if (Double.isNaN(lonMax)) {
lonMax = 180.0;
}
if (Double.isNaN(latMin)) {
if (Double.isNaN(latMin) || Math.abs(latMin + 90) < 1) {
latMin = -90.0;
}
if (Double.isNaN(latMax)) {
if (Double.isNaN(latMax) || Math.abs(latMax - 90) < 1) {
latMax = 90.0;
}

Expand Down Expand Up @@ -383,3 +392,4 @@ public boolean equals(Object obj) {
}

}

0 comments on commit e045b50

Please sign in to comment.