Skip to content

Commit 28bdb3a

Browse files
committed
Merge pull request #10 from gimbo/master
Reduce memory consumption from 750MB to 60MB by using CSV not JSON. (Also lots of other changes.)
2 parents cf4909b + b4edc85 commit 28bdb3a

File tree

4 files changed

+28117
-95
lines changed

4 files changed

+28117
-95
lines changed

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,27 @@ pytzwhere is a Python library to lookup the timezone for a given lat/lng entirel
55

66
It is a port from https://github.com/mattbornski/tzwhere with a few improvements.
77

8-
Instructions and usage information can be seen by running:
9-
./tzwhere.py --help
8+
If used as a library, basic usage is as follows:
9+
10+
>>> import tzwhere
11+
>>> tz = tzwhere.tzwhere()
12+
Reading json input file: tz_world_compact.json
13+
>>> print tz.tzNameAt(35.29, -89.66)
14+
America/Chicago
15+
16+
By default (and as shown above), the `tzwhere` class (at the heart of this library) initialises itself from a JSON file. Note that this is very very memory hungry (about 750MB, though the file is much smaller). You can save a lot of memory (hundred of megabytes) at the cost of another second or so initialisation time, by telling `tzwhere` to read its data in (one line at a time) from a CSV file instead:
17+
18+
>>> tz = tzwhere.tzwhere(input_kind='csv')
19+
Reading from CSV input file: tz_world.csv
20+
>>> print tz.tzNameAt(35.29, -89.66)
21+
America/Chicago
22+
23+
The module can also be run as a script, which offers some other possibilities including producing the CSV file mentioned above. Instructions and usage information can be seen by running:
24+
25+
tzwhere.py --help
26+
27+
Dependencies (both optional):
28+
29+
* `docopt` - if you want to use `tzwhere.py` as a script (e.g. as shown above).
30+
31+
* `numpy` - if you want to save about 200MB of RAM.

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
version='1.0',
1212
packages=['tzwhere'],
1313
package_data={
14-
'tzwhere': ['tz_world.json', 'tz_world_compact.json', 'tz_world.pickle']
14+
'tzwhere': ['tz_world.json', 'tz_world_compact.json',
15+
'tz_world.pickle', 'tz_world.csv']
1516
},
1617
include_package_data=True,
1718
license='MIT License',

tzwhere/tz_world.csv

Lines changed: 27756 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)