Exemplo n.º 1
0
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 ***')
Exemplo n.º 2
0
def main():
    # create a project with test-callbacks
    lib = SoundSpeedLibrary(callbacks=TestCallbacks())

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

    # 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 = [
        "aml",
    ]
    tests = testing.input_dict_test_files(inclusive_filters=filters)
    # print(tests)

    # import each identified file
    for idx, testfile in enumerate(tests.keys()):

        logger.debug("filename: %s" % testfile)

        if idx > 4:  # FILE FILTER
            break

        logger.info("test: * New profile: #%03d *" % idx)

        # import
        lib.import_data(data_path=testfile, data_format=tests[testfile].name)
        # print(lib.cur)
        lib.plot_ssp(more=True, show=False)

        # store the current profile
        success = lib.store_data()
        logger.info("stored: %s" % success)

    from matplotlib import pyplot as plt
    plt.show()

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

    # retrieve a specific profile and delete it
    ssp_pk = lst[0][0]
    ssp = lib.db_retrieve_profile(pk=ssp_pk)
    logger.info("Retrieved profile:\n%s" % ssp)
    ret = lib.delete_db_profile(pk=ssp_pk)
    logger.info("Deleted profile: %s" % ret)

    logger.info('test: *** END ***')
Exemplo n.º 3
0
    def test_available_projects(self):
        from hyo.soundspeed.soundspeed import SoundSpeedLibrary

        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()
Exemplo n.º 4
0
    def test_new_projects(self):
        from hyo.soundspeed.soundspeed import SoundSpeedLibrary

        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()
Exemplo n.º 5
0
class TestSoundSpeedDb(unittest.TestCase):
    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)

    def tearDown(self):
        if os.path.exists(self.db_path):
            os.remove(self.db_path)

    @unittest.skipUnless(sys.platform.startswith("win"),
                         "only works with GDAL < 2.0 on Windows")
    def test_save_load_cast(self):
        def test_pk(pk):
            self.lib.ssp = self.lib.db_retrieve_profile(pk)
            self.lib.store_data()
            self.lib.ssp = self.lib.db_retrieve_profile(pk)
            sum_ = len(self.lib.ssp.cur.proc.speed) + len(
                self.lib.ssp.cur.proc.depth)
            sum_ += len(self.lib.ssp.cur.data.speed) + len(
                self.lib.ssp.cur.data.depth)
            self.assertEqual(sum_, self.levels * 4)
            self.assertTrue((self.lib.ssp.cur.data.depth == self.depth).all())
            self.assertTrue((self.lib.ssp.cur.proc.depth == self.depth).all())

        for i in range(self.levels):
            # pk = random.randint(1, self.max_pk)
            pk = i % self.max_pk + 1
            test_pk(pk)
Exemplo n.º 6
0
def main():
    # initialize the library
    lib = SoundSpeedLibrary()

    prj_list = lib.list_projects()
    print("projects: %s" % len(prj_list))
    for prj in prj_list:
        print('- %s' % prj)

    lib.current_project = "test2"

    ssp_list = lib.db_list_profiles()
    print('profiles in db: %d' % len(ssp_list))

    lib.close()
Exemplo n.º 7
0
def main():
    # initialize the library
    lib = SoundSpeedLibrary()

    # print(lib)

    # # exploring folders
    # lib.open_data_folder()
    # lib.open_release_folder()
    # lib.open_projects_folder()
    # lib.open_atlases_folder()

    ssp_list = lib.db_list_profiles()
    print('profiles in db: %d' % len(ssp_list))

    print('setup version: %s' % lib.setup.setup_version)

    lib.close()