def test_repr_html(self, converted_zarr):
        zarr_path_string = str(converted_zarr.absolute())
        ed = EchoData(converted_raw_path=converted_zarr)
        assert hasattr(ed, "_repr_html_")
        html_repr = ed._repr_html_().strip()
        assert (
            f"""<div class="xr-obj-type">EchoData: standardized raw data from {zarr_path_string}</div>"""
            in html_repr
        )

        with xr.set_options(display_style="text"):
            html_fallback = ed._repr_html_().strip()

        assert html_fallback.startswith(
            "<pre>EchoData"
        ) and html_fallback.endswith("</pre>")
Example #2
0
    def test_setitem(self, converted_zarr):
        ed = EchoData.from_file(converted_raw_path=converted_zarr)
        ed['Sonar/Beam_group1'] = ed['Sonar/Beam_group1'].rename(
            {'beam': 'beam_newname'})

        assert sorted(ed['Sonar/Beam_group1'].dims.keys()) == [
            'beam_newname', 'channel', 'ping_time', 'range_sample'
        ]
Example #3
0
    def test_get_dataset(self, converted_zarr):
        ed = EchoData.from_file(converted_raw_path=converted_zarr)
        node = DataTree()
        result = ed._EchoData__get_dataset(node)

        ed_node = ed._tree['Sonar']
        ed_result = ed._EchoData__get_dataset(ed_node)

        assert result is None
        assert isinstance(ed_result, xr.Dataset)
Example #4
0
    def test_getitem(self, converted_zarr):
        ed = EchoData.from_file(converted_raw_path=converted_zarr)
        beam = ed['Sonar/Beam_group1']
        assert isinstance(beam, xr.Dataset)
        try:
            ed['MyGroup']
        except Exception as e:
            assert isinstance(e, GroupNotFoundError)

        ed._tree = None
        try:
            ed['Sonar']
        except Exception as e:
            assert isinstance(e, ValueError)
Example #5
0
 def test_getattr(self, converted_zarr):
     ed = EchoData.from_file(converted_raw_path=converted_zarr)
     expected_groups = {
         'top': 'Top-level',
         'environment': 'Environment',
         'platform': 'Platform',
         'nmea': 'Platform/NMEA',
         'provenance': 'Provenance',
         'sonar': 'Sonar',
         'beam': 'Sonar/Beam_group1',
         'vendor': 'Vendor_specific',
     }
     for group, path in expected_groups.items():
         ds = getattr(ed, group)
         assert ds.equals(ed[path])
Example #6
0
 def test_repr(self):
     zarr_path_string = str(self.converted_zarr.absolute())
     expected_repr = dedent(f"""\
         EchoData: standardized raw data from {zarr_path_string}
           > top: (Top-level) contains metadata about the SONAR-netCDF4 file format.
           > environment: (Environment) contains information relevant to acoustic propagation through water.
           > platform: (Platform) contains information about the platform on which the sonar is installed.
           > provenance: (Provenance) contains metadata about how the SONAR-netCDF4 version of the data were obtained.
           > sonar: (Sonar) contains specific metadata for the sonar system.
           > beam: (Beam) contains backscatter data and other beam or channel-specific data.
           > vendor: (Vendor specific) contains vendor-specific information about the sonar and the data."""
                            )
     ed = EchoData(converted_raw_path=self.converted_zarr)
     actual = "\n".join(x.rstrip() for x in repr(ed).split("\n"))
     assert expected_repr == actual
Example #7
0
    def test_setattr(self, converted_zarr):
        sample_data = xr.Dataset({"x": [0, 0, 0]})
        sample_data2 = xr.Dataset({"y": [0, 0, 0]})
        ed = EchoData.from_file(converted_raw_path=converted_zarr)
        current_ed_beam = ed.beam
        current_ed_top = ed.top
        ed.beam = sample_data
        ed.top = sample_data2

        assert ed.beam.equals(sample_data) is True
        assert ed.beam.equals(ed['Sonar/Beam_group1']) is True
        assert ed.beam.equals(current_ed_beam) is False

        assert ed.top.equals(sample_data2) is True
        assert ed.top.equals(ed['Top-level']) is True
        assert ed.top.equals(current_ed_top) is False
Example #8
0
 def test_repr(self, converted_zarr):
     zarr_path_string = str(converted_zarr.absolute())
     expected_repr = dedent(f"""\
         <EchoData: standardized raw data from {zarr_path_string}>
         Top-level: contains metadata about the SONAR-netCDF4 file format.
         ├── Environment: contains information relevant to acoustic propagation through water.
         ├── Platform: contains information about the platform on which the sonar is installed.
         │   └── NMEA: contains information specific to the NMEA protocol.
         ├── Provenance: contains metadata about how the SONAR-netCDF4 version of the data were obtained.
         ├── Sonar: contains sonar system metadata and sonar beam groups.
         │   └── Beam_group1: contains backscatter data (either complex samples or uncalibrated power samples) and other beam or channel-specific data, including split-beam angle data when they exist.
         └── Vendor_specific: contains vendor-specific information about the sonar and the data."""
                            )
     ed = EchoData.from_file(converted_raw_path=converted_zarr)
     actual = "\n".join(x.rstrip() for x in repr(ed).split("\n"))
     assert expected_repr == actual
Example #9
0
    def test_constructor(self, converted_zarr):
        ed = EchoData.from_file(converted_raw_path=converted_zarr)
        expected_groups = [
            'top',
            'environment',
            'platform',
            'provenance',
            'sonar',
            'beam',
            'vendor',
        ]

        assert ed.sonar_model == 'EK60'
        assert ed.converted_raw_path == converted_zarr
        assert ed.storage_options == {}
        for group in expected_groups:
            assert isinstance(getattr(ed, group), xr.Dataset)