Skip to content

Commit

Permalink
0.9.1
Browse files Browse the repository at this point in the history
- Use logging throughout
- Review docstrings and add type hints
- Make some methods private
- Use Pandas merge when geocoding postcodes for better performance
- Minor bug fixes and performance improvements
  • Loading branch information
JamieTaylor-TUOS committed May 23, 2022
1 parent 33d95f9 commit 774fde9
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 167 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Geocode various geographical entities including postcodes and LLSOAs. Reverse-geocode to LLSOA or GSP/GNode.

*Latest Version: 0.9.0*
*Latest Version: 0.9.1*

## What is this repository for?

Expand Down
7 changes: 7 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
import logging

from geocode import Geocoder

def main():
Expand Down Expand Up @@ -40,4 +43,8 @@ def main():
print(f" {lat:.3f}, {lon:.3f}")

if __name__ == "__main__":
log_fmt = "%(asctime)s [%(levelname)s] [%(filename)s:%(funcName)s] - %(message)s"
fmt = os.environ.get("GEOCODE_LOGGING_FMT", log_fmt)
datefmt = os.environ.get("GEOCODE_LOGGING_DATEFMT", "%Y-%m-%dT%H:%M:%SZ")
logging.basicConfig(format=fmt, datefmt=datefmt, level=os.environ.get("LOGLEVEL", "DEBUG"))
main()
4 changes: 2 additions & 2 deletions geocode/bng2latlon.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ def main():
with open(options.infile, "r") as fid:
df = pd.read_csv(fid)
with Geocoder(progress_bar=True) as geo:
lons, lats = geo.bng2latlon(df["eastings"].to_numpy(), df["northings"].to_numpy())
lons, lats = geo._bng2latlon(df["eastings"].to_numpy(), df["northings"].to_numpy())
df["latitude"] = lats
df["longitude"] = lons
df.to_csv(options.outfile, index=False)
print(f"Finished, time taken: {TIME.time() - timerstart} seconds")
print(f"Finished, time taken: {TIME.time() - timerstart:.1f} seconds")

if __name__ == "__main__":
main()
447 changes: 289 additions & 158 deletions geocode/geocode.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion geocode/latlons2gsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def main():
columns = row.index.to_list() + list(l.keys())
output = pd.DataFrame(output, columns=columns)
output.to_csv(options.outfile, index=False)
print(f"Finished, time taken: {TIME.time() - timerstart} seconds")
print(f"Finished, time taken: {TIME.time() - timerstart:.1f} seconds")

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion geocode/latlons2llsoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def main():
df["llsoacd"] = geo.reverse_geocode_llsoa(df[["latitude", "longitude"]].to_numpy(),
options.datazones)
df.to_csv(options.outfile, index=False)
print(f"Finished, time taken: {TIME.time() - timerstart} seconds")
print(f"Finished, time taken: {TIME.time() - timerstart:.1f} seconds")

if __name__ == "__main__":
main()
5 changes: 2 additions & 3 deletions geocode/postcodes2latlon.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ def main():
timerstart = TIME.time()
options = parse_options()
with open(options.infile, "r") as fid:
df = pd.read_csv(fid)
df = pd.read_csv(fid).iloc[:100]
with Geocoder(progress_bar=True) as geo:
# import pdb; pdb.set_trace()
results = geo.geocode(postcodes=df["postcode"].to_numpy())
lats = [r[0] if r[0] is not None else pd.NA for r in results]
lons = [r[1] if r[1] is not None else pd.NA for r in results]
Expand All @@ -52,7 +51,7 @@ def main():
df["longitude"] = lons
df["geocode_status"] = status
df.to_csv(options.outfile, index=False)
print(f"Finished, time taken: {TIME.time() - timerstart} seconds")
print(f"Finished, time taken: {TIME.time() - timerstart:.1f} seconds")

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version="0.9.0",
version="0.9.1",

description="Geocode postcodes, addresses or LLSOA using the Code Point Open database and GMaps API.",
long_description=long_description,
Expand Down

0 comments on commit 774fde9

Please sign in to comment.