Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/gebcoimport #89

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<classpathentry kind="src" path="plugins-dev/arcgis-maps"/>
<classpathentry kind="src" path="plugins-dev/soi"/>
<classpathentry kind="src" path="plugins-dev/hmapping"/>
<classpathentry kind="src" path="plugins-dev/gebcoimport"/>
<classpathentry kind="lib" path="lib/log4j-1.2.17.jar"/>
<classpathentry kind="lib" path="lib/xerces-2.7.1/xml-apis.jar"/>
<classpathentry kind="lib" path="lib/xerces-2.7.1/xercesImpl.jar"/>
Expand Down
19 changes: 10 additions & 9 deletions conf/consoles/lauv.ncon
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<console name="Neptus Console" width="1366" height="727" resizable="true" mission-file="../../missions/APDL/missao-apdl.nmisz" main-vehicle="lauv-xplore-1">
<!-- Data saved on 2018-04-07T11:57:44.0Z with Neptus version 2018.01.1-dev (compiled on 2018-04-05, gtag/20170721-rep17-arpao-337-gd346a79-dirty). -->
<!-- Data saved on 2018-04-23T21:56:49.0Z with Neptus version @VERSION@ (compiled on @DATE@, g@SCM_REV@). -->
<mainpanel name="console main panel">
<subpanel class="pt.lsts.neptus.console.plugins.containers.MigLayoutContainer" x="0" y="0" width="1360" height="643">
<subpanel class="pt.lsts.neptus.console.plugins.containers.MigLayoutContainer" x="0" y="0" width="1366" height="641">
<properties>
<entry key="XML Definitions">&lt;profiles&gt;
&lt;profile name="Normal"&gt;
Expand Down Expand Up @@ -87,21 +87,19 @@
<child class="pt.lsts.neptus.plugins.map.MapEditor" x="0" y="0" width="0" height="0">
<properties/>
</child>
<child class="pt.lsts.neptus.console.plugins.planning.MapPanel" x="0" y="0" width="1054" height="643">
<child class="pt.lsts.neptus.console.plugins.planning.MapPanel" x="0" y="0" width="1060" height="641">
<properties>
<entry key="World Map Transparency">false</entry>
</properties>
</child>
<child class="pt.lsts.neptus.console.plugins.planning.MissionTreePanel" x="0" y="162" width="294" height="475">
<child class="pt.lsts.neptus.console.plugins.planning.MissionTreePanel" x="0" y="162" width="294" height="473">
<properties/>
</child>
<child class="pt.lsts.neptus.console.plugins.planning.MultiVehiclePlanOverlay" x="0" y="0" width="0" height="0">
<properties/>
</child>
<child class="pt.lsts.neptus.console.plugins.MyLocationDisplay" x="0" y="0" width="0" height="0">
<properties>
<entry key="Location">N38.44020556°, W9.11050278°</entry>
</properties>
<properties/>
</child>
<child class="pt.lsts.neptus.plugins.oplimits.OperationLimitsSubPanel" x="0" y="0" width="95" height="40">
<properties/>
Expand Down Expand Up @@ -158,6 +156,9 @@ altitude: ${EstimatedState.alt};
<child class="pt.lsts.neptus.plugins.sunfish.iridium.feedback.IridiumStatus" x="0" y="0" width="0" height="0">
<properties/>
</child>
<child class="pt.lsts.neptus.plugins.datacdf.Datacdf" x="0" y="0" width="0" height="0">
<properties/>
</child>
</subpanel>
</mainpanel>
<mainpanel name="console alarm panel"/>
Expand All @@ -181,10 +182,10 @@ altitude: ${EstimatedState.alt};
<layer class="pt.lsts.neptus.console.plugins.planning.PlanSimulationLayer" opacity="1.0">
<properties/>
</layer>
<layer class="pt.lsts.neptus.plugins.position.painter.SystemInfoPainter" opacity="1.0">
<layer class="pt.lsts.ripples.RipplesPositions" opacity="1.0">
<properties/>
</layer>
<layer class="pt.lsts.ripples.RipplesPositions" opacity="1.0">
<layer class="pt.lsts.neptus.plugins.position.painter.SystemInfoPainter" opacity="1.0">
<properties/>
</layer>
</layers>
Expand Down
1 change: 1 addition & 0 deletions plugins-dev/gebcoimport/plugins.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pt.lsts.neptus.plugins.gebcoimport.GebcoBathymetryImport
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
/*
* Copyright (c) 2004-2018 Universidade do Porto - Faculdade de Engenharia
* Laboratório de Sistemas e Tecnologia Subaquática (LSTS)
* All rights reserved.
* Rua Dr. Roberto Frias s/n, sala I203, 4200-465 Porto, Portugal
*
* This file is part of Neptus, Command and Control Framework.
*
* Commercial Licence Usage
* Licencees holding valid commercial Neptus licences may use this file
* in accordance with the commercial licence agreement provided with the
* Software or, alternatively, in accordance with the terms contained in a
* written agreement between you and Universidade do Porto. For licensing
* terms, conditions, and further information contact lsts@fe.up.pt.
*
* Modified European Union Public Licence - EUPL v.1.1 Usage
* Alternatively, this file may be used under the terms of the Modified EUPL,
* Version 1.1 only (the "Licence"), appearing in the file LICENSE.md
* included in the packaging of this file. You may not use this work
* except in compliance with the Licence. Unless required by applicable
* law or agreed to in writing, software distributed under the Licence is
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the Licence for the specific
* language governing permissions and limitations at
* https://github.com/LSTS/neptus/blob/develop/LICENSE.md
* and http://ec.europa.eu/idabc/eupl.html.
*
* For more information please see <http://lsts.fe.up.pt/neptus>.
*
* Author: nachito
* 23/04/2018
*/
package pt.lsts.neptus.plugins.gebcoimport;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;


import javax.swing.JFileChooser;
import pt.lsts.neptus.console.ConsoleLayout;
import pt.lsts.neptus.console.ConsolePanel;
import pt.lsts.neptus.console.plugins.planning.SimulatedBathymetry;
import pt.lsts.neptus.data.Pair;
import pt.lsts.neptus.i18n.I18n;
import pt.lsts.neptus.plugins.PluginDescription;
import pt.lsts.neptus.plugins.PluginUtils;
import pt.lsts.neptus.types.coord.LocationType;
import pt.lsts.neptus.util.AngleUtils;
import pt.lsts.neptus.util.ConsoleParse;
import pt.lsts.neptus.util.ImageUtils;
import pt.lsts.neptus.util.netcdf.NetCDFUtils;
import ucar.ma2.Array;
import ucar.nc2.NetcdfFile;
import ucar.nc2.Variable;

@PluginDescription(name = "NetCDF Tools")
public class GebcoBathymetryImport extends ConsolePanel {

/**
*
*/
private static final long serialVersionUID = 1L;



/**
*
*/

/**
* @param console
*/

// TODO Auto-generated method stub

public GebcoBathymetryImport(ConsoleLayout console) {

super(console);
}

/*
* (non-Javadoc)
*
* @see pt.lsts.neptus.console.ConsolePanel#cleanSubPanel()
*/
@Override
public void cleanSubPanel() {
removeMenuItem(I18n.text("Tools") + ">" + I18n.text("NetCDF"));

}

/*
* (non-Javadoc)
*
* @see pt.lsts.neptus.console.ConsolePanel#initSubPanel()
*/
@Override
public void initSubPanel() {


addMenuItem(I18n.text("Tools") + ">" + I18n.text("NetCDF"),
ImageUtils.getIcon(PluginUtils.getPluginIcon(getClass())), new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {


JFileChooser fileChooser = new JFileChooser();
int returnValue = fileChooser.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();


NetcdfFile dataFile = null;
try {
dataFile = NetcdfFile.open(selectedFile.getAbsolutePath());
System.out.println(dataFile.toString());
Pair<String, Variable> searchPair = NetCDFUtils.findVariableForStandardNameOrName(
dataFile, selectedFile.getAbsolutePath(), true, "latitude", "lat");

Variable latVar = searchPair.second();

searchPair = NetCDFUtils.findVariableForStandardNameOrName(dataFile,
selectedFile.getAbsolutePath(), true, "longitude", "lon");
Variable lonVar = searchPair.second();

searchPair = NetCDFUtils.findVariableForStandardNameOrName(dataFile,
selectedFile.getAbsolutePath(), true, "elevation",
"height_above_reference_ellipsoid");
Variable elevVar = searchPair.second();

searchPair = NetCDFUtils.findVariableForStandardNameOrName(dataFile,
selectedFile.getAbsolutePath(), true, "time");
Variable timeVar = searchPair == null ? null : searchPair.second();

searchPair = NetCDFUtils.findVariableForStandardNameOrName(dataFile,
selectedFile.getAbsolutePath(), false, "depth", "altitude");
Variable depthOrAltitudeVar = searchPair == null ? null : searchPair.second();

// Get the u (north) wind velocity Variables.
searchPair = NetCDFUtils.findVariableForStandardNameOrName(dataFile,
selectedFile.getAbsolutePath(), false, "x_wind", "grid_eastward_wind", "u");
Variable uVar = searchPair == null ? null : searchPair.second();

// Get the v (east) wind velocity Variables.
searchPair = NetCDFUtils.findVariableForStandardNameOrName(dataFile,
selectedFile.getAbsolutePath(), false, "y_wind", "grid_northward_wind", "v");
Variable vVar = searchPair == null ? null : searchPair.second();

if (latVar == null) {
System.out.println("Cant find Variable latitude");
}
if (lonVar == null) {
System.out.println("Cant find Variable longitude");
}
if (timeVar == null) {
System.out.println("Cant find Variable time");
}
if (uVar == null) {
System.out.println("Cant find Variable xWind");
}
if (vVar == null) {
System.out.println("Cant find Variable yWind");
}
if (elevVar == null) {
System.out.println("Cant find Variable elevation");
}

if (depthOrAltitudeVar == null) {
System.out.println("Cant find Variable depth or altitude");

}

//TODO add u and v
// Get the lat/lon data from the file.
Array latArray; // ArrayFloat.D1
Array lonArray; // ArrayFloat.D1
Array elevArray;

latArray = latVar.read();
lonArray = lonVar.read();
elevArray = elevVar.read();



double lat = 0;
double lon = 0;
double elev=0;


Map<LocationType, Double> data= new HashMap<>();


for(int i = 0; i < elevArray.getSize(); i++) {
lat = AngleUtils.nomalizeAngleDegrees180((latArray.getDouble((int) (i/lonArray.getSize()))));

lon = AngleUtils.nomalizeAngleDegrees180(lonArray.getDouble((int) (i%lonArray.getSize())));

elev = elevArray.getDouble(i);
LocationType l = new LocationType();
l.setLatitudeDegs(lat);
l.setLongitudeDegs(lon);
l.setDepth(elev);
System.out.println("l: " + l);

data.put(l, l.getDepth());
}


SimulatedBathymetry.getInstance().addSoundings(data);

}
catch (java.io.IOException e1) {
System.out.println(" fail = " + e1);
e1.printStackTrace();
}
catch (Exception e1) {
e1.printStackTrace();
}
finally {
if (dataFile != null)
try {
dataFile.close();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}

}



}
});

}



public static void main(String[] args) {
ConsoleParse.testSubPanel(GebcoBathymetryImport.class);
}
}