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.util.HashMap;
032import java.util.Map;
033
034import visad.FlatField;
035
036public class IASI_L1C_Spectrum extends SpectrumAdapter {
037
038  public static float IDefSpectDWn1b = 25f;  //- m-1
039  public static float IDefNsfirst1b = 2581f;
040  public static float IDefNslast1b = 11041f;
041  //-public static int[][] ifov_order2 = new int[][] {new int[] {1,1}, new int[] {0,-1}, new int[] {-1,1}, new int[] {0,-1}};
042  //-public static int[][] ifov_order2 = new int[][] {new int[] {0,1}, new int[] {1,1}, new int[] {1,0}, new int[] {0,0}};
043  public static int[][] ifov_order2 = new int[][] {new int[] {1,1}, new int[] {0,-1}, new int[] {0,0}, new int[] {-1,0}};
044
045  public Map<String, double[]> new_subset = new HashMap<>();
046
047  public IASI_L1C_Spectrum(MultiDimensionReader reader, Map<String, Object> metadata) {
048    super(reader, metadata);
049  }
050
051  public int computeNumChannels() {
052    int numChannels = (int) (IDefNslast1b + 1f - IDefNsfirst1b);
053    return numChannels;
054  }
055
056  public float[] getChannels() throws Exception {
057    float[] spectrum = new float[numChannels];
058    for (int k=0; k<numChannels; k++) {
059      spectrum[k] = (IDefSpectDWn1b*(IDefNsfirst1b+k-1))/100;  //- m-1 to cm-1
060    }
061    return spectrum;
062  }
063
064   
065  public FlatField getData(Map<String, double[]> subset) throws Exception {
066     new_subset.putAll(subset);
067
068     double[] xx = subset.get(SpectrumAdapter.x_dim_name);
069     double[] yy = subset.get(SpectrumAdapter.y_dim_name);
070     double[] new_xx = new double[3];
071     double[] new_yy = new double[3];
072
073     int i = (int) xx[0]/2;
074     int j = (int) yy[0]/2;
075
076     int ii = ((int)xx[0]) - i*2;
077     int jj = ((int)yy[0]) - j*2;
078
079     int k = jj*2 + ii;
080     //int idx = j*120 + i*2 + (jj+ifov_order2[k][0])*60 + (ii+ifov_order2[k][1]);
081     int idx = j*120 + i*4 + (jj+ifov_order2[k][0])*2 + (ii+ifov_order2[k][1]);
082
083     double y = (double) ((int)(idx/120));
084     double x = idx - (int) y*120;
085     
086     new_yy[0] = y;
087     new_yy[1] = y;
088     new_yy[2] = 1;
089
090     new_xx[0] = x;
091     new_xx[1] = x;
092     new_xx[2] = 1;
093
094     new_subset.put(SpectrumAdapter.x_dim_name, new_xx);
095     new_subset.put(SpectrumAdapter.y_dim_name, new_yy);
096
097     return super.getData(new_subset);
098   }
099
100  public float[] processRange(short[] range, Map<String, double[]> subset) {
101    return IASI_L1C_Utility.getDecodedIASISpectra(range, null);
102  }
103
104}