Exemplo n.º 1
0
            % (type(full_uncertainty), full_uncertainty.shape, full_uncertainty.dtype))
ax = plt.contourf(full_uncertainty)
plt.colorbar(ax)
plt.show()
# - read the first 10 rows of the uncertainty layers
selection_slice = slice(10, 20)
sliced_uncertainty = bag_0.uncertainty(mask_nan=True, row_range=selection_slice)
logger.info("sliced uncertainty array:\n  type: %s\n  shape: %s\n  dtype: %s"
            % (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")
Exemplo n.º 2
0
from __future__ import absolute_import, division, print_function, unicode_literals

import os
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 hydroffice.bag import BAGFile
from hydroffice.bag import BAGError
from hydroffice.bag.helper import Helper
from hydroffice.bag.tracklist import TrackList2Csv

bag_file = os.path.join(Helper.samples_folder(), "bdb_00.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()
print(tl_fields)
tl2csv = TrackList2Csv(track_list=tl, header=tl_fields)
Exemplo n.º 3
0
def main():
    logger = logging.getLogger()
    logger.setLevel(logging.NOTSET)


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

    app_name = "bag_tracklist"
    app_info = "Extraction the tracklist from an OpenNS BAG file, using hydroffice.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 hydroffice.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")