Example #1
0
def main():
    title = Colors.BOLD + 'GIPS Data Processing (v%s)' % __version__ + Colors.OFF

    # argument parsing
    parser0 = GIPSParser(description=title)
    parser0.add_inventory_parser()
    parser0.add_process_parser()
    args = parser0.parse_args()

    try:
        print title
        cls = import_data_class(args.command)

        extents = SpatialExtent.factory(cls, args.site, args.key, args.where,
                                        args.tiles, args.pcov, args.ptile)
        for extent in extents:
            inv = DataInventory(cls, extent,
                                TemporalExtent(args.dates, args.days),
                                **vars(args))
            inv.process(overwrite=args.overwrite)

    except Exception, e:
        import traceback
        VerboseOut(traceback.format_exc(), 4)
        print 'Data processing error: %s' % e
Example #2
0
 def inventory(cls, site=None, key='', where='', tiles=None, pcov=0.0,
               ptile=0.0, dates=None, days=None, **kwargs):
     """ Return list of inventories (size 1 if not looping through geometries) """
     from gips.inventory import DataInventory
     from gips.core import SpatialExtent, TemporalExtent
     spatial = SpatialExtent.factory(cls, site=site, key=key, where=where, tiles=tiles, pcov=pcov, ptile=ptile)
     temporal = TemporalExtent(dates, days)
     return DataInventory(cls, spatial[0], temporal, **kwargs)
Example #3
0
File: core.py Project: aniucd/gips
 def inventory(cls, site=None, key='', where='', tiles=None, pcov=0.0,
               ptile=0.0, dates=None, days=None, **kwargs):
     """ Return list of inventories (size 1 if not looping through geometries) """
     from gips.inventory import DataInventory
     from gips.core import SpatialExtent, TemporalExtent
     spatial = SpatialExtent.factory(cls, site=site, key=key, where=where, tiles=tiles, pcov=pcov, ptile=ptile)
     temporal = TemporalExtent(dates, days)
     return DataInventory(cls, spatial[0], temporal, **kwargs)
Example #4
0
def t_raster_spatialspec():
    """Test that shapefile and rastermask return the same tile list"""
    with utils.make_temp_dir(prefix='t_gridded_inventory') as td:
        rastermask = os.path.join(td, 'nhseacost_mask.tif')

        rasterize = ('gdal_rasterize -burn 1 -ot Byte -tr 30 30 {} {}'.format(
            NH_SHP_PATH, rastermask))
        status, output = commands.getstatusoutput(rasterize)
        assert status == 0

        cls = utils.import_data_class('modis')
        s_extents = SpatialExtent.factory(cls, site=NH_SHP_PATH)
        r_extents = SpatialExtent.factory(cls, rastermask=rastermask)

        assert len(s_extents) == len(r_extents)
        for i in range(len(r_extents)):
            assert s_extents[i].tiles == r_extents[i].tiles
Example #5
0
def main():
    title = Colors.BOLD + 'GIPS Data Inventory (v%s)' % gipsversion + Colors.OFF

    # argument parsing
    parser0 = GIPSParser(description=title)
    parser = parser0.add_inventory_parser()
    group = parser.add_argument_group('additional inventory options')
    group.add_argument('--md',
                       help='Show dates using MM-DD',
                       action='store_true',
                       default=False)
    group.add_argument(
        '--rectify',
        help=
        'Instead of displaying or fetching inventory, rectify the inventory '
        'database by comparing it against the present state of the data repos.',
        action='store_true',
        default=False)
    args = parser0.parse_args()

    cls = utils.gips_script_setup(args.command, args.stop_on_error)

    with utils.error_handler():
        print(title)

        if args.rectify:
            if not orm.use_orm():
                raise ValueError("--rectify can only be used if"
                                 " GIPS_ORM = True.")
            for k, v in vars(args).items():
                # Let the user know not to expect other options to effect rectify
                if v and k not in ('rectify', 'verbose', 'command'):
                    msg = "INFO: Option '--{}' is has no effect on --rectify."
                    utils.verbose_out(msg.format(k), 1)
            print("Rectifying inventory DB with filesystem archive:")
            print("Rectifying assets:")
            dbinv.rectify_assets(cls.Asset)
            print("Rectifying products:")
            dbinv.rectify_products(cls)
            return

        extents = SpatialExtent.factory(cls,
                                        site=args.site,
                                        rastermask=args.rastermask,
                                        key=args.key,
                                        where=args.where,
                                        tiles=args.tiles,
                                        pcov=args.pcov,
                                        ptile=args.ptile)
        for extent in extents:
            inv = DataInventory(cls, extent,
                                TemporalExtent(args.dates, args.days),
                                **vars(args))
            inv.pprint(md=args.md, size=args.size)

    utils.gips_exit(
    )  # produce a summary error report then quit with a proper exit status
Example #6
0
def main():
    title = Colors.BOLD + 'GIPS Data Processing (v%s)' % __version__ + Colors.OFF

    # argument parsing
    parser0 = GIPSParser(description=title)
    parser0.add_inventory_parser()
    parser0.add_process_parser()
    args = parser0.parse_args()

    try:
        print title
        cls = import_data_class(args.command)

        extents = SpatialExtent.factory(
            cls, args.site, args.key, args.where, args.tiles, args.pcov,
            args.ptile
        )
        batchargs = None
        if args.batchout:
            tdl = []
            batchargs = '--chunksize ' + str(args.chunksize)
            batchargs += ' --format ' + str(args.format)
            if args.overwrite:
                batchargs += ' --overwrite '
            if args.products:
                batchargs += ' -p ' + ' '.join(args.products)

        for extent in extents:
            inv = DataInventory(
                cls, extent,
                TemporalExtent(args.dates, args.days), **vars(args)
            )
            if args.batchout:
                tdl = reduce(
                    list.__add__,
                    map(
                        lambda tiles: [
                            args.command + ' -t ' + str(tile) +
                            ' -d ' + str(tiles.date) + ' ' +
                            batchargs + '\n'
                            for tile in tiles.tiles.keys()
                        ],
                        inv.data.values(),
                    ),
                    tdl
                )

            else:
                inv.process(overwrite=args.overwrite)
        if args.batchout:
            with open(args.batchout, 'w') as ofile:
                ofile.writelines(tdl)

    except Exception, e:
        import traceback
        VerboseOut(traceback.format_exc(), 4)
        print 'Data processing error: %s' % e
Example #7
0
def main():
    title = Colors.BOLD + 'GIPS Data Project (v%s)' % __version__ + Colors.OFF

    # argument parsing
    parser0 = GIPSParser(description=title)
    parser0.add_inventory_parser(site_required=True)
    parser0.add_process_parser()
    parser0.add_project_parser()
    parser0.add_warp_parser()
    args = parser0.parse_args()

    try:
        print title
        cls = import_data_class(args.command)

        extents = SpatialExtent.factory(cls, args.site, args.key, args.where,
                                        args.tiles, args.pcov, args.ptile)

        # create tld: SITENAME--KEY_DATATYPE_SUFFIX
        if args.notld:
            tld = args.outdir
        else:
            key = '' if args.key == '' else '--' + args.key
            suffix = '' if args.suffix == '' else '_' + args.suffix
            res = '' if args.res is None else '_%sx%s' % (args.res[0],
                                                          args.res[1])
            bname = (extents[0].site.LayerName() + key + res + '_' +
                     args.command + suffix)
            tld = os.path.join(args.outdir, bname)

        for extent in extents:
            t_extent = TemporalExtent(args.dates, args.days)
            inv = DataInventory(cls, extent, t_extent, **vars(args))
            datadir = os.path.join(tld, extent.site.Value())
            if inv.numfiles > 0:
                inv.mosaic(
                    datadir=datadir,
                    tree=args.tree,
                    overwrite=args.overwrite,
                    res=args.res,
                    interpolation=args.interpolation,
                    crop=args.crop,
                    alltouch=args.alltouch,
                )
                inv = ProjectInventory(datadir)
                inv.pprint()
            else:
                VerboseOut(
                    'No data found for {} within temporal extent {}'.format(
                        str(t_extent), str(t_extent)),
                    2,
                )
    except Exception as e:
        import traceback
        VerboseOut(traceback.format_exc(), 4)
        print 'Data Project error: %s' % e
Example #8
0
def main():
    title = Colors.BOLD + 'GIPS Tiles (v%s)' % __version__ + Colors.OFF

    # argument parsing
    parser0 = GIPSParser(description=title)
    parser0.add_inventory_parser()
    parser0.add_process_parser()
    parser0.add_project_parser()
    parser0.add_warp_parser()
    args = parser0.parse_args()

    cls = utils.gips_script_setup(args.command, args.stop_on_error)
    print title

    with utils.error_handler():
        # create output directory if needed
        # tld is "{}_tiles_{}_{}".format(DATATYPE, RESOLUTION, SUFFIX)
        if args.notld:
            tld = args.outdir
        else:
            tld = os.path.join(args.outdir, '%s_tiles' % args.command)
            if args.res is not None:
                tld = tld + '_%sx%s' % (args.res[0], args.res[1])
            if args.suffix != '':
                tld = tld + '_' + args.suffix
        mkdir(tld)

        extents = SpatialExtent.factory(cls,
                                        site=args.site,
                                        rastermask=args.rastermask,
                                        key=args.key,
                                        where=args.where,
                                        tiles=args.tiles,
                                        pcov=args.pcov,
                                        ptile=args.ptile)
        for extent in extents:
            inv = DataInventory(cls, extent,
                                TemporalExtent(args.dates, args.days),
                                **vars(args))
            for date in inv.dates:
                for tid in inv[date].tiles:
                    # make sure back-end tiles are processed
                    inv[date].tiles[tid].process(args.products,
                                                 overwrite=False)
                    # warp the tiles & copy into place in the output dir
                    inv[date].tiles[tid].copy(tld, args.products,
                                              inv.spatial.site, args.res,
                                              args.interpolation, args.crop,
                                              args.overwrite, args.tree)

    utils.gips_exit(
    )  # produce a summary error report then quit with a proper exit status
Example #9
0
def main():
    title = Colors.BOLD + "GIPS Data Project (v%s)" % __version__ + Colors.OFF

    # argument parsing
    parser0 = GIPSParser(description=title)
    parser0.add_inventory_parser(site_required=True)
    parser0.add_process_parser()
    parser0.add_project_parser()
    parser0.add_warp_parser()
    args = parser0.parse_args()

    try:
        print title
        cls = import_data_class(args.command)

        extents = SpatialExtent.factory(cls, args.site, args.key, args.where, args.tiles, args.pcov, args.ptile)

        # create tld: SITENAME--KEY_DATATYPE_SUFFIX
        if args.notld:
            tld = args.outdir
        else:
            key = "" if args.key == "" else "--" + args.key
            suffix = "" if args.suffix == "" else "_" + args.suffix
            res = "" if args.res is None else "_%sx%s" % (args.res[0], args.res[1])
            bname = extents[0].site.LayerName() + key + res + "_" + args.command + suffix
            tld = os.path.join(args.outdir, bname)

        for extent in extents:
            t_extent = TemporalExtent(args.dates, args.days)
            inv = DataInventory(cls, extent, t_extent, **vars(args))
            datadir = os.path.join(tld, extent.site.Value())
            if inv.numfiles > 0:
                inv.mosaic(
                    datadir=datadir,
                    tree=args.tree,
                    overwrite=args.overwrite,
                    res=args.res,
                    interpolation=args.interpolation,
                    crop=args.crop,
                    alltouch=args.alltouch,
                )
                inv = ProjectInventory(datadir)
                inv.pprint()
            else:
                VerboseOut("No data found for {} within temporal extent {}".format(str(t_extent), str(t_extent)), 2)
    except Exception as e:
        import traceback

        VerboseOut(traceback.format_exc(), 4)
        print "Data Project error: %s" % e
Example #10
0
def main():
    title = Colors.BOLD + 'GIPS Tiles (v%s)' % __version__ + Colors.OFF

    # argument parsing
    parser0 = GIPSParser(description=title)
    parser0.add_inventory_parser()
    parser0.add_process_parser()
    parser0.add_project_parser()
    parser0.add_warp_parser()
    args = parser0.parse_args()

    try:
        print title
        cls = import_data_class(args.command)

        # create tld: DATATYPE_tiles_RESOLUTION_SUFFIX
        if args.notld:
            tld = args.outdir
        else:
            tld = os.path.join(args.outdir, '%s_tiles' % args.command)
            if args.res is not None:
                tld = tld + '_%sx%s' % (args.res[0], args.res[1])
            if args.suffix != '':
                tld = tld + '_' + args.suffix
        mkdir(tld)

        extents = SpatialExtent.factory(cls, args.site, args.key, args.where,
                                        args.tiles, args.pcov, args.ptile)
        for extent in extents:
            inv = DataInventory(cls, extent,
                                TemporalExtent(args.dates, args.days),
                                **vars(args))
            for date in inv.dates:
                for tid in inv[date].tiles:
                    # make sure back-end tiles are processed
                    inv[date].tiles[tid].process(args.products,
                                                 overwrite=False)
                    # warp the tiles
                    inv[date].tiles[tid].copy(tld, args.products,
                                              inv.spatial.site, args.res,
                                              args.interpolation, args.crop,
                                              args.overwrite, args.tree)

    except Exception, e:
        import traceback
        VerboseOut(traceback.format_exc(), 4)
        print 'Warp Tiles error: %s' % e
Example #11
0
def main():
    title = Colors.BOLD + 'GIPS Tiles (v%s)' % __version__ + Colors.OFF

    # argument parsing
    parser0 = GIPSParser(description=title)
    parser0.add_inventory_parser()
    parser0.add_process_parser()
    parser0.add_project_parser()
    parser0.add_warp_parser()
    args = parser0.parse_args()

    try:
        print title
        cls = data_class(args.command)

        # create tld: DATATYPE_tiles_RESOLUTION_SUFFIX
        if args.notld:
            tld = args.outdir
        else:
            tld = os.path.join(args.outdir, '%s_tiles' % args.command)
            if args.res is not None:
                tld = tld + '_%sx%s' % (args.res[0], args.res[1])
            if args.suffix != '':
                tld = tld + '_' + args.suffix
        mkdir(tld)

        extents = SpatialExtent.factory(cls, args.site, args.key, args.where, args.tiles, args.pcov, args.ptile)
        for extent in extents:
            inv = DataInventory(cls, extent, TemporalExtent(args.dates, args.days), **vars(args))
            for date in inv.dates:
                for tid in inv[date].tiles:
                    # make sure back-end tiles are processed
                    inv[date].tiles[tid].process(args.products, overwrite=False)
                    # warp the tiles
                    inv[date].tiles[tid].copy(tld, args.products, inv.spatial.site,
                                              args.res, args.interpolation, args.crop, args.overwrite, args.tree)

    except Exception, e:
        import traceback
        VerboseOut(traceback.format_exc(), 4)
        print 'Warp Tiles error: %s' % e
Example #12
0
def main():
    title = Colors.BOLD + 'GIPS Data Project (v%s)' % __version__ + Colors.OFF

    # argument parsing
    parser0 = GIPSParser(description=title)
    parser0.add_inventory_parser(site_required=True)
    parser0.add_process_parser()
    parser0.add_project_parser()
    parser0.add_warp_parser()
    args = parser0.parse_args()

    try:
        print title
        cls = import_data_class(args.command)

        extents = SpatialExtent.factory(cls, args.site, args.key, args.where, args.tiles, args.pcov, args.ptile)

        # create tld: SITENAME--KEY_DATATYPE_SUFFIX
        if args.notld:
            tld = args.outdir
        else:
            key = '' if args.key == '' else '--' + args.key
            suffix = '' if args.suffix == '' else '_' + args.suffix
            res = '' if args.res is None else '_%sx%s' % (args.res[0], args.res[1])
            bname = extents[0].site.LayerName() + key + res + '_' + args.command + suffix
            tld = os.path.join(args.outdir, bname)

        for extent in extents:
            inv = DataInventory(cls, extent, TemporalExtent(args.dates, args.days), **vars(args))
            datadir = os.path.join(tld, extent.site.Value())
            if inv.numfiles > 0:
                inv.mosaic(datadir=datadir, tree=args.tree, overwrite=args.overwrite,
                           res=args.res, interpolation=args.interpolation, crop=args.crop)
            if not args.tree:
                inv = ProjectInventory(datadir)
                inv.pprint()

    except Exception, e:
        import traceback
        VerboseOut(traceback.format_exc(), 4)
        print 'Data Project error: %s' % e
Example #13
0
def main():
    title = Colors.BOLD + 'GIPS Data Processing (v%s)' % __version__ + Colors.OFF

    # argument parsing
    parser0 = GIPSParser(description=title)
    parser0.add_inventory_parser()
    parser0.add_process_parser()
    args = parser0.parse_args()

    try:
        print title
        cls = import_data_class(args.command)

        extents = SpatialExtent.factory(cls, args.site, args.key, args.where, args.tiles, args.pcov, args.ptile)
        for extent in extents:
            inv = DataInventory(cls, extent, TemporalExtent(args.dates, args.days), **vars(args))
            inv.process(overwrite=args.overwrite)

    except Exception, e:
        import traceback
        VerboseOut(traceback.format_exc(), 4)
        print 'Data processing error: %s' % e
Example #14
0
def main():
    title = Colors.BOLD + 'GIPS Data Inventory (v%s)' % gipsversion + Colors.OFF

    # argument parsing
    parser0 = GIPSParser(description=title)
    parser = parser0.add_inventory_parser()
    group = parser.add_argument_group('inventory display')
    group.add_argument('--md', help='Show dates using MM-DD', action='store_true', default=False)
    args = parser0.parse_args()

    try:
        print title
        cls = data_class(args.command)

        extents = SpatialExtent.factory(cls, args.site, args.key, args.where, 
                                        args.tiles, args.pcov, args.ptile)
        for extent in extents:
            inv = DataInventory(cls, extent, TemporalExtent(args.dates, args.days), **vars(args))
            inv.pprint(md=args.md)            
           
    except Exception, e:
        import traceback
        VerboseOut(traceback.format_exc(), 4)
        print 'Data inventory error: %s' % e
Example #15
0
def main():
    title = Colors.BOLD + 'GIPS Data Inventory (v%s)' % gipsversion + Colors.OFF

    # argument parsing
    parser0 = GIPSParser(description=title)
    parser = parser0.add_inventory_parser()
    group = parser.add_argument_group('inventory display')
    group.add_argument('--md', help='Show dates using MM-DD', action='store_true', default=False)
    args = parser0.parse_args()

    try:
        print title
        cls = import_data_class(args.command)

        extents = SpatialExtent.factory(cls, args.site, args.key, args.where, 
                                        args.tiles, args.pcov, args.ptile)
        for extent in extents:
            inv = DataInventory(cls, extent, TemporalExtent(args.dates, args.days), **vars(args))
            inv.pprint(md=args.md)            
           
    except Exception, e:
        import traceback
        VerboseOut(traceback.format_exc(), 4)
        print 'Data inventory error: %s' % e
Example #16
0
def main():
    title = Colors.BOLD + 'GIPS Data Export (v%s)' % __version__ + Colors.OFF

    # argument parsing
    parser0 = GIPSParser(description=title)
    parser0.add_inventory_parser(site_required=True)
    parser0.add_process_parser()
    parser0.add_project_parser()
    parser0.add_warp_parser()
    args = parser0.parse_args()

    cls = utils.gips_script_setup(args.command, args.stop_on_error)
    print title

    with utils.error_handler():
        extents = SpatialExtent.factory(cls,
                                        site=args.site,
                                        rastermask=args.rastermask,
                                        key=args.key,
                                        where=args.where,
                                        tiles=args.tiles,
                                        pcov=args.pcov,
                                        ptile=args.ptile)

        # create tld: SITENAME--KEY_DATATYPE_SUFFIX
        if args.notld:
            tld = args.outdir
        else:
            key = '' if args.key == '' else '--' + args.key
            suffix = '' if args.suffix == '' else '_' + args.suffix
            res = '' if args.res is None else '_%sx%s' % (args.res[0],
                                                          args.res[1])
            bname = (extents[0].site.LayerName() + key + res + '_' +
                     args.command + suffix)
            tld = os.path.join(args.outdir, bname)

        for extent in extents:
            t_extent = TemporalExtent(args.dates, args.days)
            inv = DataInventory(cls, extent, t_extent, **vars(args))
            datadir = os.path.join(tld, extent.site.Value())
            if inv.numfiles > 0:
                inv.mosaic(
                    datadir=datadir,
                    tree=args.tree,
                    overwrite=args.overwrite,
                    res=args.res,
                    interpolation=args.interpolation,
                    crop=args.crop,
                    alltouch=args.alltouch,
                    process=(not args.dont_process),
                )
                inv = ProjectInventory(datadir)
                inv.pprint()
            else:
                VerboseOut(
                    'No data found for {} within temporal extent {}'.format(
                        str(t_extent), str(t_extent)),
                    2,
                )

    utils.gips_exit(
    )  # produce a summary error report then quit with a proper exit status
Example #17
0
def main():
    title = Colors.BOLD + 'GIPS Data Processing (v%s)' % __version__ + Colors.OFF

    # argument parsing
    parser0 = GIPSParser(description=title)
    parser0.add_inventory_parser()
    parser0.add_process_parser()
    args = parser0.parse_args()

    cls = utils.gips_script_setup(args.command, args.stop_on_error)
    print title

    with utils.error_handler():
        extents = SpatialExtent.factory(
            cls, site=args.site, rastermask=args.rastermask,
            key=args.key, where=args.where, tiles=args.tiles,
            pcov=args.pcov, ptile=args.ptile
        )
        batchargs = None
        if args.batchout:
            tdl = []
            batchargs = '--chunksize ' + str(args.chunksize)
            batchargs += ' --format ' + str(args.format)
            batchargs += ' --numprocs ' + str(args.numprocs)
            batchargs += ' --verbose ' + str(args.verbose)
            if args.overwrite:
                batchargs += ' --overwrite '
            if args.products:
                batchargs += ' -p ' + ' '.join(args.products)

        for extent in extents:
            inv = DataInventory(
                cls, extent,
                TemporalExtent(args.dates, args.days), **vars(args)
            )
            if args.batchout:
                def get_commands(tiles_obj):
                    commands = []
                    for tile in tiles_obj.tiles.keys():
                        needed = any([p not in [k for sen, k in tiles_obj.tiles[tile].filenames.keys()]
                                      for p in args.products])
                        if not needed:
                            continue
                        commands.append(args.command + ' -t ' + str(tile) +
                                    ' -d ' + str(tiles_obj.date) + ' ' +
                                    batchargs + '\n')
                    return commands


                tdl = reduce(
                    list.__add__,
                    map(
                        get_commands,
                        inv.data.values()
                    ),
                    tdl
                )

            else:
                inv.process(overwrite=args.overwrite)
        if args.batchout:
            with open(args.batchout, 'w') as ofile:
                ofile.writelines(tdl)

    utils.gips_exit() # produce a summary error report then quit with a proper exit status
Example #18
0
#!/usr/bin/env python

try:
    from gips.data.cdl import cdlData as data
except:
    from gips.data.cdl import CDLData as data

from gips.core import SpatialExtent
from gips.utils import open_vector
from shapely.wkt import loads
from timeit import Timer

extent = SpatialExtent.factory(data, 'Belknap.shp')


assert len(extent[0].tiles) == 1, ('Belknap is contained wholly NH tile, '
                                   'but vector2tiles says it is in {} tiles'
                                   .format(len(extent[0].tiles)))

t = 'NH.shp'
f = 'NHseacoast.shp'


aWKT = open_vector(t)[0].WKT()
bWKT = open_vector(f)[0].WKT()
a = loads(aWKT)
b = loads(bWKT)
iters = 1000


def intersect():