Skip to content

Commit

Permalink
drop cioos-siooc-data-transform from odf parser
Browse files Browse the repository at this point in the history
  • Loading branch information
JessyBarrette committed Aug 31, 2023
1 parent 3e705c3 commit 5c8eb1b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 49 deletions.
34 changes: 0 additions & 34 deletions ocean_data_parser/parsers/dfo/odf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
"""

import logging
from typing import Union

import xarray
from odf_transform.process import odf_to_xarray
from odf_transform.process import read_config as cioos_odf_config

from ocean_data_parser.parsers.dfo.odf_source.process import parse_odf

Expand Down Expand Up @@ -60,37 +57,6 @@
}


def bio_odf_cioos(path: str, config: Union[dict, str]) -> xarray.Dataset:
"""Read BIO ODF with the CIOOS Data Transform package
Args:
path (str): file path to read.
config (Union[dict, str]): cioos-ioos-data-transform configurations
Returns:
xarray.Dataset: CIOOS Compliant Xarray object
"""

config = cioos_odf_config(config)
config["organisationVocabulary"] = ["BIO", "GF3"]
return odf_to_xarray(path, config)


def mli_odf_cioos(path: str, config: Union[dict, str]) -> xarray.Dataset:
"""Read MLI ODF with the CIOOS Data Transform package
Args:
path (str): file path to read.
config (Union[dict, str]): cioos-ioos-data-transform configurations
Returns:
xarray.Dataset: CIOOS Compliant Xarray object
"""
config = cioos_odf_config(config)
config["organisationVocabulary"] = ["MLI", "GF3"]
return odf_to_xarray(path, config)


def bio_odf(path: str, global_attributes: dict = None) -> xarray.Dataset:
"""Bedford Institute of Ocean ODF format parser
Expand Down
2 changes: 1 addition & 1 deletion ocean_data_parser/parsers/dfo/odf_source/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def _define_cdm_data_type_from_odf(odf_header: dict) -> dict:
attributes["cdm_data_type"] = "Point"
else:
logger.error(
"ODF_transform is not yet incompatible with ODF DATA_TYPE: %s",
"ODF parser is not yet incompatible with ODF DATA_TYPE: %s",
odf_data_type,
)
return attributes
Expand Down
37 changes: 24 additions & 13 deletions ocean_data_parser/parsers/dfo/odf_source/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import re
from pathlib import Path

import xarray as xr

import ocean_data_parser.parsers.seabird as seabird
from ocean_data_parser._version import __version__
from ocean_data_parser.parsers.dfo.odf_source import attributes, flags
Expand Down Expand Up @@ -38,26 +40,35 @@


def parse_odf(
odf_path,
global_attributes=None,
vocabularies=None,
add_attributes_existing_variables=True,
generate_new_vocabulary_variables=True,
):
odf_path: str,
global_attributes: dict = None,
vocabularies: list = None,
add_attributes_existing_variables: bool = True,
generate_new_vocabulary_variables: bool = True,
) -> xr.Dataset:
"""Convert an ODF file to an xarray object.
Args:
odf_path (str): path to ODF file to convert
config (dictionary, optional): Conversion configuration to apply.
Defaults to odf_transform/config.json.
odf_path (str): ODF file path
global_attributes (dict, optional): Global attribtes to append to dataaset.
Defaults to None.
vocabularies (list, optional): Vocabularies to use ['GF3','BIO','IML'].
Defaults to None.
add_attributes_existing_variables (bool, optional): Append vocabulary attributes.
Defaults to True.
generate_new_vocabulary_variables (bool, optional): Generate vocabulary variables.
Defaults to True.
Returns:
xr.Dataset: Parsed dataset
"""

# Parse the ODF file with the CIOOS python parsing tool
metadata, dataset = odf_parser.read(odf_path)

# Review ODF data type compatible with odf_transform
# Review ODF data type compatible with ODF parser
if metadata["EVENT_HEADER"]["DATA_TYPE"] not in ODF_COMPATIBLE_DATA_TYPES:
logger.warning(
"ODF_transform is not yet fully compatible with the ODF Data Type: %s",
"ODF parser is not yet fully compatible with the ODF Data Type: %s",
metadata["EVENT_HEADER"]["DATA_TYPE"],
)

Expand All @@ -76,7 +87,7 @@ def parse_odf(
dataset = attributes.global_attributes_from_header(dataset, metadata)
dataset.attrs[
"history"
] += f"# Convert ODF to NetCDF with cioos_data_trasform.odf_transform V {__version__}\n"
] += f"# Convert ODF to NetCDF with ocean_data_parser V {__version__}\n"

# Handle ODF flag variables
dataset = flags.rename_qqqq_flags(dataset)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_reference_netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def ignore_from_attr(attr, expression, placeholder):
ignore_from_attr(
"history",
r"cioos_data_trasform.odf_transform V \d+\.\d+.\d+",
"cioos_data_trasform.odf_transform V VERSION",
"package_name_version",
)
ignore_from_attr(
"history", r"\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.*\d*Z", "TIMESTAMP"
Expand Down

0 comments on commit 5c8eb1b

Please sign in to comment.