def main():
    # create a project
    lib = SoundSpeedLibrary()

    # set the current project name
    lib.setup.current_project = 'test'
    lib.setup.save_to_db()

    # retrieve all the id profiles from db
    lst = lib.db_list_profiles()
    logger.info("Profiles: %s" % len(lst))

    # plots/maps/exports
    # - map
    lib.map_db_profiles()
    lib.save_map_db_profiles()

    # - aggregate plot
    ssp_times = lib.db_timestamp_list()
    dates = [ssp_times[0][0].date(), ssp_times[-1][0].date()]
    lib.aggregate_plot(dates=dates)
    lib.save_aggregate_plot(dates=dates)

    # - daily plots
    lib.plot_daily_db_profiles()
    lib.save_daily_db_profiles()

    # - exports
    lib.export_db_profiles_metadata(ogr_format=GdalAux.ogr_formats[b'KML'])
    lib.export_db_profiles_metadata(ogr_format=GdalAux.ogr_formats[b'CSV'])
    lib.export_db_profiles_metadata(
        ogr_format=GdalAux.ogr_formats[b'ESRI Shapefile'])

    logger.info('test: *** END ***')
예제 #2
0
    def setUp(self):
        def add_cast(lat, lon):
            self.lib.ssp.cur.meta.latitude = lat
            self.lib.ssp.cur.meta.longitude = lon
            self.lib.ssp.cur.meta.utc_time = datetime.now()
            self.lib.ssp.cur.init_data(self.levels)
            self.lib.ssp.cur.data.depth[:self.levels] = self.depth
            self.lib.ssp.cur.data.speed[:self.levels] = 1415
            self.lib.restart_proc()
            self.lib.store_data()

        self.max_pk = 5
        self.levels = self.max_pk * self.max_pk
        self.depth = np.array(range(self.levels))
        projects_folder = os.path.abspath(os.curdir)
        project_name = 'unittest'
        db_name = '%s.db' % project_name
        self.db_path = os.path.join(projects_folder, db_name)
        self.tearDown()
        self.lib = SoundSpeedLibrary()
        self.lib.projects_folder = projects_folder
        self.lib.current_project = project_name
        self.lib.ssp = ProfileList()
        self.lib.ssp.append()
        if len(self.lib.db_list_profiles()) < self.max_pk:
            for i in range(self.max_pk):
                add_cast(20 + i, -75)
예제 #3
0
 def test_creation_of_Gomofs(self):
     prj = SoundSpeedLibrary(data_folder=self.cur_dir)
     gomofs = RegOfsOnline(data_folder=prj.regofs_folder,
                           prj=prj,
                           model=RegOfsOnline.Model.GoMOFS)
     self.assertTrue('regofs' in gomofs.data_folder)
     self.assertFalse(gomofs.is_present())
     prj.close()
예제 #4
0
    def test_creation_of_Atlases(self):
        lib = SoundSpeedLibrary(data_folder=self.cur_dir)
        atl = atlases.Atlases(prj=lib)

        self.assertTrue("atlases" in atl.rtofs_folder)
        self.assertTrue("woa" in atl.woa09_folder)
        self.assertTrue("woa" in atl.woa13_folder)

        lib.close()
    def test_available_projects(self):

        lib = SoundSpeedLibrary()
        ssp_list = lib.db_list_profiles()
        self.assertGreaterEqual(len(ssp_list), 0)

        prj_list = lib.list_projects()
        self.assertGreaterEqual(len(prj_list), 1)

        lib.close()
예제 #6
0
    def test_download_db_from_Rtofs(self):
        prj = SoundSpeedLibrary(data_folder=self.cur_dir)
        rtofs = Rtofs(data_folder=prj.data_folder, prj=prj)
        rtofs.download_db(server_mode=True)

        # to avoid test failures
        if not rtofs.is_present():
            logger.warning("unable to download RTOFS data")
        # self.assertTrue(rtofs.is_present())

        prj.close()
예제 #7
0
def gui():
    """Run the Sound Speed Settings gui"""

    app = QtWidgets.QApplication(sys.argv)
    app.setStyleSheet(AppStyle.load_stylesheet())

    lib = SoundSpeedLibrary()
    main = MainWin(lib=lib)
    main.show()

    sys.exit(app.exec_())
예제 #8
0
def gui():
    """Run the Sound Speed Settings gui"""
    from hyo2.soundspeedsettings.mainwin import MainWin
    from hyo2.soundspeed.soundspeed import SoundSpeedLibrary

    app = QtWidgets.QApplication(sys.argv)
    app.setStyleSheet(AppStyle.load_stylesheet())

    lib = SoundSpeedLibrary()
    main = MainWin(lib=lib)
    main.show()

    sys.exit(app.exec_())
예제 #9
0
    def test_download_db_from_Gomofs(self):
        prj = SoundSpeedLibrary(data_folder=self.cur_dir)
        gomofs = RegOfsOnline(data_folder=prj.regofs_folder,
                              prj=prj,
                              model=RegOfsOnline.Model.GoMOFS)
        gomofs.download_db(server_mode=True)

        # to avoid test failures
        if not gomofs.is_present():
            logger.warning("unable to download GoMOFS data")
        # self.assertTrue(rtofs.is_present())

        prj.close()
    def test_new_projects(self):

        lib = SoundSpeedLibrary()
        ssp_list = lib.db_list_profiles()
        self.assertGreaterEqual(len(ssp_list), 0)

        lib.current_project = "zzz"
        ssp_list = lib.db_list_profiles()
        self.assertGreaterEqual(len(ssp_list), 0)

        prj_list = lib.list_projects()
        self.assertGreaterEqual(len(prj_list), 2)

        lib.current_project = "aaa"
        lib.remove_project("zzz")
        prj_list = lib.list_projects()
        self.assertGreaterEqual(len(prj_list), 1)

        lib.close()
예제 #11
0
    def _run(self, filters):
        # create a project with test-callbacks
        lib = SoundSpeedLibrary(callbacks=TestCallbacks())

        # set the current project name
        lib.setup.current_project = 'test_read_store_and_write'

        tests = self.testing.input_dict_test_files(inclusive_filters=filters)
        data_outputs = dict()
        for format in self.output_formats:
            data_outputs[format] = self.data_output

        for idx, testfile in enumerate(tests.keys()):

            if reduced_testing and (os.path.basename(testfile)[0] != "_"):
                continue
            logger.info("test: * New profile: #%03d * -> %s" % (idx, os.path.basename(testfile)))

            lib.import_data(data_path=testfile, data_format=tests[testfile].name)

            lib.store_data()

            lib.export_data(data_paths=data_outputs, data_formats=self.output_formats)
예제 #12
0
 def test_creation_of_Rtofs(self):
     prj = SoundSpeedLibrary(data_folder=self.cur_dir)
     rtofs = Rtofs(data_folder=prj.rtofs_folder, prj=prj)
     self.assertTrue('rtofs' in rtofs.data_folder)
     self.assertFalse(rtofs.is_present())
     prj.close()
from hyo2.soundspeedmanager import AppInfo
from hyo2.soundspeed.soundspeed import SoundSpeedLibrary
from hyo2.soundspeed.base.testing import SoundSpeedTesting
from hyo2.soundspeed.base.callbacks.fake_callbacks import FakeCallbacks
from hyo2.abc.lib.logging import set_logging

ns_list = [
    "hyo2.soundspeed", "hyo2.soundspeedmanager", "hyo2.soundspeedsettings"
]
set_logging(ns_list=ns_list)

logger = logging.getLogger(__name__)

# create a project with test-callbacks
lib = SoundSpeedLibrary(callbacks=FakeCallbacks())

# set the current project name
lib.setup.current_project = 'test'

data_folder = os.path.abspath(
    os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
testing = SoundSpeedTesting(root_folder=data_folder)

# retrieve data input/output folders
data_input = testing.input_data_folder()
logger.info('input folder: %s' % data_input)
data_output = testing.output_data_folder()
logger.info('output folder: %s' % data_output)

# test readers/writers
예제 #14
0
 def test_creation_of_Gomofs(self):
     prj = SoundSpeedLibrary(data_folder=self.cur_dir)
     gomofs = Gomofs(data_folder=prj.gomofs_folder, prj=prj)
     self.assertTrue('gomofs' in gomofs.data_folder)
     self.assertFalse(gomofs.is_present())
     prj.close()
set_logging(ns_list=ns_list)

logger = logging.getLogger(__name__)

# examples of test position:
# - offshore Portsmouth: 43.026480, -70.318824
# - Indian Ocean: -19.1, 74.16
# - middle of Africa (in land): 18.2648113, 16.1761115

switch = "LEOFS"  # WOA09 or WOA13 or RTOFS or GoMOFS or LEOFS or LHOFS

app = QtWidgets.QApplication([])  # PySide stuff (start)
mw = QtWidgets.QMainWindow()
mw.show()

lib = SoundSpeedLibrary(progress=QtProgress(parent=mw),
                        callbacks=QtCallbacks(parent=mw))

if switch == "WOA09":

    # download the WOA09 if not present
    if not lib.has_woa09():
        success = lib.download_woa09()
        if not success:
            raise RuntimeError("unable to download")
    logger.info("has WOA09: %s" % lib.has_woa09())

    # ask user for location and timestamp
    lib.retrieve_woa09()
    logger.info("retrieved WOA09 profiles: %s" % lib.ssp)

elif switch == "WOA13":
예제 #16
0
import time
import logging

from hyo2.soundspeedmanager import app_info
from hyo2.soundspeed.soundspeed import SoundSpeedLibrary
from hyo2.soundspeed.server.server import Server
from hyo2.abc.lib.logging import set_logging

ns_list = [
    "hyo2.soundspeed", "hyo2.soundspeedmanager", "hyo2.soundspeedsettings"
]
set_logging(ns_list=ns_list)

logger = logging.getLogger(__name__)

lib = SoundSpeedLibrary()
lib.listen_sis()
time.sleep(3)  # for SIS emulator

server = Server(prj=lib)

success = server.check_settings()
if not success:
    exit("Issue while checking the settings")
logger.debug("Settings successfully checked")

server.start()
time.sleep(20)

server.force_send = True
time.sleep(10)
예제 #17
0
import os
import logging

from hyo2.soundspeedmanager import app_info
from hyo2.soundspeed.soundspeed import SoundSpeedLibrary
from hyo2.soundspeed.base.testing import SoundSpeedTesting
from hyo2.soundspeed.base.callbacks.test_callbacks import TestCallbacks

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

# create a project with test-callbacks
lib = SoundSpeedLibrary(callbacks=TestCallbacks())

# set the current project name
lib.setup.current_project = 'test'

data_folder = os.path.abspath(
    os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
testing = SoundSpeedTesting(root_folder=data_folder)

# retrieve data input/output folders
data_input = testing.input_data_folder()
logger.info('input folder: %s' % data_input)
data_output = testing.output_data_folder()
logger.info('output folder: %s' % data_output)

# test readers/writers
logger.info('test: *** START ***')
filters = [
    "valeport",
예제 #18
0
    def __init__(self):
        QtWidgets.QMainWindow.__init__(self)

        logger.info("* > APP: initializing ...")

        # set the application name and the version
        self.name = app_info.app_name
        self.version = app_info.app_version
        self.setWindowTitle('%s v.%s' % (self.name, self.version))
        # noinspection PyArgumentList
        _app = QtCore.QCoreApplication.instance()
        _app.setApplicationName('%s' % self.name)
        _app.setOrganizationName("HydrOffice")
        _app.setOrganizationDomain("hydroffice.org")

        # set the minimum and the initial size
        self.setMinimumSize(640, 480)
        self.resize(920, 640)

        # set icons
        self.setWindowIcon(QtGui.QIcon(app_info.app_icon_path))

        # check if setup db exists; if yes, ask to copy
        has_setup = SoundSpeedLibrary.setup_exists()
        logger.info("setup exists: %s" % has_setup)
        if not has_setup:
            other_setups = SoundSpeedLibrary.list_other_setups()
            if len(other_setups) != 0:
                logger.debug("other existing setups: %d" % len(other_setups))
                # noinspection PyCallByClass
                sel, ok = QtWidgets.QInputDialog.getItem(self, 'Do you want to copy an existing setup?',
                                                         'Select one (or click on Cancel to create a new one):',
                                                         other_setups, 0, False)
                if ok:
                    SoundSpeedLibrary.copy_setup(input_setup=sel)

        # create the project
        self.lib = SoundSpeedLibrary(callbacks=QtCallbacks(parent=self), progress=QtProgress(parent=self))
        logger.info("current configuration:\n%s" % Helper(lib_info=lib_info).package_info())
        self.check_woa09()
        self.check_woa13()
        # self.check_rtofs()  # no need to wait for the download at the beginning
        self.check_sis4()
        self.check_sis5()
        self.check_sippican()
        self.check_mvp()

        # init default settings
        settings = QtCore.QSettings()
        export_folder = settings.value("export_folder")
        if (export_folder is None) or (not os.path.exists(export_folder)):
            settings.setValue("export_folder", self.lib.data_folder)
        import_folder = settings.value("import_folder")
        if (import_folder is None) or (not os.path.exists(import_folder)):
            settings.setValue("import_folder", self.lib.data_folder)

        # menu

        self.menu = self.menuBar()
        self.file_menu = self.menu.addMenu("File")
        self.edit_menu = self.menu.addMenu("Process")
        self.database_menu = self.menu.addMenu("Database")
        self.monitor_menu = self.menu.addMenu("Monitor")
        self.server_menu = self.menu.addMenu("Server")
        self.setup_menu = self.menu.addMenu("Setup")
        self.help_menu = self.menu.addMenu("Help")

        # make tabs
        self.tabs = QtWidgets.QTabWidget()
        self.setCentralWidget(self.tabs)
        self.tabs.setIconSize(QtCore.QSize(42, 42))
        self.tabs.blockSignals(True)  # during the initialization
        # noinspection PyUnresolvedReferences
        self.tabs.currentChanged.connect(self.on_change)  # changed!
        # editor
        self.tab_editor = Editor(lib=self.lib, main_win=self)
        self.idx_editor = self.tabs.insertTab(0, self.tab_editor,
                                              QtGui.QIcon(os.path.join(app_info.app_media_path, 'editor.png')), "")
        self.tabs.setTabToolTip(self.idx_editor, "Editor")
        # database
        self.tab_database = Database(lib=self.lib, main_win=self)
        self.idx_database = self.tabs.insertTab(1, self.tab_database,
                                                QtGui.QIcon(os.path.join(app_info.app_media_path, 'database.png')), "")
        self.tabs.setTabToolTip(self.idx_database, "Database")
        # survey data monitor
        self.has_sdm_support = True
        try:  # try.. except to make SSM working also without SDM
            # noinspection PyUnresolvedReferences
            from hyo2.surveydatamonitor.app.widgets.monitor import SurveyDataMonitor
            self.tab_monitor = SurveyDataMonitor(lib=self.lib, main_win=self)
            self.idx_monitor = self.tabs.insertTab(3, self.tab_monitor,
                                                   QtGui.QIcon(
                                                       os.path.join(app_info.app_media_path, 'surveydatamonitor.png')),
                                                   "")
            self.tabs.setTabToolTip(self.idx_monitor, "Survey Data Monitor")
            logger.info("Support for Survey Monitor: ON")
        except Exception as e:
            traceback.print_exc()
            self.has_sdm_support = False
            logger.info("Support for Survey Monitor: OFF(%s)" % e)
        # server
        self.tab_server = Server(lib=self.lib, main_win=self)
        self.idx_server = self.tabs.insertTab(4, self.tab_server,
                                              QtGui.QIcon(os.path.join(app_info.app_media_path, 'server.png')), "")
        self.tabs.setTabToolTip(self.idx_server, "Synthetic Profile Server")

        # refraction
        # self.tab_refraction = Refraction(lib=self.lib, main_win=self)
        # idx = self.tabs.insertTab(5, self.tab_refraction,
        #                           QtGui.QIcon(os.path.join(app_info.app_media_path, 'refraction.png')), "")
        # self.tabs.setTabToolTip(idx, "Refraction Monitor")
        # setup
        self.tab_setup = Settings(lib=self.lib, main_win=self)
        self.idx_setup = self.tabs.insertTab(6, self.tab_setup,
                                             QtGui.QIcon(os.path.join(app_info.app_media_path, 'settings.png')), "")
        self.tabs.setTabToolTip(self.idx_setup, "Setup")
        # info
        self.tab_info = InfoTab(main_win=self, lib_info=lib_info, app_info=app_info,
                                with_online_manual=True,
                                with_offline_manual=True,
                                with_bug_report=True,
                                with_hydroffice_link=True,
                                with_ccom_link=True,
                                with_noaa_link=True,
                                with_unh_link=True,
                                with_license=True)
        self.idx_info = self.tabs.insertTab(6, self.tab_info,
                                            QtGui.QIcon(os.path.join(app_info.app_media_path, 'info.png')), "")
        self.tabs.setTabToolTip(self.idx_info, "Info")
        # Help menu
        self.help_menu.addAction(self.tab_info.open_online_manual_action)
        self.help_menu.addAction(self.tab_info.open_offline_manual_action)
        self.help_menu.addAction(self.tab_info.fill_bug_report_action)
        self.help_menu.addAction(self.tab_info.authors_action)
        self.help_menu.addAction(self.tab_info.show_about_action)

        self.statusBar().setStyleSheet("QStatusBar{color:rgba(0,0,0,128);font-size: 8pt;}")
        self.status_bar_normal_style = self.statusBar().styleSheet()
        self.statusBar().showMessage("%s" % app_info.app_name, 2000)
        self.releaseInfo = QtWidgets.QLabel()
        self.statusBar().addPermanentWidget(self.releaseInfo)
        self.releaseInfo.setStyleSheet("QLabel{color:rgba(0,0,0,128);font-size: 8pt;}")
        timer = QtCore.QTimer(self)
        # noinspection PyUnresolvedReferences
        timer.timeout.connect(self.update_gui)
        timer.start(1500)
        self.timer_execs = 0

        self.data_cleared()
        self.tabs.blockSignals(False)

        logger.info("* > APP: initialized!")
예제 #19
0
 def test_init(self):
     prj = SoundSpeedLibrary(data_folder=self.cur_dir)
     _ = RegOfsOffline(data_folder=prj.regofs_folder, prj=prj)
     prj.close()