Skip to content

Commit a9a1f11

Browse files
author
haileyajohnson
authored
revert axis name changes and add work done to use coordVars to set co… (#1360)
* revert axis name changes and add work done to use coordVars to set coordinate axes props * fix CF version and min/max dates * minor refactor
1 parent a5ee0de commit a9a1f11

35 files changed

Lines changed: 312 additions & 190 deletions

cdm/core/src/main/java/ucar/nc2/constants/CDM.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class CDM {
2727
public static final String ABBREV = "abbreviation";
2828
public static final String ADD_OFFSET = "add_offset";
2929
public static final String CONVENTIONS = "Conventions";
30+
public static final String CF_VERSION = "CF-1.9";
3031
public static final String DESCRIPTION = "description";
3132
public static final String FILL_VALUE = "_FillValue";
3233
public static final String HISTORY = "history";

cdm/core/src/main/java/ucar/nc2/ft/DsgFeatureCollection.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import javax.annotation.Nonnull;
88
import javax.annotation.Nullable;
99
import ucar.nc2.Variable;
10+
import ucar.nc2.dataset.CoordinateAxis;
1011
import ucar.nc2.time.CalendarDateRange;
1112
import ucar.nc2.time.CalendarDateUnit;
1213
import java.util.List;
@@ -36,20 +37,20 @@ public interface DsgFeatureCollection {
3637
ucar.nc2.constants.FeatureType getCollectionFeatureType();
3738

3839
/**
39-
* The name of time unit.
40+
* The name of time unit, if there is a time axis.
4041
*
41-
* @return name of time unit string, may not be null
42+
* @return name of time unit string, may be null
4243
*/
43-
@Nonnull
44+
@Nullable
4445
String getTimeName();
4546

4647

4748
/**
48-
* The time unit.
49+
* The time unit, if there is a time axis.
4950
*
50-
* @return time unit, may not be null
51+
* @return time unit, may be null
5152
*/
52-
@Nonnull
53+
@Nullable
5354
CalendarDateUnit getTimeUnit();
5455

5556
/**
@@ -68,6 +69,14 @@ public interface DsgFeatureCollection {
6869
@Nullable
6970
String getAltUnits();
7071

72+
/**
73+
* The list of coordinate variables in the collection
74+
*
75+
* @return the list of coordinate variables, may be empty but not null;
76+
*/
77+
@Nonnull
78+
List<CoordinateAxis> getCoordinateVariables();
79+
7180
/*
7281
* Other variables needed for completeness, eg joined coordinate variables
7382
*

cdm/core/src/main/java/ucar/nc2/ft/FeatureDatasetFactoryManager.java

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -330,17 +330,6 @@ private static FeatureDataset wrapUnknown(NetcdfDataset ncd, ucar.nc2.util.Cance
330330
if (ft != null)
331331
return wrap(ft, ncd, task, errlog);
332332

333-
/*
334-
* grids dont usually have a FeatureType attribute, so check these fist
335-
* if (isGrid(ncd.getCoordinateSystems())) {
336-
* ucar.nc2.dt.grid.GridDataset gds = new ucar.nc2.dt.grid.GridDataset(ncd); // LOOK
337-
* if (gds.getGrids().size() > 0) {
338-
* if (debug) System.out.println(" wrapUnknown found grids ");
339-
* return gds;
340-
* }
341-
* }
342-
*/
343-
344333
// find a Factory that claims this dataset
345334
Object analysis = null;
346335
FeatureDatasetFactory useFactory = null;
@@ -355,16 +344,6 @@ private static FeatureDataset wrapUnknown(NetcdfDataset ncd, ucar.nc2.util.Cance
355344
}
356345
}
357346

358-
/*
359-
* try again as a Grid
360-
* if (null == useFactory) {
361-
* // if no datatype was requested, give em a GridDataset only if some Grids are found.
362-
* ucar.nc2.dt.grid.GridDataset gds = new ucar.nc2.dt.grid.GridDataset(ncd);
363-
* if (gds.getGrids().size() > 0)
364-
* return gds;
365-
* }
366-
*/
367-
368347
// Fail
369348
if (null == useFactory) {
370349
errlog.format("Failed (wrapUnknown) to find Datatype Factory for= %s%n", ncd.getLocation());
@@ -375,26 +354,6 @@ private static FeatureDataset wrapUnknown(NetcdfDataset ncd, ucar.nc2.util.Cance
375354
return useFactory.open(null, ncd, analysis, task, errlog);
376355
}
377356

378-
/*
379-
* static private boolean isGrid(java.util.List<CoordinateSystem> csysList) {
380-
* CoordinateSystem use = null;
381-
* for (CoordinateSystem csys : csysList) {
382-
* if (use == null) use = csys;
383-
* else if (csys.getCoordinateAxes().size() > use.getCoordinateAxes().size())
384-
* use = csys;
385-
* }
386-
*
387-
* if (use == null) return false;
388-
* CoordinateAxis lat = use.getLatAxis();
389-
* CoordinateAxis lon = use.getLonAxis();
390-
* if ((lat != null) && (lat.getSize() <= 1)) return false; // COARDS singletons
391-
* if ((lon != null) && (lon.getSize() <= 1)) return false;
392-
*
393-
* // hueristics - cant say i like this, multidim point features could easily violate
394-
* return (use.getRankDomain() > 2) && (use.getRankDomain() <= use.getRankRange());
395-
* }
396-
*/
397-
398357
/**
399358
* Determine if factory type matches wanted feature type.
400359
*

cdm/core/src/main/java/ucar/nc2/ft/point/DsgCollectionImpl.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package ucar.nc2.ft.point;
66

77
import ucar.nc2.Variable;
8+
import ucar.nc2.dataset.CoordinateAxis;
89
import ucar.nc2.ft.DsgFeatureCollection;
910
import ucar.nc2.time.CalendarDateRange;
1011
import ucar.nc2.time.CalendarDateUnit;
@@ -27,6 +28,7 @@ public abstract class DsgCollectionImpl implements DsgFeatureCollection {
2728
protected String altName = "altitude";
2829
protected String altUnits;
2930
protected CollectionInfo info;
31+
protected List<CoordinateAxis> coordVars;
3032
protected List<Variable> extras; // variables needed to make CF/DSG writing work
3133

3234
protected DsgCollectionImpl(String name, CalendarDateUnit timeUnit, String altUnits) {
@@ -35,13 +37,19 @@ protected DsgCollectionImpl(String name, CalendarDateUnit timeUnit, String altUn
3537
this.altUnits = altUnits;
3638
}
3739

38-
protected DsgCollectionImpl(String name, String timeName, CalendarDateUnit timeUnit, String altName,
39-
String altUnits) {
40+
protected DsgCollectionImpl(String name, List<CoordinateAxis> coordVars) {
4041
this.name = name;
41-
this.timeName = timeName;
42-
this.timeUnit = timeUnit;
43-
this.altName = altName;
44-
this.altUnits = altUnits;
42+
this.coordVars = coordVars;
43+
44+
for (CoordinateAxis coord : coordVars) {
45+
if (coord.getAxisType().isTime()) {
46+
this.timeUnit = CalendarDateUnit.of(null, coord.getUnitsString());
47+
this.timeName = coord.getShortName();
48+
} else if (coord.getAxisType().isVert()) {
49+
this.altUnits = coord.getUnitsString();
50+
this.altName = coord.getShortName();
51+
}
52+
}
4553
}
4654

4755
@Nonnull
@@ -50,13 +58,13 @@ public String getName() {
5058
return name;
5159
}
5260

53-
@Nonnull
61+
@Nullable
5462
@Override
5563
public String getTimeName() {
5664
return timeName;
5765
}
5866

59-
@Nonnull
67+
@Nullable
6068
@Override
6169
public CalendarDateUnit getTimeUnit() {
6270
return timeUnit;
@@ -74,6 +82,12 @@ public String getAltUnits() {
7482
return altUnits;
7583
}
7684

85+
@Nonnull
86+
@Override
87+
public List<CoordinateAxis> getCoordinateVariables() {
88+
return this.coordVars;
89+
}
90+
7791
@Nonnull
7892
public List<Variable> getExtraVariables() {
7993
return (extras == null) ? new ArrayList<>() : extras;

cdm/core/src/main/java/ucar/nc2/ft/point/PointCollectionImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
import java.io.IOException;
88
import java.util.Iterator;
9+
import java.util.List;
910
import javax.annotation.Nonnull;
1011
import ucar.nc2.constants.FeatureType;
12+
import ucar.nc2.dataset.CoordinateAxis;
1113
import ucar.nc2.ft.PointFeature;
1214
import ucar.nc2.ft.PointFeatureCollection;
1315
import ucar.nc2.ft.PointFeatureIterator;
@@ -28,9 +30,8 @@ protected PointCollectionImpl(String name, CalendarDateUnit timeUnit, String alt
2830
super(name, timeUnit, altUnits);
2931
}
3032

31-
protected PointCollectionImpl(String name, String timeName, CalendarDateUnit timeUnit, String altName,
32-
String altUnits) {
33-
super(name, timeName, timeUnit, altName, altUnits);
33+
protected PointCollectionImpl(String name, List<CoordinateAxis> coordVars) {
34+
super(name, coordVars);
3435
}
3536

3637
@Nonnull
@@ -61,7 +62,7 @@ protected static class PointCollectionSubset extends PointCollectionImpl {
6162
protected CalendarDateRange filter_date;
6263

6364
public PointCollectionSubset(PointCollectionImpl from, LatLonRect filter_bb, CalendarDateRange filter_date) {
64-
super(from.name, from.getTimeName(), from.getTimeUnit(), from.getAltName(), from.getAltUnits());
65+
super(from.name, from.timeUnit, from.altUnits);
6566
this.from = from;
6667
this.filter_bb = filter_bb;
6768
this.filter_date = filter_date;

cdm/core/src/main/java/ucar/nc2/ft/point/PointFeatureCCCImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
*/
55
package ucar.nc2.ft.point;
66

7+
import ucar.nc2.dataset.CoordinateAxis;
78
import ucar.nc2.ft.*;
89
import ucar.nc2.time.CalendarDateUnit;
910
import ucar.nc2.constants.FeatureType;
1011
import javax.annotation.Nonnull;
12+
import java.util.List;
1113

1214
/**
1315
* Abstract superclass for multiply nested NestedPointFeatureCollection
@@ -25,9 +27,8 @@ protected PointFeatureCCCImpl(String name, CalendarDateUnit timeUnit, String alt
2527
this.collectionFeatureType = collectionFeatureType;
2628
}
2729

28-
protected PointFeatureCCCImpl(String name, String timeName, CalendarDateUnit timeUnit, String altName,
29-
String altUnits, FeatureType collectionFeatureType) {
30-
super(name, timeName, timeUnit, altName, altUnits);
30+
protected PointFeatureCCCImpl(String name, List<CoordinateAxis> coords, FeatureType collectionFeatureType) {
31+
super(name, coords);
3132
this.collectionFeatureType = collectionFeatureType;
3233
}
3334

cdm/core/src/main/java/ucar/nc2/ft/point/PointFeatureCCImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
package ucar.nc2.ft.point;
66

77
import java.io.IOException;
8+
import java.util.List;
89
import javax.annotation.Nonnull;
910
import ucar.nc2.constants.FeatureType;
11+
import ucar.nc2.dataset.CoordinateAxis;
1012
import ucar.nc2.ft.PointFeatureCC;
1113
import ucar.nc2.ft.PointFeatureIterator;
1214
import ucar.nc2.time.CalendarDateRange;
@@ -29,9 +31,9 @@ protected PointFeatureCCImpl(String name, CalendarDateUnit timeUnit, String altU
2931
this.collectionFeatureType = collectionFeatureType;
3032
}
3133

32-
protected PointFeatureCCImpl(String name, String timeName, CalendarDateUnit timeUnit, String altName, String altUnits,
33-
FeatureType collectionFeatureType) {
34-
super(name, timeName, timeUnit, altName, altUnits);
34+
35+
protected PointFeatureCCImpl(String name, List<CoordinateAxis> coords, FeatureType collectionFeatureType) {
36+
super(name, coords);
3537
this.collectionFeatureType = collectionFeatureType;
3638
}
3739

cdm/core/src/main/java/ucar/nc2/ft/point/ProfileFeatureImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66

77
import javax.annotation.Nonnull;
88
import ucar.nc2.constants.FeatureType;
9+
import ucar.nc2.dataset.CoordinateAxis;
910
import ucar.nc2.ft.ProfileFeature;
1011
import ucar.nc2.time.CalendarDateUnit;
1112
import ucar.unidata.geoloc.LatLonPoint;
1213

14+
import java.util.List;
15+
1316
/**
1417
* Abstract superclass for implementations of ProfileFeature.
1518
*
@@ -31,9 +34,9 @@ public ProfileFeatureImpl(String name, CalendarDateUnit timeUnit, String altUnit
3134
}
3235
}
3336

34-
public ProfileFeatureImpl(String name, String timeName, CalendarDateUnit timeUnit, String altName, String altUnits,
35-
double lat, double lon, double time, int nfeatures) {
36-
super(name, timeName, timeUnit, altName, altUnits);
37+
public ProfileFeatureImpl(String name, List<CoordinateAxis> coords, double lat, double lon, double time,
38+
int nfeatures) {
39+
super(name, coords);
3740
this.latlonPoint = LatLonPoint.create(lat, lon);
3841
this.time = time;
3942
if (nfeatures >= 0) {

cdm/core/src/main/java/ucar/nc2/ft/point/SectionCollectionImpl.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
package ucar.nc2.ft.point;
66

77
import java.io.IOException;
8+
import java.util.List;
9+
810
import ucar.nc2.constants.FeatureType;
11+
import ucar.nc2.dataset.CoordinateAxis;
912
import ucar.nc2.ft.PointFeatureCCIterator;
1013
import ucar.nc2.ft.TrajectoryProfileFeature;
1114
import ucar.nc2.ft.TrajectoryProfileFeatureCollection;
@@ -21,9 +24,12 @@
2124

2225
public abstract class SectionCollectionImpl extends PointFeatureCCCImpl implements TrajectoryProfileFeatureCollection {
2326

24-
protected SectionCollectionImpl(String name, String timeName, CalendarDateUnit timeUnit, String altName,
25-
String altUnits) {
26-
super(name, timeName, timeUnit, altName, altUnits, FeatureType.TRAJECTORY_PROFILE);
27+
protected SectionCollectionImpl(String name, CalendarDateUnit timeUnit, String altUnits) {
28+
super(name, timeUnit, altUnits, FeatureType.TRAJECTORY_PROFILE);
29+
}
30+
31+
protected SectionCollectionImpl(String name, List<CoordinateAxis> coords) {
32+
super(name, coords, FeatureType.TRAJECTORY_PROFILE);
2733
}
2834

2935
/////////////////////////////////////////////////////////////////////////////////////

cdm/core/src/main/java/ucar/nc2/ft/point/SectionFeatureImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

2424
public abstract class SectionFeatureImpl extends PointFeatureCCImpl implements TrajectoryProfileFeature {
2525

26-
protected SectionFeatureImpl(String name, String timeName, CalendarDateUnit timeUnit, String altName,
27-
String altUnits) {
28-
super(name, timeName, timeUnit, altName, altUnits, FeatureType.TRAJECTORY_PROFILE);
26+
27+
protected SectionFeatureImpl(String name, CalendarDateUnit timeUnit, String altUnits) {
28+
super(name, timeUnit, altUnits, FeatureType.TRAJECTORY_PROFILE);
2929
}
3030

3131
/////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)