|
1 |
| -# Written: fmk 4/23 |
2 |
| -# License: BSD-2 |
| 1 | +# Copyright (c) 2024 The Regents of the University of California |
| 2 | +# |
| 3 | +# This file is part of BRAILS++. |
| 4 | +# |
| 5 | +# Redistribution and use in source and binary forms, with or without |
| 6 | +# modification, are permitted provided that the following conditions are met: |
| 7 | +# |
| 8 | +# 1. Redistributions of source code must retain the above copyright notice, |
| 9 | +# this list of conditions and the following disclaimer. |
| 10 | +# |
| 11 | +# 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | +# this list of conditions and the following disclaimer in the documentation |
| 13 | +# and/or other materials provided with the distribution. |
| 14 | +# |
| 15 | +# 3. Neither the name of the copyright holder nor the names of its contributors |
| 16 | +# may be used to endorse or promote products derived from this software without |
| 17 | +# specific prior written permission. |
| 18 | +# |
| 19 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' |
| 20 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 | +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 23 | +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 | +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 | +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 | +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 | +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 | +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 | +# POSSIBILITY OF SUCH DAMAGE. |
| 30 | +# |
| 31 | +# You should have received a copy of the BSD 3-Clause License along with |
| 32 | +# BRAILS++. If not, see <http://www.opensource.org/licenses/>. |
| 33 | +# |
| 34 | +# Contributors: |
| 35 | +# Frank McKenna |
| 36 | +# Barbaros Cetiner |
| 37 | +# |
| 38 | +# Last updated: |
| 39 | +# 11-06-2024 |
3 | 40 |
|
4 | 41 | """
|
5 |
| - Purpose: Testing Importer and get_footprints methods |
6 |
| -""" |
7 |
| - |
8 |
| -import sys |
| 42 | +Example demonstrating BRAILS' automated footprint downloading capabilities. |
9 | 43 |
|
10 |
| -sys.path.insert(1, "../../") |
11 |
| - |
12 |
| -from brails.utils.utils import Importer |
| 44 | + Purpose: Testing 1) get_class method of Importer |
| 45 | + 2) get_footprints method of OSM_FootprintScraper, |
| 46 | + MS_FootprintScraper, and USA_FootprintScraper modules |
| 47 | + 3) get_random_sample of AssetInventory |
| 48 | +""" |
13 | 49 |
|
14 |
| -# create an Import to get the classes |
| 50 | +from brails import Importer |
15 | 51 |
|
| 52 | +# create an Importer object to fetch BRAILS++ classes: |
16 | 53 | importer = Importer()
|
17 | 54 |
|
18 |
| -# |
19 |
| -# specify the BoundaryRegion |
20 |
| -# |
21 |
| - |
| 55 | +# Specify the BoundaryRegion: |
22 | 56 |
|
23 |
| -region_data = {"type": "locationName", "data": "Tiburon, CA"} |
24 |
| -region_boundary_class = importer.get_class("RegionBoundary") |
| 57 | +region_data = {'type': 'locationName', 'data': 'Tiburon, CA'} |
| 58 | +region_boundary_class = importer.get_class('RegionBoundary') |
25 | 59 | region_boundary_object = region_boundary_class(region_data)
|
26 | 60 |
|
27 |
| -# |
28 |
| -# Get Footprints using OSM |
29 |
| -# |
| 61 | +# Get Footprints using OSM: |
| 62 | +print('Trying OSM_FootprintsScraper...') |
30 | 63 |
|
31 |
| -print("Trying OSM_FootprintsScraper ...") |
32 |
| - |
33 |
| -osm_class = importer.get_class("OSM_FootprintScraper") |
34 |
| -osm_data = {"length": "ft"} |
| 64 | +osm_class = importer.get_class('OSM_FootprintScraper') |
| 65 | +osm_data = {'length': 'ft'} |
35 | 66 | instance1 = osm_class(osm_data)
|
36 | 67 | osm_inventory = instance1.get_footprints(region_boundary_object)
|
37 | 68 |
|
38 |
| -print("num assets OSM", len(osm_inventory.inventory)) |
| 69 | +print('Number of assets in OSM', len(osm_inventory.inventory)) |
39 | 70 |
|
40 |
| -# |
41 |
| -# Get Footprints using Microsofts Database |
42 |
| -# |
43 | 71 |
|
44 |
| -print("Trying Microsoft Footprint Database ...") |
45 |
| -ms_class = importer.get_class("MS_FootprintScraper") |
46 |
| -ms_data = {"length": "ft"} |
47 |
| -instance3 = ms_class(ms_data) |
48 |
| -ms_inventory = instance3.get_footprints(region_boundary_object) |
| 72 | +# Get Footprints using Microsoft Footprints Database: |
| 73 | +print('Trying Microsoft Footprint Database...') |
| 74 | +ms_class = importer.get_class('MS_FootprintScraper') |
| 75 | +ms_data = {'length': 'ft'} |
| 76 | +instance2 = ms_class(ms_data) |
| 77 | +ms_inventory = instance2.get_footprints(region_boundary_object) |
49 | 78 |
|
50 |
| -print("num assets Microsoft", len(ms_inventory.inventory)) |
| 79 | +print('Number of assets in Microsoft Footprint Database', |
| 80 | + len(ms_inventory.inventory)) |
51 | 81 |
|
52 | 82 |
|
53 |
| -# |
54 |
| -# Get Footprints using USA Structures |
55 |
| -# |
56 |
| - |
| 83 | +# Get Footprints using USA Structures data: |
| 84 | +print('Trying USA_FootprintsScraper...') |
| 85 | +usa_class = importer.get_class('USA_FootprintScraper') |
| 86 | +usa_data = {'length': 'ft'} |
| 87 | +instance3 = usa_class(usa_data) |
| 88 | +usa_inventory = instance3.get_footprints(region_boundary_object) |
57 | 89 |
|
58 |
| -print("Trying USA_FootprintsScraper ...") |
59 |
| -usa_class = importer.get_class("USA_FootprintScraper") |
60 |
| -usa_data = {"length": "ft"} |
61 |
| -instance2 = usa_class(usa_data) |
62 |
| -usa_inventory = instance2.get_footprints(region_boundary_object) |
| 90 | +print('Number of assets in USA Structures', len(usa_inventory.inventory)) |
63 | 91 |
|
64 |
| -print("num assets USA", len(usa_inventory.inventory)) |
65 |
| - |
66 |
| -# |
67 |
| -# Test obtaining a smaller subset of random values, |
68 |
| -# method used as we will not always want to get all the images |
69 |
| -# |
70 | 92 |
|
71 |
| -small_inventory = usa_inventory.get_random_sample(4, 200) |
72 |
| -print("num assets USA subset", len(small_inventory.inventory)) |
| 93 | +# Obtain a smaller subset of random values, as we will not always want to get |
| 94 | +# all the images: |
| 95 | +print('\nGetting a subset of the USA footprints...') |
| 96 | +small_inventory = usa_inventory.get_random_sample(10, 200) |
| 97 | +print('Number of assets in the subset', len(small_inventory.inventory)) |
0 commit comments