Skip to content

Commit

Permalink
Merge branch 'Parse-sonar-model-from-.raw-for-EK60,-EK80' into parse-…
Browse files Browse the repository at this point in the history
…remaining-sonar-models-from-raws
  • Loading branch information
spacetimeengineer committed Nov 1, 2024
2 parents bf73faa + 8a2517d commit a8cd12b
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 10 deletions.
18 changes: 17 additions & 1 deletion docs/source/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,23 @@ One can replace `conda` with `mamba` in the above commands when creating the env

Currently, test data are stored in a private Google Drive folder and
made available via the [`cormorack/http`](https://hub.docker.com/r/cormorack/http)
Docker image on Docker hub.
Docker image on Docker hub. There’s no need to pull directly from Docker Hub, as the scripts below will handle that for you. For Linux Users: If you run into an issue where accessing the Docker daemon requires sudo privileges, which may not suit your environment, you can adjust your settings to allow non-root access to Docker:

```shell
sudo groupadd docker
```

Add the current user to the Docker group
```shell
sudo gpasswd -a $USER docker
```

Restart the docker daemon
```shell
sudo service docker restart
```

You might also need to restart your computer if the steps above don't resolve the issue.
The image is rebuilt daily when new test data are added.
If your tests require adding new test data, ping the maintainers (@leewujung, @ctuguinay)
to get them added to the the Google Drive.
Expand Down
4 changes: 2 additions & 2 deletions echopype/convert/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from .parse_azfp import ParseAZFP
from .parse_azfp6 import ParseAZFP6
from .parse_base import ParseBase
from .parse_ek60 import ParseEK60
from .parse_ek80 import ParseEK80
from .parse_ek60 import ParseEK60, is_EK60
from .parse_ek80 import ParseEK80, is_EK80
from .set_groups_ad2cp import SetGroupsAd2cp
from .set_groups_azfp import SetGroupsAZFP
from .set_groups_azfp6 import SetGroupsAZFP6
Expand Down
27 changes: 24 additions & 3 deletions echopype/convert/parse_ek60.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import numpy as np


from .parse_base import ParseEK
from .utils.ek_raw_io import RawSimradFile



class ParseEK60(ParseEK):
"""Class for converting data from Simrad EK60 echosounders."""

Expand All @@ -18,16 +21,34 @@ def __init__(
super().__init__(file, bot_file, idx_file, storage_options, sonar_model)



def is_ER60(raw_file, storage_options):
"""Check if a raw data file is from Simrad EK60 echosounder."""
with RawSimradFile(raw_file, "r", storage_options=storage_options) as fid:
config_datagram = fid.read(1)
config_datagram["timestamp"] = np.datetime64(
config_datagram["timestamp"].replace(tzinfo=None), "[ns]"
)

# Return True if the sounder name matches "ER60"
try:
# Return True if the sounder name matches "ER60" or "EK60"
return config_datagram["sounder_name"] in {"ER60"}
except KeyError:
return False
return False



def is_EK60(raw_file, storage_options):

"""Check if a raw data file is from Simrad EK60 echosounder."""
with RawSimradFile(raw_file, "r", storage_options=storage_options) as fid:
config_datagram = fid.read(1)
config_datagram["timestamp"] = np.datetime64(
config_datagram["timestamp"].replace(tzinfo=None), "[ns]"
)

try:
# Return True if the sounder name matches "EK60"
return config_datagram["sounder_name"] in {"EK60"}
except KeyError:
return False

15 changes: 15 additions & 0 deletions echopype/convert/parse_ek80.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import numpy as np

from .parse_base import ParseEK
from .utils.ek_raw_io import RawSimradFile


class ParseEK80(ParseEK):
Expand All @@ -15,3 +18,15 @@ def __init__(
):
super().__init__(file, bot_file, idx_file, storage_options, sonar_model)
self.environment = {} # dictionary to store environment data


def is_EK80(raw_file, storage_options):
"""Check if a raw data file is from Simrad EK80 echosounder."""
with RawSimradFile(raw_file, "r", storage_options=storage_options) as fid:
config_datagram = fid.read(1)
config_datagram["timestamp"] = np.datetime64(
config_datagram["timestamp"].replace(tzinfo=None), "[ns]"
)

# Return True if "configuration" exists in config_datagram
return "configuration" in config_datagram
32 changes: 30 additions & 2 deletions echopype/tests/convert/test_convert_ek60.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import warnings

import glob
import numpy as np
import pandas as pd
from scipy.io import loadmat
import pytest

from echopype import open_raw
from echopype.convert import ParseEK60
from echopype.convert import ParseEK60, is_EK60


@pytest.fixture
Expand Down Expand Up @@ -264,3 +264,31 @@ def test_converting_ek60_raw_with_missing_channel_power():
# Check that all empty power channels do not exist in the EchoData Beam group
for _, empty_power_channel_name in empty_power_chs.items():
assert empty_power_channel_name not in ed["Sonar/Beam_group1"]["channel"]


def test_is_EK60_ek60_files():
"""Check that EK60 files are identified as EK60"""
# Collect all .raw files in the ek60 directory
ek60_files = glob.glob("echopype/test_data/ek60/*.raw")

# Check that each file in ek60 is identified as EK60
for test_file_path in ek60_files:
assert is_EK60(test_file_path, storage_options={}) == True

Check failure on line 276 in echopype/tests/convert/test_convert_ek60.py

View workflow job for this annotation

GitHub Actions / 3.9--ubuntu-latest

test_is_EK60_ek60_files AssertionError: assert False == True + where False = is_EK60('echopype/test_data/ek60/EK60-Summer2018-D20180822-T174237.raw', storage_options={})

def test_is_EK60_er60_files():
"""Check that ER60 files are identified as EK60"""
# Collect all .raw files in the ek60 directory (assuming ER60 files are also here)
er60_files = glob.glob("echopype/test_data/ek60/*.raw")

# Check that each file in ek60 is identified as EK60
for test_file_path in er60_files:
assert is_EK60(test_file_path, storage_options={}) == True

Check failure on line 285 in echopype/tests/convert/test_convert_ek60.py

View workflow job for this annotation

GitHub Actions / 3.9--ubuntu-latest

test_is_EK60_er60_files AssertionError: assert False == True + where False = is_EK60('echopype/test_data/ek60/EK60-Summer2018-D20180822-T174237.raw', storage_options={})

def test_is_EK60_non_ek60_files():
"""Check that non-EK60 files are not identified as EK60"""
# Collect all .raw files in the ek80 directory (non-EK60 files)
ek80_files = glob.glob("echopype/test_data/ek80/*.raw")

# Check that each file in ek80 is not identified as EK60
for test_file_path in ek80_files:
assert is_EK60(test_file_path, storage_options={}) == False
22 changes: 20 additions & 2 deletions echopype/tests/convert/test_convert_ek80.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import shutil

import glob
import pytest
import numpy as np
import pandas as pd
from scipy.io import loadmat

from echopype import open_raw, open_converted
from echopype.testing import TEST_DATA_FOLDER
from echopype.convert.parse_ek80 import ParseEK80
from echopype.convert.parse_ek80 import ParseEK80, is_EK80
from echopype.convert.set_groups_ek80 import WIDE_BAND_TRANS, PULSE_COMPRESS, FILTER_IMAG, FILTER_REAL, DECIMATION


Expand Down Expand Up @@ -531,3 +531,21 @@ def test_parse_ek80_with_invalid_env_datagrams():
env_var = ed["Environment"][var]
assert env_var.notnull().all() and env_var.dtype == np.float64


def test_is_EK80_ek80_files():
"""Test that EK80 files are identified as EK80."""
# Collect all .raw files in the ek80 directory
ek80_files = glob.glob("echopype/test_data/ek80/*.raw")

# Check that each file in ek80 is identified as EK80
for test_file_path in ek80_files:
assert is_EK80(test_file_path, storage_options={}) == True

def test_is_EK80_non_ek80_files():
"""Test that non-EK80 files are not identified as EK80."""
# Collect all .raw files in the ek60 directory (non-EK80 files)
ek60_files = glob.glob("echopype/test_data/ek60/*.raw")

# Check that each file in ek60 is not identified as EK80
for test_file_path in ek60_files:
assert is_EK80(test_file_path, storage_options={}) == False

0 comments on commit a8cd12b

Please sign in to comment.