Commit MetaInfo

Revisión9e5a0b6dea229d21bd40c81a725a70e192cf5654 (tree)
Tiempo2022-01-17 04:13:48
Autorrdnielsen
Commiterrdnielsen

Log Message

Added .hgignore and temp dev copy of mapdata.py.

Cambiar Resumen

Diferencia incremental

diff -r 316d4a561e57 -r 9e5a0b6dea22 .hgignore
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore Sun Jan 16 11:13:48 2022 -0800
@@ -0,0 +1,6 @@
1+syntax=glob
2+\.*
3+.*~
4+.*\.swp
5+documentation/*
6+
diff -r 316d4a561e57 -r 9e5a0b6dea22 mapdata/mapdata_2.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mapdata/mapdata_2.py Sun Jan 16 11:13:48 2022 -0800
@@ -0,0 +1,124 @@
1+#!/usr/bin/python
2+# mapdata.py
3+#
4+# PURPOSE
5+# Create a simple static map of data points that can be saved to a static
6+# image file.
7+#
8+# COPYRIGHT AND LICENSE
9+# Copyright (c) 2022, R. Dreas Nielsen
10+# This program is free software: you can redistribute it and/or modify
11+# it under the terms of the GNU General Public License as published by
12+# the Free Software Foundation, either version 3 of the License, or
13+# (at your option) any later version.
14+# This program is distributed in the hope that it will be useful,
15+# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+# GNU General Public License for more details.
18+# The GNU General Public License is available at <http://www.gnu.org/licenses/>
19+##
20+# NOTES
21+# 1.
22+#
23+# AUTHOR
24+# Dreas Nielsen (RDN)
25+#
26+# HISTORY
27+# Date Remarks
28+# ---------- -----------------------------------------------------
29+# 2022-01-15 Created. RDN.
30+# ==================================================================
31+
32+__version__ = "0.2.0"
33+__vdate = "2022-01-16"
34+
35+
36+import argparse
37+import pandas as pd
38+import matplotlib.pyplot as plt
39+import cartopy.crs as ccrs
40+import cartopy.io.img_tiles as cimgt
41+
42+
43+
44+def make_map(points_dataframe, lat="y_coord", lon="x_coord", name="location_id",
45+ basemap_layer="carto-positron", outfile_name="location_map.png",
46+ outwidth= 1600, outheight=1600, show=False):
47+ plt.figure(figsize=(8,6))
48+ stamen_terrain = cimgt.Stamen('terrain_background')
49+ mapaxes = plt.axes(projection=stamen_terrain.crs)
50+ plt.scatter(
51+ x = points[lon],
52+ y = points[lat],
53+ color = "red",
54+ s = 4,
55+ alpha = 0.6,
56+ transform = stamen_terrain.crs
57+ )
58+ if outfile_name is not None:
59+ plt.savefig(outfile_name)
60+ if show:
61+ plt.show()
62+
63+
64+
65+
66+
67+def clparser():
68+ desc_msg = "Create a static map image displaying points read from a CSV file. Version %s, %s" % (__version__, __vdate)
69+ parser = argparse.ArgumentParser(description=desc_msg)
70+ parser.add_argument('point_data_file',
71+ help="The name of a data file containing latitude and longitude coordinates, and an identifier")
72+ parser.add_argument('output_image_file',
73+ help="The name of the image file to create")
74+ parser.add_argument('-y', '--lat', default='y_coord', dest='lat',
75+ help="The name of the column in the data file containg latitude values")
76+ parser.add_argument('-x', '--lon', default='x_coord', dest='lon',
77+ help="The name of the column in the data file containing longitude values")
78+ parser.add_argument('-i', '--identifier', default='location_id', dest='id',
79+ help="The name of the column in the data file containing location identifiers")
80+ parser.add_argument('-b', '--baselayer', choices=['open-street-map', 'carto-positron',
81+ 'carto-darkmatter', 'stamen-terrain', 'stamen-toner', 'stamen-watercolor'],
82+ default='carto-positron', dest='baselayer',
83+ help="The name of the basemap layer to use")
84+ parser.add_argument('-w', '--width', type=int, default=1600, dest='width',
85+ help="The width of the output image, in pixels")
86+ parser.add_argument('-t', '--height', type=int, default=1600, dest='height',
87+ help="The height of the output image, in pixels")
88+ parser.add_argument('-s', '--show', type=bool, default=True, dest='show',
89+ help="Whether or not to show the map in the browser as well as saving it to a file")
90+
91+ return parser
92+
93+
94+
95+def main():
96+ p= clparser().parse_args()
97+ pts = pd.read_csv(p.point_data_file)
98+ make_map(pts, lat=p.lat, lon=p.lon, name=p.id, basemap_layer=p.baselayer,
99+ outfile_name=p.output_image_file, outwidth=p.width, outheight=p.height, show=p.show)
100+
101+
102+main()
103+
104+
105+#try:
106+# main()
107+#except SystemExit as x:
108+# raise
109+#except ErrInfo as e:
110+# exit_now(1, e)
111+#except ConfigError as e:
112+# strace = traceback.extract_tb(sys.exc_info()[2])[-1:]
113+# lno = strace[0][1]
114+# sys.exit(u"Configuration error on line %d of execsql.py: %s" % (lno, e.value))
115+#except Exception:
116+# strace = traceback.extract_tb(sys.exc_info()[2])[-1:]
117+# lno = strace[0][1]
118+# msg1 = u"%s: Uncaught exception %s (%s) on line %s" % (os.path.basename(sys.argv[0]), sys.exc_info()[0], sys.exc_info()[1], lno)
119+# script, lno = current_script_line()
120+# if script is not None:
121+# msg1 = msg1 + " in script %s, line %d" % (script, lno)
122+# exit_now(1, ErrInfo("exception", exception_msg=msg1))
123+
124+
Show on old repository browser