Пример #1
0
def main():
    logger = logging.getLogger()
    logger.setLevel(logging.NOTSET)


    import argparse
    from hyo.bag import BAGFile, is_bag, __version__

    app_name = "bag_metadata"
    app_info = "Extraction of XML metadata from an OpenNS BAG file, using hyo.bag r%s" % __version__

    parser = argparse.ArgumentParser(prog=app_name, description=app_info)
    parser.add_argument("bag_file", type=str, help="a valid BAG file from which to extract metadata")
    parser.add_argument("-x", "--xml_file", help="the output XML metadata file", type=str)
    parser.add_argument("-v", "--verbose", help="increase output verbosity", action="store_true")
    args = parser.parse_args()

    if args.verbose:
        print("> verbosity: ON")
        ch = logging.StreamHandler()
        ch.setLevel(logging.DEBUG)  # change to WARNING to reduce verbosity, DEBUG for high verbosity
        ch_formatter = logging.Formatter('%(levelname)-9s %(name)s.%(funcName)s:%(lineno)d > %(message)s')
        ch.setFormatter(ch_formatter)
        logger.addHandler(ch)

    if args.verbose:
        print("> input: %s" % args.bag_file)

        if args.xml_file:
            args.xml_file = os.path.abspath(args.xml_file)
            print("> output: %s" % args.xml_file)
        else:
            args.xml_file = os.path.abspath(BAGFile.default_metadata_file)
            print("> output: %s [default]" % args.xml_file)

    if not os.path.exists(args.bag_file):
        parser.exit(1, "ERROR: the input valid does not exist: %s" % args.bag_file)

    if not is_bag(args.bag_file):
        parser.exit(1, "ERROR: the input valid does not seem a BAG file: %s" % args.bag_file)

    bf = BAGFile(args.bag_file)
    try:
        bf.extract_metadata(args.xml_file)
    except Exception as e:
        parser.exit(1, "ERROR: %s" % e)

    if args.verbose:
        print("> DONE")
Пример #2
0
    def _metadata_export(self, fmt='xml'):
        """ Helper function to be re-used for different output formats """
        bag_file = self._ask_bag_input()
        fmt_name = self._metadata_formats[fmt][1]
        fmt_ext = self._metadata_formats[fmt][0]
        out_file = self._ask_file_output(fmt_name=fmt_name, fmt_ext=fmt_ext)

        try:
            bag = BAGFile(bag_file)
            bag.extract_metadata(name=out_file)
        except Exception as e:
            dlg = wx.MessageDialog(parent=None, message="%s" % e, caption="Error", style=wx.OK | wx.ICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
            return

        self._check_file_creation(out_file)
Пример #3
0
    def _metadata_export(self, fmt='xml'):
        """ Helper function to be re-used for different output formats """
        bag_file = self._ask_bag_input()
        fmt_name = self._metadata_formats[fmt][1]
        fmt_ext = self._metadata_formats[fmt][0]
        out_file = self._ask_file_output(fmt_name=fmt_name, fmt_ext=fmt_ext)

        try:
            bag = BAGFile(bag_file)
            bag.extract_metadata(name=out_file)
        except Exception as e:
            dlg = wx.MessageDialog(parent=None,
                                   message="%s" % e,
                                   caption="Error",
                                   style=wx.OK | wx.ICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
            return

        self._check_file_creation(out_file)
Пример #4
0
            (type(sliced_uncertainty), sliced_uncertainty.shape,
             sliced_uncertainty.dtype))
ax = plt.contourf(sliced_uncertainty)
plt.colorbar(ax)
plt.show()

# - tracking list
logger.debug("\ntracking list:\n  type: %s\n  shape: %s\n  dtype: %s" %
             (type(bag_0.tracking_list()), bag_0.tracking_list().shape,
              bag_0.tracking_list().dtype))

# - metadata
logger.debug("\nmetadata: %s %s\n" %
             (type(bag_0.metadata()), len(bag_0.metadata())))
file_bag_0_xml = os.path.join("bdb_00.bag.xml")
bag_0.extract_metadata(name=file_bag_0_xml)

bag_0.populate_metadata()
logger.debug("rows, cols: %d, %d" % (bag_0.meta.rows, bag_0.meta.cols))
logger.debug("res x, y: %f, %f" % (bag_0.meta.res_x, bag_0.meta.res_y))
logger.debug("corner SW, NE: %s, %s" % (bag_0.meta.sw, bag_0.meta.ne))
logger.debug("coord sys: %s" % bag_0.meta.wkt_srs)

logger.debug(bag_0)

file_bag_1 = os.path.join(Helper.samples_folder(), "bdb_01.bag")
if os.path.exists(file_bag_1):
    logger.debug("file_bag_1: %s" % file_bag_1)

file_bag_2 = os.path.abspath(os.path.join("test_00.bag"))
logger.debug("file_bag_2: %s" % file_bag_2)
Пример #5
0
import os
import logging

logger = logging.getLogger()
logger.setLevel(logging.NOTSET)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)  # change to WARNING to reduce verbosity, DEBUG for high verbosity
ch_formatter = logging.Formatter('%(levelname)-9s %(name)s.%(funcName)s:%(lineno)d > %(message)s')
ch.setFormatter(ch_formatter)
logger.addHandler(ch)

from hyo.bag import BAGFile
from hyo.bag import BAGError
from hyo.bag.helper import Helper
from hyo.bag.meta import Meta

# file_bag_0 = os.path.join(Helper.samples_folder(), "bdb_01.bag")
# file_bag_0 = os.path.join(os.path.dirname(__file__), "tmp_copy.bag")
file_bag_0 = R"C:\code\hyo\bagexplorer\bag_tools\H11709_1m_MLLW_5of24.bag"
if os.path.exists(file_bag_0):
    print("- file_bag_0: %s" % file_bag_0)

bag_0 = BAGFile(file_bag_0)
print(bag_0)

meta = Meta(bag_0.metadata())

output_xml = "original_metadata.xml"
bag_0.extract_metadata(output_xml)
os.remove(output_xml)
Пример #6
0
def main():
    logger = logging.getLogger()
    logger.setLevel(logging.NOTSET)

    import argparse
    from hyo.bag import BAGFile, is_bag, __version__

    app_name = "bag_metadata"
    app_info = "Extraction of XML metadata from an OpenNS BAG file, using hyo.bag r%s" % __version__

    parser = argparse.ArgumentParser(prog=app_name, description=app_info)
    parser.add_argument("bag_file",
                        type=str,
                        help="a valid BAG file from which to extract metadata")
    parser.add_argument("-x",
                        "--xml_file",
                        help="the output XML metadata file",
                        type=str)
    parser.add_argument("-v",
                        "--verbose",
                        help="increase output verbosity",
                        action="store_true")
    args = parser.parse_args()

    if args.verbose:
        print("> verbosity: ON")
        ch = logging.StreamHandler()
        ch.setLevel(
            logging.DEBUG
        )  # change to WARNING to reduce verbosity, DEBUG for high verbosity
        ch_formatter = logging.Formatter(
            '%(levelname)-9s %(name)s.%(funcName)s:%(lineno)d > %(message)s')
        ch.setFormatter(ch_formatter)
        logger.addHandler(ch)

    if args.verbose:
        print("> input: %s" % args.bag_file)

        if args.xml_file:
            args.xml_file = os.path.abspath(args.xml_file)
            print("> output: %s" % args.xml_file)
        else:
            args.xml_file = os.path.abspath(BAGFile.default_metadata_file)
            print("> output: %s [default]" % args.xml_file)

    if not os.path.exists(args.bag_file):
        parser.exit(
            1, "ERROR: the input valid does not exist: %s" % args.bag_file)

    if not is_bag(args.bag_file):
        parser.exit(
            1, "ERROR: the input valid does not seem a BAG file: %s" %
            args.bag_file)

    bf = BAGFile(args.bag_file)
    try:
        bf.extract_metadata(args.xml_file)
    except Exception as e:
        parser.exit(1, "ERROR: %s" % e)

    if args.verbose:
        print("> DONE")
Пример #7
0
logger = logging.getLogger()
logger.setLevel(logging.NOTSET)
ch = logging.StreamHandler()
ch.setLevel(
    logging.DEBUG
)  # change to WARNING to reduce verbosity, DEBUG for high verbosity
ch_formatter = logging.Formatter(
    '%(levelname)-9s %(name)s.%(funcName)s:%(lineno)d > %(message)s')
ch.setFormatter(ch_formatter)
logger.addHandler(ch)

from hyo.bag import BAGFile
from hyo.bag import BAGError
from hyo.bag.helper import Helper
from hyo.bag.meta import Meta

# file_bag_0 = os.path.join(Helper.samples_folder(), "bdb_01.bag")
# file_bag_0 = os.path.join(os.path.dirname(__file__), "tmp_copy.bag")
file_bag_0 = R"C:\code\hyo\bagexplorer\bag_tools\H11709_1m_MLLW_5of24.bag"
if os.path.exists(file_bag_0):
    print("- file_bag_0: %s" % file_bag_0)

bag_0 = BAGFile(file_bag_0)
print(bag_0)

meta = Meta(bag_0.metadata())

output_xml = "original_metadata.xml"
bag_0.extract_metadata(output_xml)
os.remove(output_xml)