From 03c236ab676d66354696c31b75f2ed0c1abd36ae Mon Sep 17 00:00:00 2001 From: bacetiner Date: Mon, 1 Apr 2024 11:43:43 -0700 Subject: [PATCH] Changed warning settings to ignore connection pooling warnings --- brails/InventoryGenerator.py | 19 +++++++++++-------- brails/workflow/FootprintHandler.py | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/brails/InventoryGenerator.py b/brails/InventoryGenerator.py index 9004e50..1e06a55 100644 --- a/brails/InventoryGenerator.py +++ b/brails/InventoryGenerator.py @@ -63,7 +63,7 @@ # Set a custom warning message format: warnings.formatwarning = lambda message, category, filename, lineno, line=None: \ f"{category.__name__}: {message}\n" -warnings.simplefilter('always') +warnings.simplefilter('always',UserWarning) class InventoryGenerator: def __init__(self, location='Berkeley California', fpSource:str='osm', @@ -90,9 +90,9 @@ def __init__(self, location='Berkeley California', fpSource:str='osm', fpHandler = FootprintHandler() # If a baseline inventory is not specified: if not baselineInv: - # If location entry is a string containing geojson or csv file - # extension and an attribute mapping file is specified: - if ('csv' in location.lower() or 'geojson' in location.lower()) and attrmap: + # If location entry is a string containing geojson file extension + # and an attribute mapping file is specified: + if (location is str and 'geojson' in location.lower()) and attrmap: fpHandler.fetch_footprint_data(location, fpSource=fpSource, attrmap=attrmap, @@ -111,7 +111,7 @@ def __init__(self, location='Berkeley California', fpSource:str='osm', # If a user-specified inventory is defined and is accompanied by an # attribute mapping file: elif attrmap: - if ('csv' in location.lower() or 'geojson' in location.lower()): + if (location is str and 'csv' in location.lower() or 'geojson' in location.lower()): self.fpSource = 'user-specified' fpInp = location else: @@ -126,7 +126,8 @@ def __init__(self, location='Berkeley California', fpSource:str='osm', # accompanied by an attribute mapping file, ignore the entered: else: warnings.warn('Missing attribute mapping file. ' + - 'Ignoring the user-specified baseline inventory') + 'Ignoring the user-specified baseline inventory', + UserWarning) fpHandler.fetch_footprint_data(location,fpSource=fpSource,lengthUnit=lengthUnit) # Write geometry information from footprint data into a DataFrame: @@ -248,7 +249,8 @@ def __write_inventory_output(self,inventorydf:pd.DataFrame, # inventory output in GeoJSON format: if '.geojson' not in outputFile.lower(): warnings.warn('Output format unimplemented! ' - 'Writing the inventory output in GeoJSON format.') + 'Writing the inventory output in GeoJSON format', + UserWarning) outputFile = outputFile.replace(outputFile.split('.')[-1],'geojson') # Define GeoJSON file dictionary including basic metadata: @@ -434,7 +436,8 @@ def parse_attribute_input(attrIn:list,attrEnabled:list)->list: warnings.warn('Incorrect attributes entry. Supported attributes' + ' entries are a list containing the string labels ' + " for requested attributes, 'all' or 'hazuseq'. " + - ' Running BRAILS for roof shape detection only...') + ' Running BRAILS for roof shape detection only...', + UserWarning) attrOut=['roofshape'] return attrOut diff --git a/brails/workflow/FootprintHandler.py b/brails/workflow/FootprintHandler.py index df76876..9e2a374 100644 --- a/brails/workflow/FootprintHandler.py +++ b/brails/workflow/FootprintHandler.py @@ -59,7 +59,7 @@ # Set a custom warning message format: warnings.formatwarning = lambda message, category, filename, lineno, line=None: \ f"{category.__name__}: {message}\n" -warnings.simplefilter('always') +warnings.simplefilter('always',UserWarning) class FootprintHandler: def __init__(self):