Skip to content

Commit 7051134

Browse files
authored
Merge pull request #1596 from nullschool-tech/gh-1595
grib2: add support for RRFS aerosol products
2 parents 833eacc + 196fed1 commit 7051134

12 files changed

Lines changed: 976 additions & 23 deletions

File tree

grib/src/main/java/ucar/nc2/grib/collection/Grib2Collection.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import ucar.nc2.grib.GribNumbers;
2020
import ucar.nc2.grib.GribTables;
2121
import ucar.nc2.grib.coverage.GribCoverageDataset;
22+
import ucar.nc2.grib.grib2.Grib2Utils;
2223
import ucar.nc2.grib.grib2.table.Grib2Tables;
2324
import ucar.unidata.util.StringUtil2;
2425
import java.io.IOException;
@@ -166,11 +167,12 @@ public void addGlobalAttributes(AttributeContainer result) {
166167
* if variable name is duplicate of existing variable name (this should not normally occur):
167168
* _n (where n begins with 1 for first duplicate) (ex: TMAX_P8_L103_GCA0_6h_1)
168169
*
169-
* VAR_%d-%d-%d[_error][_L%d][_layer][_I%s_S%d][_D%d][_Prob_%s]
170+
* VAR_%d-%d-%d[_error][_L%d][_layer][_I%s_S%d][_D%d][_Prob_%s][_A%d_%s]
170171
* %d-%d-%d = discipline-category-paramNo
171172
* L = level type
172173
* S = stat type
173174
* D = derived type
175+
* A = aerosol type
174176
*/
175177
@Override
176178
protected String makeVariableId(GribCollectionImmutable.VariableIndex vindex) {
@@ -213,6 +215,11 @@ private static String makeVariableId(GribCollectionImmutable.VariableIndex vinde
213215
f.format("_Prob_%s", s);
214216
}
215217

218+
if (vindex.getAerosolType() >= 0) {
219+
f.format("_A%d", vindex.getAerosolType());
220+
f.format("_%s", Grib2Utils.makeAerosolRangeSuffix(vindex.getAerosolRange()));
221+
}
222+
216223
return f.toString();
217224
}
218225
}
@@ -252,6 +259,12 @@ else if (vindex.getProbabilityName() != null && !vindex.getProbabilityName().isE
252259
v.addAttribute(new Attribute("Grib2_Probability_Name", vindex.getProbabilityName()));
253260
}
254261

262+
if (vindex.getAerosolType() >= 0) {
263+
v.addAttribute(new Attribute("Grib2_Aerosol_Type", vindex.getAerosolType()));
264+
v.addAttribute(new Attribute("Grib2_Aerosol_Name", vindex.getAerosolName()));
265+
v.addAttribute(new Attribute("Grib2_Aerosol_Range", vindex.getAerosolRange()));
266+
}
267+
255268
if (vindex.getGenProcessType() >= 0) {
256269
String genProcessTypeName = cust2.getGeneratingProcessTypeName(vindex.getGenProcessType());
257270
if (genProcessTypeName != null)

grib/src/main/java/ucar/nc2/grib/collection/Grib2Iosp.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ static String makeVariableNameFromTable(Grib2Tables cust, GribCollectionImmutabl
8484
if (vindex.getPercentileValue() >= 0) {
8585
f.format("_Percentile%2d", vindex.getPercentileValue());
8686
}
87+
88+
if (vindex.getAerosolType() >= 0) {
89+
f.format("_%s", GribUtils.makeNameFromDescription(vindex.getAerosolName()));
90+
f.format("_%s", Grib2Utils.makeAerosolRangeSuffix(vindex.getAerosolRange()));
91+
}
8792
return f.toString();
8893
}
8994
}
@@ -144,6 +149,10 @@ static String makeVariableLongName(Grib2Tables cust, GribCollectionImmutable.Var
144149
f.format(" %d Percentile", vindex.getPercentileValue());
145150
}
146151

152+
if (vindex.getAerosolName() != null && !vindex.getAerosolName().isEmpty()) {
153+
f.format(" (%s %s)", vindex.getAerosolName(), vindex.getAerosolRange());
154+
}
155+
147156
if (vindex.getLevelType() != GribNumbers.UNDEFINED) { // satellite data doesnt have a level
148157
f.format(" @ %s", cust.getCodeTableValue("4.5", vindex.getLevelType()));
149158
if (vindex.isLayer()) {

grib/src/main/java/ucar/nc2/grib/collection/GribCollectionImmutable.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,18 @@ public String getProbabilityName() {
706706
return info.probabilityName;
707707
}
708708

709+
public int getAerosolType() {
710+
return info.aerosolType;
711+
}
712+
713+
public String getAerosolName() {
714+
return info.aerosolName;
715+
}
716+
717+
public String getAerosolRange() {
718+
return info.aerosolRange;
719+
}
720+
709721
public boolean isLayer() {
710722
return info.isLayer;
711723
}
@@ -825,6 +837,9 @@ public final class Info {
825837
@Nullable
826838
final String intvName; // eg "mixed intervals, 3 Hour, etc"
827839
final String probabilityName;
840+
final int aerosolType;
841+
final String aerosolName;
842+
final String aerosolRange;
828843
final boolean isLayer, isEnsemble;
829844
final int genProcessType;
830845
final int spatialStatType;
@@ -840,6 +855,9 @@ public Info(GribCollectionMutable.VariableIndex gcVar) {
840855
this.probType = gcVar.probType;
841856
this.intvName = gcVar.getTimeIntvName();
842857
this.probabilityName = gcVar.probabilityName;
858+
this.aerosolType = gcVar.aerosolType;
859+
this.aerosolName = gcVar.aerosolName;
860+
this.aerosolRange = gcVar.aerosolRange;
843861
this.isLayer = gcVar.isLayer;
844862
this.isEnsemble = gcVar.isEnsemble;
845863
this.genProcessType = gcVar.genProcessType;

grib/src/main/java/ucar/nc2/grib/collection/GribCollectionMutable.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ public class VariableIndex implements Comparable<VariableIndex> {
435435
public final int category, parameter, levelType, intvType, ensDerivedType, probType, percentile;
436436
private String intvName; // eg "mixed intervals, 3 Hour, etc"
437437
public final String probabilityName;
438+
public final int aerosolType;
439+
public final String aerosolName;
440+
public final String aerosolRange;
438441
public final boolean isLayer, isEnsemble;
439442
public final int genProcessType;
440443
public final int spatialStatType;
@@ -476,6 +479,9 @@ private VariableIndex(GroupGC g, GribTables customizer, int discipline, int cent
476479
this.ensDerivedType = -1;
477480
this.probType = -1;
478481
this.probabilityName = null;
482+
this.aerosolType = -1;
483+
this.aerosolName = null;
484+
this.aerosolRange = null;
479485
this.percentile = -1;
480486

481487
this.genProcessType = pds.getGenProcess(); // LOOK process vs process type ??
@@ -517,6 +523,17 @@ private VariableIndex(GroupGC g, GribTables customizer, int discipline, int cent
517523
this.probabilityName = null;
518524
}
519525

526+
if (pds.isAerosol()) {
527+
Grib2Pds.PdsAerosol pdsAerosol = (Grib2Pds.PdsAerosol) pds;
528+
this.aerosolType = pdsAerosol.getAerosolType();
529+
this.aerosolName = pdsAerosol.getAerosolName();
530+
this.aerosolRange = pdsAerosol.getAerosolRange();
531+
} else {
532+
this.aerosolType = -1;
533+
this.aerosolName = null;
534+
this.aerosolRange = null;
535+
}
536+
520537
if (pds.isPercentile()) {
521538
Grib2Pds.PdsPercentile pdsPctl = (Grib2Pds.PdsPercentile) pds;
522539
this.percentile = pdsPctl.getPercentileValue();
@@ -560,6 +577,9 @@ protected VariableIndex(GroupGC g, VariableIndex other) {
560577
this.ensDerivedType = other.ensDerivedType;
561578
this.probabilityName = other.probabilityName;
562579
this.probType = other.probType;
580+
this.aerosolType = other.aerosolType;
581+
this.aerosolName = other.aerosolName;
582+
this.aerosolRange = other.aerosolRange;
563583
this.genProcessType = other.genProcessType;
564584
this.spatialStatType = other.spatialStatType;
565585
this.isEnsemble = other.isEnsemble;
@@ -619,8 +639,9 @@ public String toString() {
619639
return MoreObjects.toStringHelper(this).add("tableVersion", tableVersion).add("discipline", discipline)
620640
.add("category", category).add("parameter", parameter).add("levelType", levelType).add("intvType", intvType)
621641
.add("ensDerivedType", ensDerivedType).add("probType", probType).add("intvName", intvName)
622-
.add("probabilityName", probabilityName).add("isLayer", isLayer).add("genProcessType", genProcessType)
623-
.add("cdmHash", gribVariable.hashCode()).toString();
642+
.add("probabilityName", probabilityName).add("aerosolName", aerosolName).add("aerosolRange", aerosolRange)
643+
.add("isLayer", isLayer).add("genProcessType", genProcessType).add("cdmHash", gribVariable.hashCode())
644+
.toString();
624645
}
625646

626647
public String toStringComplete() {
@@ -629,8 +650,9 @@ public String toStringComplete() {
629650
.add("recordsLen", recordsLen).add("gribVariable", gribVariable).add("coordIndex", coordIndex)
630651
.add("category", category).add("parameter", parameter).add("levelType", levelType).add("intvType", intvType)
631652
.add("ensDerivedType", ensDerivedType).add("probType", probType).add("intvName", intvName)
632-
.add("probabilityName", probabilityName).add("isLayer", isLayer).add("isEnsemble", isEnsemble)
633-
.add("genProcessType", genProcessType).add("spatialStatType", spatialStatType).toString();
653+
.add("probabilityName", probabilityName).add("aerosolName", aerosolName).add("aerosolRange", aerosolRange)
654+
.add("isLayer", isLayer).add("isEnsemble", isEnsemble).add("genProcessType", genProcessType)
655+
.add("spatialStatType", spatialStatType).toString();
634656
}
635657

636658
public String toStringShort() {
@@ -644,6 +666,9 @@ public String toStringShort() {
644666
if (probabilityName != null && !probabilityName.isEmpty()) {
645667
sb.format(" prob=%s", probabilityName);
646668
}
669+
if (aerosolName != null && !aerosolName.isEmpty()) {
670+
sb.format(" aerosol=%s (%s)", aerosolName, aerosolRange);
671+
}
647672
sb.format(" cdmHash=%d}", gribVariable.hashCode());
648673
return sb.toString();
649674
}

0 commit comments

Comments
 (0)