From 59996e3317860c4164eb8bcc6358a590552c8592 Mon Sep 17 00:00:00 2001 From: up201304360 Date: Mon, 23 Apr 2018 22:01:01 +0100 Subject: [PATCH 1/2] pt.lsts.neptus.plugins.datacdf Plugin to read bathymetry from a file and add to Neptus with Depth Soundings --- .classpath | 1 + conf/consoles/lauv.ncon | 19 +- plugins-dev/datacdf/plugins.lst | 1 + .../lsts/neptus/plugins/datacdf/Datacdf.java | 248 ++++++++++++++++++ 4 files changed, 260 insertions(+), 9 deletions(-) create mode 100644 plugins-dev/datacdf/plugins.lst create mode 100644 plugins-dev/datacdf/pt/lsts/neptus/plugins/datacdf/Datacdf.java diff --git a/.classpath b/.classpath index 9788aaa42c..0f397d81b7 100644 --- a/.classpath +++ b/.classpath @@ -73,6 +73,7 @@ + diff --git a/conf/consoles/lauv.ncon b/conf/consoles/lauv.ncon index 23723aaafd..d9a5c7a155 100644 --- a/conf/consoles/lauv.ncon +++ b/conf/consoles/lauv.ncon @@ -1,8 +1,8 @@ - + - + <profiles> <profile name="Normal"> @@ -87,21 +87,19 @@ - + false - + - - N38.44020556°, W9.11050278° - + @@ -158,6 +156,9 @@ altitude: ${EstimatedState.alt}; + + + @@ -181,10 +182,10 @@ altitude: ${EstimatedState.alt}; - + - + diff --git a/plugins-dev/datacdf/plugins.lst b/plugins-dev/datacdf/plugins.lst new file mode 100644 index 0000000000..4d9e1306d6 --- /dev/null +++ b/plugins-dev/datacdf/plugins.lst @@ -0,0 +1 @@ +pt.lsts.neptus.plugins.datacdf.Datacdf diff --git a/plugins-dev/datacdf/pt/lsts/neptus/plugins/datacdf/Datacdf.java b/plugins-dev/datacdf/pt/lsts/neptus/plugins/datacdf/Datacdf.java new file mode 100644 index 0000000000..72067f04b4 --- /dev/null +++ b/plugins-dev/datacdf/pt/lsts/neptus/plugins/datacdf/Datacdf.java @@ -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 . + * + * Author: nachito + * 23/04/2018 + */ +package pt.lsts.neptus.plugins.datacdf; + +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 Datacdf extends ConsolePanel { + + /** + * + */ + private static final long serialVersionUID = 1L; + + + + /** + * + */ + + /** + * @param console + */ + + // TODO Auto-generated method stub + + public Datacdf(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 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 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(Datacdf.class); + } +} \ No newline at end of file From 26c5a1c1220973b6830b80ea74334e603926cf65 Mon Sep 17 00:00:00 2001 From: Ines Cruz Date: Thu, 26 Apr 2018 10:31:44 +0100 Subject: [PATCH 2/2] plugins/gebcoimport: Refactoring class name and package name. --- .classpath | 2 +- plugins-dev/datacdf/plugins.lst | 1 - plugins-dev/gebcoimport/plugins.lst | 1 + .../plugins/gebcoimport/GebcoBathymetryImport.java} | 8 ++++---- 4 files changed, 6 insertions(+), 6 deletions(-) delete mode 100644 plugins-dev/datacdf/plugins.lst create mode 100644 plugins-dev/gebcoimport/plugins.lst rename plugins-dev/{datacdf/pt/lsts/neptus/plugins/datacdf/Datacdf.java => gebcoimport/pt/lsts/neptus/plugins/gebcoimport/GebcoBathymetryImport.java} (97%) diff --git a/.classpath b/.classpath index 0f397d81b7..2e3a5baba8 100644 --- a/.classpath +++ b/.classpath @@ -73,7 +73,7 @@ - + diff --git a/plugins-dev/datacdf/plugins.lst b/plugins-dev/datacdf/plugins.lst deleted file mode 100644 index 4d9e1306d6..0000000000 --- a/plugins-dev/datacdf/plugins.lst +++ /dev/null @@ -1 +0,0 @@ -pt.lsts.neptus.plugins.datacdf.Datacdf diff --git a/plugins-dev/gebcoimport/plugins.lst b/plugins-dev/gebcoimport/plugins.lst new file mode 100644 index 0000000000..eadd121c63 --- /dev/null +++ b/plugins-dev/gebcoimport/plugins.lst @@ -0,0 +1 @@ +pt.lsts.neptus.plugins.gebcoimport.GebcoBathymetryImport diff --git a/plugins-dev/datacdf/pt/lsts/neptus/plugins/datacdf/Datacdf.java b/plugins-dev/gebcoimport/pt/lsts/neptus/plugins/gebcoimport/GebcoBathymetryImport.java similarity index 97% rename from plugins-dev/datacdf/pt/lsts/neptus/plugins/datacdf/Datacdf.java rename to plugins-dev/gebcoimport/pt/lsts/neptus/plugins/gebcoimport/GebcoBathymetryImport.java index 72067f04b4..d0c3dad6c9 100644 --- a/plugins-dev/datacdf/pt/lsts/neptus/plugins/datacdf/Datacdf.java +++ b/plugins-dev/gebcoimport/pt/lsts/neptus/plugins/gebcoimport/GebcoBathymetryImport.java @@ -30,7 +30,7 @@ * Author: nachito * 23/04/2018 */ -package pt.lsts.neptus.plugins.datacdf; +package pt.lsts.neptus.plugins.gebcoimport; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -58,7 +58,7 @@ import ucar.nc2.Variable; @PluginDescription(name = "NetCDF Tools") -public class Datacdf extends ConsolePanel { +public class GebcoBathymetryImport extends ConsolePanel { /** * @@ -77,7 +77,7 @@ public class Datacdf extends ConsolePanel { // TODO Auto-generated method stub - public Datacdf(ConsoleLayout console) { + public GebcoBathymetryImport(ConsoleLayout console) { super(console); } @@ -243,6 +243,6 @@ public void actionPerformed(ActionEvent e) { public static void main(String[] args) { - ConsoleParse.testSubPanel(Datacdf.class); + ConsoleParse.testSubPanel(GebcoBathymetryImport.class); } } \ No newline at end of file