示例#1
0
    def _tracklist_export(self, fmt='csv'):
        """ Helper function to be re-used for different output formats """
        bag_file = self._ask_bag_input()
        fmt_name = self._tracklist_formats[fmt][1]
        fmt_ext = self._tracklist_formats[fmt][0]
        out_file = self._ask_file_output(fmt_name=fmt_name, fmt_ext=fmt_ext)

        try:
            bag = BAGFile(bag_file)
            bag_tkl = bag.tracking_list()
            if bag_tkl.size == 0:
                dlg = wx.MessageDialog(
                    parent=None,
                    message="Nothing to export! The Tracking List is empty.",
                    caption="Information",
                    style=wx.OK | wx.ICON_INFORMATION)
                dlg.ShowModal()
                dlg.Destroy()
                return

            bag_tkl_fields = bag.tracking_list_fields()
            TrackList2Csv(track_list=bag_tkl,
                          header=bag_tkl_fields,
                          csv_file=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)
示例#2
0
    def _tracklist_export(self, fmt='csv'):
        """ Helper function to be re-used for different output formats """
        bag_file = self._ask_bag_input()
        fmt_name = self._tracklist_formats[fmt][1]
        fmt_ext = self._tracklist_formats[fmt][0]
        out_file = self._ask_file_output(fmt_name=fmt_name, fmt_ext=fmt_ext)

        try:
            bag = BAGFile(bag_file)
            bag_tkl = bag.tracking_list()
            if bag_tkl.size == 0:
                dlg = wx.MessageDialog(parent=None, message="Nothing to export! The Tracking List is empty.",
                                       caption="Information", style=wx.OK | wx.ICON_INFORMATION)
                dlg.ShowModal()
                dlg.Destroy()
                return

            bag_tkl_fields = bag.tracking_list_fields()
            TrackList2Csv(track_list=bag_tkl, header=bag_tkl_fields, csv_file=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 main():
    logger = logging.getLogger()
    logger.setLevel(logging.NOTSET)


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

    app_name = "bag_validate"
    app_info = "Validation of 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 to validate")
    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 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)
    print(bf.validation_info())
示例#4
0
    def _uncertainty_export(self, fmt='geotiff'):
        """ Helper function to be re-used for different output formats """
        bag_file = self._ask_bag_input()
        fmt_name = self._uncertainty_formats[fmt][1]
        fmt_ext = self._uncertainty_formats[fmt][0]
        out_file = self._ask_file_output(fmt_name=fmt_name, fmt_ext=fmt_ext)

        try:
            bag = BAGFile(bag_file)
            bag_meta = bag.populate_metadata()
            bag_unc = bag.uncertainty(mask_nan=False)
            Uncertainty2Gdal(bag_uncertainty=bag_unc,
                             bag_meta=bag_meta,
                             fmt=fmt,
                             out_file=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)
示例#5
0
 def on_meta_validate(self, evt):
     """ Validate the metadata as XML """
     from .text_ctrl import TextViewerFrame
     bag_file = self._ask_bag_input()
     bag = BAGFile(bag_file)
     val_info = bag.validation_info()
     txt_frame = TextViewerFrame(data=val_info)
     txt_frame.Show()
示例#6
0
 def on_meta_validate(self, evt):
     """ Validate the metadata as XML """
     from .text_ctrl import TextViewerFrame
     bag_file = self._ask_bag_input()
     bag = BAGFile(bag_file)
     val_info = bag.validation_info()
     txt_frame = TextViewerFrame(data=val_info)
     txt_frame.Show()
示例#7
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")
示例#8
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)
示例#9
0
def main():
    logger = logging.getLogger()
    logger.setLevel(logging.NOTSET)

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

    app_name = "bag_validate"
    app_info = "Validation of 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 to validate")
    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 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)
    print(bf.validation_info())
示例#10
0
    def _bbox_export(self, fmt='kml'):
        """ Helper function to be re-used for different output formats """
        bag_file = self._ask_bag_input()
        fmt_name = self.bbox_formats[fmt][1]
        fmt_ext = self.bbox_formats[fmt][0]
        out_file = self._ask_file_output(fmt_name=fmt_name, fmt_ext=fmt_ext)

        try:
            bag = BAGFile(bag_file)
            bag_meta = bag.populate_metadata()
            Bbox2Gdal(bag_meta, fmt=fmt, title=os.path.basename(bag_file), out_file=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)
示例#11
0
    def _uncertainty_export(self, fmt='geotiff'):
        """ Helper function to be re-used for different output formats """
        bag_file = self._ask_bag_input()
        fmt_name = self._uncertainty_formats[fmt][1]
        fmt_ext = self._uncertainty_formats[fmt][0]
        out_file = self._ask_file_output(fmt_name=fmt_name, fmt_ext=fmt_ext)

        try:
            bag = BAGFile(bag_file)
            bag_meta = bag.populate_metadata()
            bag_unc = bag.uncertainty(mask_nan=False)
            Uncertainty2Gdal(bag_uncertainty=bag_unc, bag_meta=bag_meta, fmt=fmt, out_file=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)
示例#12
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)
示例#13
0
    def _bbox_export(self, fmt='kml'):
        """ Helper function to be re-used for different output formats """
        bag_file = self._ask_bag_input()
        fmt_name = self.bbox_formats[fmt][1]
        fmt_ext = self.bbox_formats[fmt][0]
        out_file = self._ask_file_output(fmt_name=fmt_name, fmt_ext=fmt_ext)

        try:
            bag = BAGFile(bag_file)
            bag_meta = bag.populate_metadata()
            Bbox2Gdal(bag_meta,
                      fmt=fmt,
                      title=os.path.basename(bag_file),
                      out_file=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)
    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

bag_file = os.path.join(Helper.samples_folder(), "bdb_01.bag")
if os.path.exists(bag_file):
    print("- file_bag_0: %s" % bag_file)

bag = BAGFile(bag_file)

bag_meta = bag.populate_metadata()
print(bag_meta)

bag_elevation = bag.elevation(mask_nan=False)
print(type(bag.elevation()), bag.elevation().shape, bag.elevation().dtype)

from hyo.bag.elevation import Elevation2Gdal
Elevation2Gdal(bag_elevation=bag_elevation,
               bag_meta=bag_meta,
               fmt="ascii",
               epsg=4326)
Elevation2Gdal(bag_elevation=bag_elevation,
               bag_meta=bag_meta,
               fmt="geotiff",
示例#15
0
def main():
    logger = logging.getLogger()
    logger.setLevel(logging.NOTSET)


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

    app_name = "bag_tracklist"
    app_info = "Extraction the tracklist from an OpenNS BAG file, using hyo.bag r%s" % __version__

    formats = ['csv']

    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("-f", "--format", help="one of the available file format: " + ", ".join(formats),
                        choices=formats, default="csv", metavar='')
    parser.add_argument("-o", "--output", help="the output file", type=str)
    parser.add_argument("-hd", "--header", help="add an header", action="store_true")
    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.output:
            args.output = os.path.abspath(args.output)
            print("> output: %s" % args.output)
        else:
            args.output = None
            print("> output: [default]")

        print("> format: %s" % args.format)
        print("> header: %s" % args.header)

    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)
    tl = None
    try:
        tl = bf.tracking_list()
    except Exception as e:
        parser.exit(1, "ERROR: issue in tracking-list recovery: %s" % e)

    tlf = ""
    if args.header:
        try:
            tlf = bf.tracking_list_fields()
        except Exception as e:
            parser.exit(1, "ERROR: issue in tracking-list fields recovery: %s" % e)

    try:
        from hyo.bag.tracklist import TrackList2Csv
        TrackList2Csv(track_list=tl, csv_file=args.output, header=tlf)
    except Exception as e:
        parser.exit(1, "ERROR: issue in output creation: %s" % e)

    if args.verbose:
        print("> DONE")
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

bag_file = os.path.join(Helper.samples_folder(), "bdb_01.bag")
if os.path.exists(bag_file):
    print("- file_bag_0: %s" % bag_file)

bag = BAGFile(bag_file)

bag_meta = bag.populate_metadata()
print(bag_meta)

bag_elevation = bag.elevation(mask_nan=False)
print(type(bag.elevation()), bag.elevation().shape, bag.elevation().dtype)

from hyo.bag.elevation import Elevation2Gdal
Elevation2Gdal(bag_elevation=bag_elevation, bag_meta=bag_meta, fmt="ascii", epsg=4326)
Elevation2Gdal(bag_elevation=bag_elevation, bag_meta=bag_meta, fmt="geotiff", epsg=4326)
Elevation2Gdal(bag_elevation=bag_elevation, bag_meta=bag_meta, fmt="xyz", epsg=4326)


示例#17
0
from hyo.bag import BAGFile
from hyo.bag import BAGError
from hyo.bag.helper import Helper

# Example that use bag.BAGFile to:
# - open a BAG file
# - read the whole elevation and uncertainty layers
# - read a selected range of rows for the elevation and uncertainty layers

file_bag_0 = os.path.join(Helper.samples_folder(), "bdb_02.bag")
if os.path.exists(file_bag_0):
    logger.debug("- file_bag_0: %s" % file_bag_0)

# - open a file
bag_0 = BAGFile(file_bag_0)
logger.debug("\n%s\n" % bag_0)

# - get elevation shape
logger.info("elevation shape: %s" % (bag_0.elevation_shape(), ))
# - read the full elevation
full_elevation = bag_0.elevation(mask_nan=True)
logger.info("elevation array:\n  type: %s\n  shape: %s\n  dtype: %s" %
            (type(full_elevation), full_elevation.shape, full_elevation.dtype))
ax = plt.contourf(full_elevation)
plt.colorbar(ax)
plt.show()
# - read the first 10 rows of the elevation layers
selection_slice = slice(0, 10)
sliced_elevation = bag_0.elevation(mask_nan=True, row_range=selection_slice)
logger.info(
示例#18
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.tracklist import TrackList2Csv

bag_file = os.path.join(Helper.samples_folder(), "bdb_01.bag")
bag = BAGFile(bag_file)
tl = bag.tracking_list()
tl2csv = TrackList2Csv(tl)

bag_file = os.path.join(Helper.samples_folder(), "bdb_02.bag")
bag = BAGFile(bag_file)
tl = bag.tracking_list()
tl_fields = bag.tracking_list_fields()
tl_types = bag.tracking_list_types()
print(tl_fields)
print(tl_types)
print(tl)
tl2csv = TrackList2Csv(track_list=tl, header=tl_fields)
示例#19
0
def main():
    logger = logging.getLogger()
    logger.setLevel(logging.NOTSET)


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

    app_name = "bag_uncertainty"
    app_info = "Extraction of uncertainty layer from an OpenNS BAG file, using hyo.bag r%s" % __version__

    formats = ['ascii', 'geotiff', 'xyz']

    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("-f", "--format", help="one of the available file format: " + ", ".join(formats),
                        choices=formats, default="geotiff", metavar='')
    parser.add_argument("-o", "--output", help="the output 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.output:
            args.output = os.path.abspath(args.output)
            print("> output: %s" % args.output)
        else:
            args.output = None
            print("> output: [default]")

        print("> format: %s" % args.format)

    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)
    bag_meta = None
    try:
        bag_meta = bf.populate_metadata()
    except Exception as e:
        parser.exit(1, "ERROR: issue in metadata population: %s" % e)
    bag_uncertainty = None
    try:
        bag_uncertainty = bf.uncertainty(mask_nan=False)
    except Exception as e:
        parser.exit(1, "ERROR: issue in uncertainty population: %s" % e)

    try:
        from hyo.bag.uncertainty import Uncertainty2Gdal
        Uncertainty2Gdal(bag_uncertainty=bag_uncertainty, bag_meta=bag_meta, fmt=args.format, out_file=args.output)
    except Exception as e:
        parser.exit(1, "ERROR: issue in output creation: %s" % e)

    if args.verbose:
        print("> DONE")
示例#20
0
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:\Users\gmasetti\Desktop\cube.bag"
if os.path.exists(file_bag_0):
    print("- file_bag_0: %s" % file_bag_0)

bag_0 = BAGFile(file_bag_0)
ret = bag_0.validate_metadata()
print("valid: %s" % ret)

if not ret:
    for bag_error in bag_0.meta_errors:
        print(" - %s" % bag_error)
示例#21
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")
示例#22
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)
示例#23
0
    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

bag_file = os.path.join(Helper.samples_folder(), "bdb_01.bag")
if os.path.exists(bag_file):
    print("- file_bag_0: %s" % bag_file)

bag = BAGFile(bag_file)

bag_meta = bag.populate_metadata()
print(bag_meta)

print("has uncertainty? %s" % bag.has_uncertainty())
print("has product uncertainty? %s" % bag.has_product_uncertainty())

bag_uncertainty = bag.uncertainty(mask_nan=True)
print(type(bag.elevation(mask_nan=True)),
      bag.elevation(mask_nan=True).shape,
      bag.elevation(mask_nan=True).dtype)

from hyo.bag.uncertainty import Uncertainty2Gdal
Uncertainty2Gdal(bag_uncertainty, bag_meta, fmt="ascii")
Uncertainty2Gdal(bag_uncertainty, bag_meta, fmt="geotiff")
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

bag_file = os.path.join(Helper.samples_folder(), "bdb_01.bag")
if os.path.exists(bag_file):
    print("- file_bag_0: %s" % bag_file)

bag = BAGFile(bag_file)

bag_meta = bag.populate_metadata()
print(bag_meta)

bag_uncertainty = bag.uncertainty(mask_nan=True)
print(type(bag.elevation(mask_nan=True)), bag.elevation(mask_nan=True).shape, bag.elevation(mask_nan=True).dtype)

from hyo.bag.uncertainty import Uncertainty2Gdal
Uncertainty2Gdal(bag_uncertainty=bag_uncertainty, bag_meta=bag_meta, fmt="ascii", epsg=4326)
Uncertainty2Gdal(bag_uncertainty=bag_uncertainty, bag_meta=bag_meta, fmt="geotiff", epsg=4326)
Uncertainty2Gdal(bag_uncertainty=bag_uncertainty, bag_meta=bag_meta, fmt="xyz", epsg=4326)



示例#25
0
ch.setFormatter(ch_formatter)
logger.addHandler(ch)

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

file_bag_0 = os.path.join(Helper.samples_folder(), "bdb_01.bag")
if not os.path.exists(file_bag_0):
    raise RuntimeError("the file does not exist: %s" % file_bag_0)
print("- file_bag_0: %s" % file_bag_0)

file_bag_copy = os.path.join(os.path.dirname(__file__), "tmp_copy.bag")
bag_copy = copyfile(file_bag_0, file_bag_copy)

bag_0 = BAGFile(file_bag_copy)
print(bag_0)

print(type(bag_0.elevation(mask_nan=True)), bag_0.elevation(mask_nan=True).shape, bag_0.elevation(mask_nan=True).dtype)
ax = plt.contourf(bag_0.elevation(mask_nan=True))
plt.colorbar(ax)
plt.show()

wkt_prj_hor = """
    PROJCS["UTM Zone 19, Northern Hemisphere",
      GEOGCS["WGS 84",
        DATUM["WGS_1984",
          SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
            TOWGS84[0,0,0,0,0,0,0],
          AUTHORITY["EPSG","6326"]],
示例#26
0
import logging
from matplotlib import pyplot as plt

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.tracklist import TrackList2Csv

bag_file = os.path.join(Helper.samples_folder(), "bdb_01.bag")
bag = BAGFile(bag_file)
tl = bag.tracking_list()
tl2csv = TrackList2Csv(tl)

bag_file = os.path.join(Helper.samples_folder(), "bdb_02.bag")
bag = BAGFile(bag_file)
tl = bag.tracking_list()
tl_fields = bag.tracking_list_fields()
tl_types = bag.tracking_list_types()
print(tl_fields)
print(tl_types)
print(tl)
tl2csv = TrackList2Csv(track_list=tl, header=tl_fields)
示例#27
0
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

bag_file = os.path.join(Helper.samples_folder(), "bdb_01.bag")
if os.path.exists(bag_file):
    print("- file_bag_0: %s" % bag_file)

bag = BAGFile(bag_file)

bag_meta = bag.populate_metadata()
print(bag_meta)

print("has uncertainty? %s" % bag.has_uncertainty())
print("has product uncertainty? %s" % bag.has_product_uncertainty())

bag_uncertainty = bag.uncertainty(mask_nan=True)
print(type(bag.elevation(mask_nan=True)), bag.elevation(mask_nan=True).shape, bag.elevation(mask_nan=True).dtype)

from hyo.bag.uncertainty import Uncertainty2Gdal
Uncertainty2Gdal(bag_uncertainty, bag_meta, fmt="ascii")
Uncertainty2Gdal(bag_uncertainty, bag_meta, fmt="geotiff")
Uncertainty2Gdal(bag_uncertainty, bag_meta, fmt="xyz")
示例#28
0
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

bag_file = os.path.join(Helper.samples_folder(), "bdb_01.bag")
if os.path.exists(bag_file):
    print("- file_bag_0: %s" % bag_file)

bag = BAGFile(bag_file)

bag_meta = bag.populate_metadata()
print(bag_meta)

print("has density? %s" % bag.has_density())
if not bag.has_density():
    exit()

bag_density = bag.density(mask_nan=True)
print(type(bag.density(mask_nan=True)),
      bag.density(mask_nan=True).shape,
      bag.density(mask_nan=True).dtype)

print("min: %s" % np.nanmin(bag_density))
print("max: %s" % np.nanmax(bag_density))
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

file_bag_0 = os.path.join(Helper.samples_folder(), "bdb_01.bag")
# file_bag_0 = "D:\\test_data\\radar_bag\\Sample_Beaufort_2\\Sample_Beaufort_2.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)

output_xml = "fixed_metadata.xml"
if not os.path.exists(output_xml):
    raise RuntimeError("unable to find metadata file: %s" % output_xml)
bag_0.substitute_metadata(output_xml)
os.remove(output_xml)
示例#30
0
    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

file_bag_0 = os.path.join(Helper.samples_folder(), "bdb_01.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)

print(type(bag_0.elevation(mask_nan=True)),
      bag_0.elevation(mask_nan=True).shape,
      bag_0.elevation(mask_nan=True).dtype)
# ax =plt.contourf(bag_0.elevation(mask_nan=True))
# plt.colorbar(ax)
# plt.show()

bag_meta = bag_0.populate_metadata()
print(bag_meta)

from hyo.bag.bbox import Bbox2Gdal
Bbox2Gdal(bag_meta, fmt="gjs", title=os.path.basename(file_bag_0))
Bbox2Gdal(bag_meta, fmt="gml", title=os.path.basename(file_bag_0))
示例#31
0
    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

bag_file = os.path.join(Helper.samples_folder(), "bdb_01.bag")
if os.path.exists(bag_file):
    print("- file_bag_0: %s" % bag_file)

bag = BAGFile(bag_file)

bag_meta = bag.populate_metadata()
print(bag_meta)

bag_uncertainty = bag.uncertainty(mask_nan=True)
print(type(bag.elevation(mask_nan=True)),
      bag.elevation(mask_nan=True).shape,
      bag.elevation(mask_nan=True).dtype)

from hyo.bag.uncertainty import Uncertainty2Gdal

Uncertainty2Gdal(bag_uncertainty=bag_uncertainty,
                 bag_meta=bag_meta,
                 fmt="ascii",
                 epsg=4326)
示例#32
0
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

file_bag_0 = os.path.join(Helper.samples_folder(), "bdb_01.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)

print(type(bag_0.elevation(mask_nan=True)), bag_0.elevation(mask_nan=True).shape, bag_0.elevation(mask_nan=True).dtype)
# ax =plt.contourf(bag_0.elevation(mask_nan=True))
# plt.colorbar(ax)
# plt.show()

bag_meta = bag_0.populate_metadata()
print(bag_meta)

from hyo.bag.bbox import Bbox2Gdal
Bbox2Gdal(bag_meta, fmt="gjs", title=os.path.basename(file_bag_0))
Bbox2Gdal(bag_meta, fmt="gml", title=os.path.basename(file_bag_0))
Bbox2Gdal(bag_meta, fmt="kml", title=os.path.basename(file_bag_0))
Bbox2Gdal(bag_meta, fmt="shp", title=os.path.basename(file_bag_0))
示例#33
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:\Users\gmasetti\Desktop\cube.bag"
if os.path.exists(file_bag_0):
    print("- file_bag_0: %s" % file_bag_0)

bag_0 = BAGFile(file_bag_0)
ret = bag_0.validate_metadata()
print("valid: %s" % ret)

if not ret:
    for bag_error in bag_0.meta_errors:
        print(" - %s" % bag_error)
示例#34
0
def main():
    logger = logging.getLogger()
    logger.setLevel(logging.NOTSET)

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

    app_name = "bag_bbox"
    app_info = "Extraction of bounding box from an OpenNS BAG file, using hyo.bag r%s" % __version__

    formats = ['gjs', 'gml', 'kml', 'shp']

    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("-f",
                        "--format",
                        help="one of the available file format: " +
                        ", ".join(formats),
                        choices=formats,
                        default="kml",
                        metavar='')
    parser.add_argument("-o", "--output", help="the output 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.output:
            args.output = os.path.abspath(args.output)
            print("> output: %s" % args.output)
        else:
            args.output = None
            print("> output: [default]")

        print("> format: %s" % args.format)

    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:
        bag_meta = bf.populate_metadata()
    except Exception as e:
        parser.exit(1, "ERROR: issue in metadata population: %s" % e)

    try:
        from hyo.bag.bbox import Bbox2Gdal
        Bbox2Gdal(bag_meta,
                  fmt=args.format,
                  title=os.path.basename(args.bag_file),
                  out_file=args.output)
    except Exception as e:
        parser.exit(1, "ERROR: issue in output creation: %s" % e)

    if args.verbose:
        print("> DONE")
示例#35
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)