001/*
002 * $Id: JPSSUtilities.java,v 1.11 2011/03/24 16:06:33 davep Exp $
003 *
004 * This file is part of McIDAS-V
005 *
006 * Copyright 2007-2011
007 * Space Science and Engineering Center (SSEC)
008 * University of Wisconsin - Madison
009 * 1225 W. Dayton Street, Madison, WI 53706, USA
010 * https://www.ssec.wisc.edu/mcidas
011 * 
012 * All Rights Reserved
013 * 
014 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
015 * some McIDAS-V source code is based on IDV and VisAD source code.  
016 * 
017 * McIDAS-V is free software; you can redistribute it and/or modify
018 * it under the terms of the GNU Lesser Public License as published by
019 * the Free Software Foundation; either version 3 of the License, or
020 * (at your option) any later version.
021 * 
022 * McIDAS-V is distributed in the hope that it will be useful,
023 * but WITHOUT ANY WARRANTY; without even the implied warranty of
024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
025 * GNU Lesser Public License for more details.
026 * 
027 * You should have received a copy of the GNU Lesser Public License
028 * along with this program.  If not, see http://www.gnu.org/licenses.
029 */
030
031package edu.wisc.ssec.mcidasv.data.hydra;
032
033import java.util.HashMap;
034
035/**
036 * Utility class to support Joint Polar Satellite System (JPSS) functionality.
037 * Some of this is temporary hashmaps, needed because the currently available
038 * NPP data does not fully, correctly implement the specs yet as defined in
039 * the NPP Common Data Format Control Book.  See:
040 * http://jointmission.gsfc.nasa.gov/project/science-documents.html
041 * 
042 * @author tommyj
043 *
044 */
045
046public abstract class JPSSUtilities {
047   
048        public static float[] ATMSChannelCenterFrequencies = {
049                23.8f,
050                31.4f,
051                50.3f,
052                51.76f,
053                52.8f,
054                53.596f,
055                54.40f,
056                54.94f,
057                55.50f,
058                57.2903f,
059                57.2903f,
060                57.2903f,
061                57.2903f,
062                57.2903f,
063                57.2903f,
064                88.20f,
065                165.5f,
066                183.31f,
067                183.31f,
068                183.31f,
069                183.31f,
070                183.31f
071        };
072        
073        // the list of valid geolocation product ids
074        public static String[] geoProductIDs = {
075        "GATMO",
076        "GCRIO",
077        "GCRSO",
078        "GMGTO",
079        "GMODO",
080        "GMTCO",
081        "IVMIM",
082        "VMUGE",
083        "GNCCO",
084        "GDNBO",
085        "GIGTO",
086        "GIMGO",
087        "GITCO",
088        "GCLDO"         
089        };
090        
091        private static HashMap<String, String> geoHM = new HashMap<String, String>();
092    private static HashMap<String, String> prodHM = new HashMap<String, String>();
093    private static HashMap<String, String> factHM = new HashMap<String, String>();
094    
095    static {
096        
097        // populate geolocation hashmap
098        // Collection Short Name -> Geolocation Product ID
099        // This mapping is based on Table A-8, "Geolocation Identifiers", from
100        // NPP CDFCB Volume 1
101        // http://jointmission.gsfc.nasa.gov/projects/science-documents.html
102        // NOTE: I have found some mappings to be missing!  I.E., the table
103        // in the spec is apparently not complete!
104        
105        geoHM.put("ATMS-SDR-GEO", "GATMO");
106        geoHM.put("CrIMSS-AUX-EDR", "GCRIO");
107        geoHM.put("CrIS-SDR-GEO", "GCRSO");
108        geoHM.put("VIIRS-MOD-EDR-GEO", "GMGTO");
109        geoHM.put("VIIRS-MOD-GEO", "GMODO");
110        geoHM.put("VIIRS-MOD-GEO-TC", "GMTCO");
111        geoHM.put("VIIRS-MOD-MAP-IP", "IVMIM");
112        geoHM.put("VIIRS-MOD-UNAGG-GEO", "VMUGE");
113        geoHM.put("VIIRS-NCC-EDR-GEO", "GNCCO");
114        geoHM.put("VIIRS-DNB-GEO", "GDNBO");
115        geoHM.put("VIIRS-IMG-EDR-GEO", "GIGTO");
116        geoHM.put("VIIRS-IMG-GEO", "GIMGO");
117        geoHM.put("VIIRS-IMG-GEO-TC", "GITCO");
118        geoHM.put("VIIRS-CLD-AGG-GEO", "GCLDO");
119        geoHM.put("VIIRS-SIC-GEO", "GSICO");
120        
121        // populate product hashmap
122        // This table is needed because the product names in the actual granules
123        // do not match those in the XML Product Profiles, which appear to be 
124        // a short-hand version of the longer names.  Swell.
125        // Mapping:  Product name in granule -> Product name in XML Product Profile
126        
127        prodHM.put("Albedo", "albedo");
128        prodHM.put("AntennaTemperature", "antennaTemperature");
129        prodHM.put("BrightnessTemperature", "BrightnessTemperature");
130        prodHM.put("BulkSeaSurfaceTemperature", "bulkSST");
131        prodHM.put("Chlorophyll_a", "chlo_data");
132        prodHM.put("CloudBaseHeightLayer", "cbhLyr");
133        prodHM.put("CloudBaseHeightTotal", "cbhTot");
134        prodHM.put("IceAge", "iceAge");
135        prodHM.put("IceAgeWeight", "iceAgeWeight");
136        prodHM.put("IST_Array", "IST Pixel");
137        prodHM.put("Land_Temp", "lst");
138        prodHM.put("NumberOfAggregatedImageryPixels", "scdNumAggPix");
139        prodHM.put("Radiance", "Radiance");
140        prodHM.put("Reflectance", "Reflectance");
141        prodHM.put("SceneCounts", "sceneCounts");
142        prodHM.put("SkinSeaSurfaceTemperature", "skinSST");
143        prodHM.put("SnowCoverBinaryMap", "scdBinaryMap");
144        prodHM.put("SnowFraction", "scdFractionFromBinaryMap");
145        prodHM.put("TopOfAtmosphereNormalizedDifferenceVegetationIndex", "TOA_NDVI");
146        prodHM.put("TopOfCanopyEnhancedVegetationIndex", "TOC_EVI");
147        prodHM.put("VegetationFraction", "vegFraction");
148        
149        // populate scale and offset factors hashmap
150        // This table is needed because the variable name for the scale and offset
151        // is NOT ALWAYS simply the variable name with "Factors" appended, as is 
152        // implied in the reference doc.  From CDFCB-X, Vol 5, page 8:
153        // "In general, the scale factor name is generated by appending "Factors"
154        // to the name of the parameter that is scaled."  
155        
156        factHM.put("Albedo", "Factors");
157        factHM.put("AntennaTemperature", "AntennaTemperatureFactors");
158        factHM.put("BrightnessTemperature", "BrightnessTemperatureFactors");
159        factHM.put("BulkSeaSurfaceTemperatures", "BulkFactors");
160        factHM.put("CloudBaseHeightTotal", "CloudBaseHeightFactors");
161        factHM.put("IST_Array", "IST_Factors");
162        factHM.put("Land_Temp", "LST_Factors");
163        factHM.put("Radiance", "RadianceFactors");
164        factHM.put("Reflectance", "ReflectanceFactors");
165        factHM.put("SkinSeaSurfaceTemperatures", "SkinFactors");
166        factHM.put("SmokeConcentration", "SmokeConcentrationFactors");
167        factHM.put("SnowFraction", "SnowFractionFactors");
168        factHM.put("TopOfAtmosphereNormalizedDifferenceVegetationIndex", "TOA_NDVI_Factors");
169        factHM.put("TopOfCanopyEnhancedVegetationIndex", "TOC_EVI_Factors");
170        factHM.put("VegetationFraction", "Factors");
171        
172    }
173
174    
175    /**
176     * Map an NPP variable name to the corresponding name of the variable
177     * containing scale and offset factors.
178     * 
179     * @param varName
180     * @return variable name for the corresponding scale and offset factors 
181     */
182    
183    public static String mapDataVarNameToFactorsName(String varName) {
184        String s = null;
185        if (factHM != null) {
186                s = (String) factHM.get(varName);
187        }
188        return s;
189    }
190    
191    /**
192     * Map the NPP global attribute N_GEO_Ref to the appropriate geolocation
193     * product id prefix.
194     * 
195     * @param geoRef
196     * @return product id for the corresponding geolocation data 
197     */
198    
199    public static String mapGeoRefToProductID(String geoRef) {
200        String s = null;
201        if (geoHM != null) {
202                s = (String) geoHM.get(geoRef);
203        }
204        return s;
205    }
206    
207    /**
208     * Map the NPP product name to those used in the XML Product Profiles,
209     * which seem to be short-hand versions of the long names.
210     * 
211     * @param prodName
212     * @return product id for the corresponding XML Product Profile
213     */
214    
215    public static String mapProdNameToProfileName(String prodName) {
216        String s = null;
217        if (prodHM != null) {
218                s = (String) prodHM.get(prodName);
219        }
220        return s;
221    }
222    
223    /**
224         * Return true if the input string is a valid NPP Product
225     * 
226     * @param prodName
227     * @return true if the input string is a valid NPP Product
228     */
229    
230    public static boolean isValidNPPProduct(String prodName) {
231        if (prodName == null) return false;
232        if (prodHM != null) {
233                if (prodHM.containsValue(prodName)) {
234                        return true;
235                }
236        }
237        return false;
238    }
239        
240}