Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Hailey Johnson committed Jul 10, 2024
1 parent 2ff52bb commit 7811085
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
1 change: 1 addition & 0 deletions cdm/core/src/main/java/ucar/nc2/constants/CDM.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class CDM {
public static final String ABBREV = "abbreviation";
public static final String ADD_OFFSET = "add_offset";
public static final String CONVENTIONS = "Conventions";
public static final String CF_VERSION = "CF-1.9";
public static final String DESCRIPTION = "description";
public static final String FILL_VALUE = "_FillValue";
public static final String HISTORY = "history";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
*/
public abstract class CFPointWriter implements Closeable {
private static final Logger logger = LoggerFactory.getLogger(CFPointWriter.class);
private static final String CF_VERSION = "CF-1.9";

public static final String recordName = "obs";
public static final String recordDimName = "obs";
Expand Down Expand Up @@ -448,7 +447,7 @@ private void createWriter(String fileOut, CFPointWriterConfig config) throws IOE
}

private void addGlobalAtts(List<Attribute> atts) {
writer.addGroupAttribute(null, new Attribute(CDM.CONVENTIONS, isExtendedModel ? CDM.CF_EXTENDED : CF_VERSION));
writer.addGroupAttribute(null, new Attribute(CDM.CONVENTIONS, isExtendedModel ? CDM.CF_EXTENDED : CDM.CF_VERSION));
writer.addGroupAttribute(null, new Attribute(CDM.HISTORY, "Written by CFPointWriter"));
for (Attribute att : atts) {
if (!reservedGlobalAtts.contains(att.getShortName()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
abstract class WriterCFPointAbstract implements Closeable {
private static final Logger logger = LoggerFactory.getLogger(WriterCFPointAbstract.class);

private static final String CF_VERSION = "CF-1.9";

static final String recordName = "obs";
static final String recordDimName = "obs";
static final String latName = "latitude";
Expand Down Expand Up @@ -128,7 +126,7 @@ abstract class WriterCFPointAbstract implements Closeable {
}

private void addGlobalAtts(AttributeContainer atts) {
writerb.addAttribute(new Attribute(CDM.CONVENTIONS, isExtendedModel ? CDM.CF_EXTENDED : CF_VERSION));
writerb.addAttribute(new Attribute(CDM.CONVENTIONS, isExtendedModel ? CDM.CF_EXTENDED : CDM.CF_VERSION));
writerb.addAttribute(new Attribute(CDM.HISTORY, "Written by CFPointWriter"));
for (Attribute att : atts) {
if (!reservedGlobalAtts.contains(att.getShortName()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.Assert.assertThrows;

import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import ucar.ma2.Array;
import ucar.nc2.constants.FeatureType;
Expand Down Expand Up @@ -95,6 +96,26 @@ public void testCoverageAsPoint() throws IOException {
params.setLatLonPoint(latlon);
readCoverageAsPoint(varNames, params, alts[0], times, vals);

// test time series
varNames = new ArrayList<>();
varNames.add("T1noZ");
vals = Arrays.copyOfRange(expected, 0, 2);
params.setVariables(varNames);
readCoverageAsPoint(varNames, params, alts[0], times, vals);
}

@Ignore("Enable when custom axis names are working")
@Test
public void testCoverageAsPointWithAxisName() throws IOException {

double[] vals = Arrays.copyOfRange(expected, 0, 1);
// test single point (no time)
List<String> varNames = new ArrayList<>();
varNames.add("2D");
SubsetParams params = new SubsetParams();
params.setVariables(varNames);
params.setLatLonPoint(latlon);
readCoverageAsPoint(varNames, params, alts[0], times, vals);
// test time series
varNames = new ArrayList<>();
varNames.add("T1noZ");
Expand Down Expand Up @@ -143,12 +164,17 @@ public void testCoverageAsProfile() throws IOException {
varNames.add("4D");
params.setVariables(varNames);
readCoverageAsProfile(varNames, params, alts, times, expected);
}

@Ignore("Enable when custom axis names are working")
@Test
public void testCoverageAsProfileWithAxisNames() throws IOException {
List<String> varNames = new ArrayList<>();
SubsetParams params = new SubsetParams();

// test two different time axes
varNames = new ArrayList<>();
varNames.add("full4");
varNames.add("withT1");
params = new SubsetParams();
params.setVariables(varNames);
params.setLatLonPoint(latlon);
readCoverageAsProfile(varNames, params, alts, times, expected);
Expand Down

0 comments on commit 7811085

Please sign in to comment.