Skip to content

Commit

Permalink
removed unnecessary logging
Browse files Browse the repository at this point in the history
  • Loading branch information
popenc committed Sep 5, 2024
1 parent 921c1dc commit 7cddc65
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 66 deletions.
1 change: 0 additions & 1 deletion celery_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def __init__(self):
# self.cyano_request_timeout = 30 # seconds

def test_celery(self):
logging.warning("CALLING CELERY TASK")
celery_job = test_celery.apply_async(queue="celery")
return {"status": "test celery called"}

Expand Down
33 changes: 0 additions & 33 deletions flaskr/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,39 +180,27 @@ def get_waterbody_fid(objectid: int):
conn = sqlite3.connect(DB_FILE)
cur = conn.cursor()
query = "SELECT FID FROM WaterbodyBounds WHERE OBJECTID==?"
# logging.warning("Running query: {}".format(query))
cur.execute(query, (int(objectid),))
fid = cur.fetchall()
# logging.warning("fid: {}".format(fid))
if len(fid) == 0:
return None
return fid[0][0]


def get_waterbody_bypoint(lat: float, lng: float, return_fid: bool=False):

logging.warning("get_waterbody_bypoint() called")

conn = sqlite3.connect(DB_FILE)
cur = conn.cursor()
query = "SELECT OBJECTID, FID FROM WaterbodyBounds WHERE y_max>=? AND x_min<=? AND y_min<=? AND x_max>=?"
values = (lat, lng, lat, lng,)

logging.warning("Executing query: {}".format(query))

cur.execute(query, values)
lakes = cur.fetchall()

logging.warning("LAKES: {}".format(lakes))

crs = None
if len(lakes) > 0:
features = []
for lake in lakes:

logging.warning("Lake: {}".format(lake))

# w = get_waterbody(int(lake[0]))
w = get_waterbody_by_fids(fid=lake[1])
features.append(w[0][0])
crs = w[1]
Expand All @@ -222,54 +210,33 @@ def get_waterbody_bypoint(lat: float, lng: float, return_fid: bool=False):
objectid = None
gnis_name = None

logging.warning("Getting point with geopandas. lng: {}, lat: {}, wb[1]: {}".format(lng, lat, wb[1]))
out_proj = Proj(wb[1])
logging.warning("out_proj: {}".format(out_proj))
_lng, _lat = out_proj(lng, lat)
logging.warning("_lat: {}, _lng: {}".format(_lat, _lng))
point = gpd.GeoSeries(Point(_lng, _lat), crs=wb[1])
logging.warning("point: {}".format(point))

for features in wb[0]:

logging.warning("Looping features: {}".format(features))

if features["geometry"]["type"] == "MultiPolygon":
poly_geos = []

logging.warning("Geometry type is MultiPolygon")

for p in features["geometry"]["coordinates"]:
logging.warning("~~~ p: {}".format(p))
poly_geos.append(Polygon(p[0]))

logging.warning("Setting poly")
poly = gpd.GeoSeries(MultiPolygon(poly_geos), crs=wb[1])
logging.warning("Poly: {}".format(poly))
else:
logging.warning("Geometry type is not MultiPolygon")
poly = gpd.GeoSeries(Polygon(features["geometry"]["coordinates"][0]), crs=wb[1])
logging.warning("Poly: {}".format(poly))
in_wb = poly.contains(point)

logging.warning("in_wb: {}".format(in_wb))

if in_wb.loc[0]:
objectid = features["properties"]["OBJECTID"]
gnis_name = features["properties"]["GNIS_NAME"]

logging.warning("ObjectID: {}, gnis_name: {}".format(objectid, gnis_name))

break
conn.close()

logging.warning("Db connection closed.")

if return_fid and objectid is not None:
logging.warning("Returning objectid and running get_waterbody_fid()")
return objectid, get_waterbody_fid(objectid), gnis_name
else:
logging.warning("Returning objectid, None, gnis_name")
return objectid, None, gnis_name


Expand Down
32 changes: 0 additions & 32 deletions flaskr/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import numpy as np
from shapely.geometry import Polygon, MultiPolygon, Point
from pyproj import Proj, transform
import logging

import time

Expand Down Expand Up @@ -39,33 +38,20 @@ def get_waterbody_by_fids(fid: int = None, fids: list = None, tojson: bool = Fal
features = []
names = {}

# logging.warning("get_waterbody_by_fids() called")

if fid is None and fids is None:
logging.warning("fid is None and fids is None, returning features: {}".format(features))
return features
if tojson:
# logging.warning("Opening WATERBODY_DBF")
with fiona.open(WATERBODY_DBF) as waterbodies:
logging.warning("waterbodies: {}".format(waterbodies))
crs = waterbodies.crs
# logging.warning("crs: {}".format(crs))
if fid is not None:
# logging.warning("getting fid")
f = waterbodies.get(fid)
# logging.warning("f: {}".format(f))
features.append(f)
if fids is not None:
# logging.warning("getting fids")
for _fid in fids:
# logging.warning("fid: {}".format(_fid))
f = waterbodies.get(_fid)
# logging.warning("f: {}".format(f))
features.append(f)
# logging.warning("features: {}".format(features))
geojson = []
for feature in features:
# logging.warning("Looping feature: {}".format(feature))
if feature["geometry"]["type"] == "MultiPolygon":
poly_geos = []
for p in feature["geometry"]["coordinates"]:
Expand All @@ -76,29 +62,20 @@ def get_waterbody_by_fids(fid: int = None, fids: list = None, tojson: bool = Fal
geojson.append(poly.to_json())
return geojson
else:
# logging.warning("geometry.py get_waterbody_by_fids else")
with fiona.open(WATERBODY_DBF) as waterbodies:
# logging.warning("Opened WATERBODY_DBF as waterbodies, fid: {}".format(fid))
crs = waterbodies.crs

if fid is not None:
# logging.warning("Getting waterbody with fid: {}".format(fid))
f = waterbodies.get(fid)
# logging.warning("Found waterbody with fid: {}".format(f))
features.append(f)
names[int(f["properties"]["OBJECTID"])] = f["properties"]["GNIS_NAME"]
if fids is not None:
# logging.warning("Getting waterbody with FIDS")
for _fid in fids:
# logging.warning("Getting WB with _fid: {}".format(_fid))
f = waterbodies.get(_fid)
# logging.warning("Found: {}".format(f))
features.append(f)
names[int(f["properties"]["OBJECTID"])] = f["properties"]["GNIS_NAME"]
if name_only:
# logging.warning("Returning name only")
return names
# logging.warning("Returning features: {}\ncrs: {}".format(features, crs))
return features, crs


Expand Down Expand Up @@ -176,16 +153,13 @@ def get_waterbody_byname(gnis_name: str):


def get_waterbody_byID(id: int, fid: int = None):
logging.warning("inside get_waterbody_byID, id: {}, fid: {}".format(id, fid))
if id is None and fid is None:
return {}
waterbody = []
t0 = time.time()
if not fid:
logging.warning("No fid Opening WATERBODY_DBF")
with fiona.open(WATERBODY_DBF) as waterbodies:
for f in waterbodies:
logging.warning("Waterbody: {}".format(f))
if id == int(f["properties"]["OBJECTID"]):
wb = {
"name": f["properties"]["GNIS_NAME"],
Expand All @@ -198,12 +172,8 @@ def get_waterbody_byID(id: int, fid: int = None):
waterbody = [wb]
break
else:
logging.warning("with fid Opening WATERBODY_DBF")
with fiona.open(WATERBODY_DBF) as waterbodies:
f = waterbodies.get(fid)
logging.warning("waterbodies: {}".format(f))
logging.warning("Id: {}".format(id))
logging.warning('f["properties"]["OBJECTID"]: {}'.format(f["properties"]["OBJECTID"]))
if int(f["properties"]["OBJECTID"]) == id:
wb = {
"name": f["properties"]["GNIS_NAME"],
Expand All @@ -213,10 +183,8 @@ def get_waterbody_byID(id: int, fid: int = None):
"areasqkm": float(f["properties"]["AREASQKM"]),
"state_abbr": f["properties"]["STATE_ABBR"]
}
logging.warning("Found wb: {}".format(wb))
waterbody = [wb]
else:
logging.warning("Trying to run get_waterbody_byID again.")
return get_waterbody_byID(id=id)
t1 = time.time()
print(f"Search runtime: {round(t1 - t0, 3)} sec")
Expand Down

0 comments on commit 7cddc65

Please sign in to comment.