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;
035import visad.Set;
036
037public class CrIS_SDR_SwathAdapter extends SwathAdapter {
038
039   public CrIS_SDR_SwathAdapter() {
040   }
041
042   public CrIS_SDR_SwathAdapter(MultiDimensionReader reader, Map<String, Object> metadata) {
043     super(reader, metadata);
044   }
045
046   protected void setLengths() {
047     int len = getTrackLength();
048     setTrackLength(len);
049     len = getXTrackLength();
050     setXTrackLength(len *= 9);
051   }
052
053   public FlatField getData(Map<String, double[]> subset) throws Exception {
054
055     Set domainSet = makeDomain(subset);
056
057//     HashMap new_subset = (HashMap) ((HashMap)subset).clone();
058//     new_subset.putAll((HashMap)subset);
059     Map<String, double[]> new_subset = new HashMap<>(subset);
060
061     double[] coords = (double[]) new_subset.get(SwathAdapter.track_name);
062     double[] new_coords = new double[] {0.0, coords[1], 1.0};
063
064     new_subset.put(SwathAdapter.track_name, new_coords);
065     new_coords = new double[] {0.0, (30.0 - 1.0), 1.0};
066     new_subset.put(SwathAdapter.xtrack_name, new_coords);
067
068     new_coords = new double[] {0.0, (9.0 - 1.0), 1.0};
069     new_subset.put(SpectrumAdapter.FOVindex_name, new_coords);
070
071     // put FOVs onto a grid
072
073     FlatField swath = makeFlatField(domainSet, new_subset);
074
075     float[][] corners = MultiSpectralData.getLonLatBoundingCorners(swath.getDomainSet());
076
077     visad.georef.MapProjection mp = MultiSpectralDataSource.getSwathProjection(swath, corners);
078
079     visad.Linear2DSet grid = MultiSpectralDataSource.makeGrid(mp, corners, 15000);
080
081     return ReprojectSwath.swathToGrid(grid, swath, 0);
082   }
083}