|
| 1 | +package com.bc.fiduceo.reader.insitu.sic_cci; |
| 2 | + |
| 3 | +import com.bc.fiduceo.util.NetCDFUtils; |
| 4 | +import com.bc.fiduceo.util.VariableProxy; |
| 5 | +import ucar.ma2.DataType; |
| 6 | +import ucar.nc2.Attribute; |
| 7 | +import ucar.nc2.Variable; |
| 8 | + |
| 9 | +import java.text.ParseException; |
| 10 | +import java.util.ArrayList; |
| 11 | +import java.util.List; |
| 12 | + |
| 13 | +import static com.bc.fiduceo.util.NetCDFUtils.*; |
| 14 | + |
| 15 | +class AMSR2SectionParser extends AbstractSectionParser { |
| 16 | + |
| 17 | + @Override |
| 18 | + List<Variable> getVariables() { |
| 19 | + final List<Variable> variables = new ArrayList<>(); |
| 20 | + |
| 21 | + createCommonVariables(variables, "AMSR2_"); |
| 22 | + |
| 23 | + variables.add(createBTVariableProxy("AMSR2_6.9GHzH")); |
| 24 | + variables.add(createBTVariableProxy("AMSR2_6.9GHzV")); |
| 25 | + variables.add(createBTVariableProxy("AMSR2_7.3GHzH")); |
| 26 | + variables.add(createBTVariableProxy("AMSR2_7.3GHzV")); |
| 27 | + variables.add(createBTVariableProxy("AMSR2_10.7GHzH")); |
| 28 | + variables.add(createBTVariableProxy("AMSR2_10.7GHzV")); |
| 29 | + variables.add(createBTVariableProxy("AMSR2_18.7GHzH")); |
| 30 | + variables.add(createBTVariableProxy("AMSR2_18.7GHzV")); |
| 31 | + variables.add(createBTVariableProxy("AMSR2_23.8GHzH")); |
| 32 | + variables.add(createBTVariableProxy("AMSR2_23.8GHzV")); |
| 33 | + variables.add(createBTVariableProxy("AMSR2_36.5GHzH")); |
| 34 | + variables.add(createBTVariableProxy("AMSR2_36.5GHzV")); |
| 35 | + variables.add(createBTVariableProxy("AMSR2_89.0GHzH")); |
| 36 | + variables.add(createBTVariableProxy("AMSR2_89.0GHzV")); |
| 37 | + |
| 38 | + ArrayList<Attribute> attributes = new ArrayList<>(); |
| 39 | + attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class))); |
| 40 | + attributes.add(new Attribute(CF_STANDARD_NAME, "angle_of_incidence")); |
| 41 | + attributes.add(new Attribute(CF_UNITS_NAME, "deg")); |
| 42 | + variables.add(new VariableProxy("AMSR2_Earth-Incidence", DataType.FLOAT, attributes)); |
| 43 | + |
| 44 | + attributes = new ArrayList<>(); |
| 45 | + attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class))); |
| 46 | + attributes.add(new Attribute(CF_UNITS_NAME, "deg")); |
| 47 | + variables.add(new VariableProxy("AMSR2_Earth-Azimuth", DataType.FLOAT, attributes)); |
| 48 | + |
| 49 | + attributes = new ArrayList<>(); |
| 50 | + attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(short.class))); |
| 51 | + attributes.add(new Attribute(CF_LONG_NAME, "Scanpos (0-243)")); |
| 52 | + variables.add(new VariableProxy("AMSR2_scanpos", DataType.SHORT, attributes)); |
| 53 | + |
| 54 | + attributes = new ArrayList<>(); |
| 55 | + variables.add(new VariableProxy("AMSR2_upstreamfile", DataType.CHAR, attributes)); |
| 56 | + |
| 57 | + attributes = new ArrayList<>(); |
| 58 | + attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(short.class))); |
| 59 | + attributes.add(new Attribute(CF_LONG_NAME, "Time difference between reference time and AMSR time (seconds)")); |
| 60 | + attributes.add(new Attribute(CF_UNITS_NAME, "s")); |
| 61 | + variables.add(new VariableProxy("AMSR2_timediff", DataType.SHORT, attributes)); |
| 62 | + |
| 63 | + return variables; |
| 64 | + } |
| 65 | + |
| 66 | + private static VariableProxy createBTVariableProxy(String name) { |
| 67 | + ArrayList<Attribute> attributes = new ArrayList<>(); |
| 68 | + attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class))); |
| 69 | + attributes.add(new Attribute(CF_STANDARD_NAME, "toa_brightness_temperature")); |
| 70 | + attributes.add(new Attribute(CF_UNITS_NAME, "K")); |
| 71 | + return new VariableProxy(name, DataType.FLOAT, attributes); |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + int getNumVariables() { |
| 76 | + return 23; |
| 77 | + } |
| 78 | + |
| 79 | + @Override |
| 80 | + String getNamePrefix() { |
| 81 | + return "AMSR2"; |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + Section parse(String[] tokens, int offset) throws ParseException { |
| 86 | + final Section section = new Section(); |
| 87 | + |
| 88 | + section.add("AMSR2_latitude", parseFloat(tokens[offset])); |
| 89 | + section.add("AMSR2_longitude", parseFloat(tokens[offset + 1])); |
| 90 | + section.add("AMSR2_time", parseUtcTime(tokens[offset + 2])); |
| 91 | + section.add("AMSR2_reference-id", parseString(tokens[offset + 3])); |
| 92 | + section.add("AMSR2_6.9GHzH", parseFloat(tokens[offset + 4])); |
| 93 | + section.add("AMSR2_6.9GHzV", parseFloat(tokens[offset + 5])); |
| 94 | + section.add("AMSR2_7.3GHzH", parseFloat(tokens[offset + 6])); |
| 95 | + section.add("AMSR2_7.3GHzV", parseFloat(tokens[offset + 7])); |
| 96 | + section.add("AMSR2_10.7GHzH", parseFloat(tokens[offset + 8])); |
| 97 | + section.add("AMSR2_10.7GHzV", parseFloat(tokens[offset + 9])); |
| 98 | + section.add("AMSR2_18.7GHzH", parseFloat(tokens[offset + 10])); |
| 99 | + section.add("AMSR2_18.7GHzV", parseFloat(tokens[offset + 11])); |
| 100 | + section.add("AMSR2_23.8GHzH", parseFloat(tokens[offset + 12])); |
| 101 | + section.add("AMSR2_23.8GHzV", parseFloat(tokens[offset + 13])); |
| 102 | + section.add("AMSR2_36.5GHzH", parseFloat(tokens[offset + 14])); |
| 103 | + section.add("AMSR2_36.5GHzV", parseFloat(tokens[offset + 15])); |
| 104 | + section.add("AMSR2_89.0GHzH", parseFloat(tokens[offset + 16])); |
| 105 | + section.add("AMSR2_89.0GHzV", parseFloat(tokens[offset + 17])); |
| 106 | + section.add("AMSR2_Earth-Incidence", parseFloat(tokens[offset + 18])); |
| 107 | + section.add("AMSR2_Earth-Azimuth", parseFloat(tokens[offset + 19])); |
| 108 | + section.add("AMSR2_scanpos", parseShort(tokens[offset + 20])); |
| 109 | + section.add("AMSR2_upstreamfile", parseString(tokens[offset + 21])); |
| 110 | + section.add("AMSR2_timediff", parseShort(tokens[offset + 22])); |
| 111 | + |
| 112 | + return section; |
| 113 | + } |
| 114 | +} |
0 commit comments