Skip to content

Commit 68b7035

Browse files
authored
Merge pull request #48 from bacetiner/master
Updated example scripts for BRAILS++
2 parents 1d41d9c + 9c2e810 commit 68b7035

File tree

7 files changed

+578
-418
lines changed

7 files changed

+578
-418
lines changed

brails/filters/filter.py

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,86 @@
1-
from abc import ABC, abstractmethod
2-
from brails.types.image_set import ImageSet
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
340

441
"""
5-
This module defines abstract filter class
42+
This module defines abstract filter class.
643
744
.. autosummary::
845
946
Filter
1047
"""
1148

49+
from abc import ABC, abstractmethod
50+
from brails.types.image_set import ImageSet
51+
52+
1253
class Filter(ABC):
1354
"""
14-
Abstract base class representing a class that filters an ImageSet
55+
Abstract base class for filtering an ImageSet.
1556
16-
Methods:
17-
__init__(dict): Constructor
18-
get_footprints(location): An abstract method to return the footprint given a location
57+
Methods:
58+
filter(images, dir_path): Filters the ImageSet based on specific
59+
criteria.
1960
"""
2061

21-
2262
def __init__(self, input_data: dict):
63+
"""
64+
Initialize the Filter with the provided input.
65+
66+
Args:
67+
input_data (dict): Configuration or parameters required for
68+
filtering.
69+
"""
2370
self.input_data = input_data
24-
71+
2572
@abstractmethod
26-
def filter(self, images: ImageSet, dir_path: str) ->ImageSet:
73+
def filter(self, images: ImageSet, dir_path: str) -> ImageSet:
2774
"""
28-
An abstract class that must be implemented by subclasses.
75+
Abstract class that must be implemented by subclasses.
2976
3077
This method will be used by the caller to obtain a filtered ImageSet
78+
and save the output in a specified directory.
3179
3280
Args:
33-
image_set (ImageSet):
34-
The input ImageSet to be filtered
35-
dir_path
36-
The path to output dir where filtered images are to be placed
81+
images (ImageSet): The ImageSet to filter.
82+
dir_path (str): Path to the output directory for filtered images.
3783
3884
Returns:
39-
ImageSet:
40-
The filtered set of images
41-
85+
ImageSet: The filtered set of images.
4286
"""
43-
pass
Lines changed: 75 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,97 @@
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
340

441
"""
5-
Purpose: Testing Importer and get_footprints methods
6-
"""
7-
8-
import sys
42+
Example demonstrating BRAILS' automated footprint downloading capabilities.
943
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+
"""
1349

14-
# create an Import to get the classes
50+
from brails import Importer
1551

52+
# create an Importer object to fetch BRAILS++ classes:
1653
importer = Importer()
1754

18-
#
19-
# specify the BoundaryRegion
20-
#
21-
55+
# Specify the BoundaryRegion:
2256

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')
2559
region_boundary_object = region_boundary_class(region_data)
2660

27-
#
28-
# Get Footprints using OSM
29-
#
61+
# Get Footprints using OSM:
62+
print('Trying OSM_FootprintsScraper...')
3063

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'}
3566
instance1 = osm_class(osm_data)
3667
osm_inventory = instance1.get_footprints(region_boundary_object)
3768

38-
print("num assets OSM", len(osm_inventory.inventory))
69+
print('Number of assets in OSM', len(osm_inventory.inventory))
3970

40-
#
41-
# Get Footprints using Microsofts Database
42-
#
4371

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)
4978

50-
print("num assets Microsoft", len(ms_inventory.inventory))
79+
print('Number of assets in Microsoft Footprint Database',
80+
len(ms_inventory.inventory))
5181

5282

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)
5789

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))
6391

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-
#
7092

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))

examples/image_downloads/brails_download_images.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
# Barbaros Cetiner
3737
#
3838
# Last updated:
39-
# 10-24-2024
39+
# 11-06-2024
4040

4141
"""
4242
Example showcasing BRAILS' image downloading capabilities.
@@ -60,7 +60,9 @@
6060
if os.path.exists(API_KEY_DIR):
6161
with open(API_KEY_DIR, 'r', encoding='utf-8') as file:
6262
api_key = file.readline().strip() # Read first line & strip whitespace
63-
63+
else:
64+
raise FileNotFoundError('API key file not found. Please ensure the file'
65+
f' exists at: {API_KEY_DIR}')
6466

6567
# Create the importer:
6668
importer = Importer()

0 commit comments

Comments
 (0)