001/* 002 * This file is part of McIDAS-V 003 * 004 * Copyright 2007-2024 005 * Space Science and Engineering Center (SSEC) 006 * University of Wisconsin - Madison 007 * 1225 W. Dayton Street, Madison, WI 53706, USA 008 * https://www.ssec.wisc.edu/mcidas/ 009 * 010 * All Rights Reserved 011 * 012 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and 013 * some McIDAS-V source code is based on IDV and VisAD source code. 014 * 015 * McIDAS-V is free software; you can redistribute it and/or modify 016 * it under the terms of the GNU Lesser Public License as published by 017 * the Free Software Foundation; either version 3 of the License, or 018 * (at your option) any later version. 019 * 020 * McIDAS-V is distributed in the hope that it will be useful, 021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 023 * GNU Lesser Public License for more details. 024 * 025 * You should have received a copy of the GNU Lesser Public License 026 * along with this program. If not, see https://www.gnu.org/licenses/. 027 */ 028 029package edu.wisc.ssec.mcidasv.data.hydra; 030 031import java.io.BufferedReader; 032import java.io.InputStream; 033import java.io.InputStreamReader; 034import java.util.Map; 035import java.util.StringTokenizer; 036 037public class AIRS_L1B_Spectrum extends SpectrumAdapter { 038 039 String propertyFileName; 040 float[] srf_centroid_freq; 041 int[] radiance_quality; 042 private static final float AIRS_VALID_MIN = 0.0f; 043 private static final float AIRS_MISSING_VALUE = -9999.0f; 044 045 public AIRS_L1B_Spectrum(MultiDimensionReader reader, Map<String, Object> metadata) { 046 super(reader, metadata); 047 } 048 049 public float[] getChannels() throws Exception { 050 srf_centroid_freq = new float[numChannels]; 051 radiance_quality = new int[numChannels]; 052 propertyFileName = (String) metadata.get(SpectrumAdapter.ancillary_file_name); 053 InputStream ios = getClass().getResourceAsStream(propertyFileName); 054 BufferedReader ancillaryReader = new BufferedReader(new InputStreamReader(ios)); 055 056 int cnt = 0; 057 while (true) { 058 String line = ancillaryReader.readLine(); 059 if (line == null) 060 break; 061 if (line.startsWith("!")) 062 continue; 063 StringTokenizer strTok = new StringTokenizer(line); 064 String[] tokens = new String[strTok.countTokens()]; 065 int tokCnt = 0; 066 while (strTok.hasMoreElements()) { 067 tokens[tokCnt++] = strTok.nextToken(); 068 } 069 srf_centroid_freq[cnt] = Float.valueOf(tokens[1]); 070 radiance_quality[cnt] = Integer.valueOf(tokens[12]); 071 cnt++; 072 } 073 ios.close(); 074 075 float[] channels = new float[numChannels]; 076 System.arraycopy(srf_centroid_freq, 0, channels, 0, numChannels); 077 return srf_centroid_freq; 078 } 079 080 public float[] processRange(float[] range, Map<String, double[]> subset) { 081 for (int k = 0; k < numChannels; k++) { 082 if (radiance_quality[k] != 0) 083 range[k] = Float.NaN; 084 } 085 float[] new_range = sortRange(range); 086 087 // TJJ Jul 2016, Patch for Inq #2382 088 for (int k = 0; k < new_range.length; k++) { 089 if ((new_range[k] < AIRS_VALID_MIN) || (new_range[k] == AIRS_MISSING_VALUE)) { 090 new_range[k] = Float.NaN; 091 } 092 } 093 094 return new_range; 095 } 096 097 public double[] processRange(double[] range, Map<String, double[]> subset) { 098 for (int k = 0; k < numChannels; k++) { 099 if (radiance_quality[k] != 0) 100 range[k] = Double.NaN; 101 } 102 double[] new_range = sortRange(range); 103 104 // TJJ Jul 2016, Patch for Inq #2382 105 for (int k = 0; k < new_range.length; k++) { 106 if ((new_range[k] < AIRS_VALID_MIN) || (new_range[k] == AIRS_MISSING_VALUE)) { 107 new_range[k] = Double.NaN; 108 } 109 } 110 111 return new_range; 112 } 113 114}