-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
59 lines (48 loc) · 1.62 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""in.py:
"""
__author__ = "Dilawar Singh"
__copyright__ = "Copyright 2017-, Dilawar Singh"
__version__ = "1.0.0"
__maintainer__ = "Dilawar Singh"
__email__ = "dilawars@ncbs.res.in"
__status__ = "Development"
import sys
from osgeo import gdal_array
#from mpl_toolkits.basemap import Basemap, cm
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.style.use( ['bmh', 'fivethirtyeight'] )
import numpy as np
import scipy.spatial
import pandas as pd
scale_ = 111.03 # At 40deg from equation 1deg=111.03km
cols='id:name:asciiname:alternatenames:latitude: longitude:' \
+ 'featureclass:featurecode: countrycode: cc2:' \
+ 'admin1code: admin2code: admin3code: admin4code: population:'\
+ 'elevation:dem:timezone:modificationdate'
cols = [x.strip() for x in cols.split(':')]
def info(df):
print( 'MIN ELEVATION', df['elevation'].min() )
print( 'MAX ELEVATION', df['elevation'].max() )
print('TOTAL POINTS: ', len(df))
def center_of_mass(xs, ys, ws):
gmean = xs.mean(), ys.mean()
pts = np.dstack((xs, ys))[0]
hull = scipy.spatial.ConvexHull(pts)
outline = pts[hull.vertices]
mean = sum(xs * ws)/sum(ws), sum(ys*ws)/sum(ws)
return mean, gmean, outline
def main_gdal(infile):
raster = gdal_array.LoadFile(infile)
print(raster)
plt.xlabel('Longitude')
plt.ylabel('Latitude')
plt.tight_layout( )
plt.savefig(f'{__file__}.png')
def main_png(pngfile):
data = plt.imread(pngfile)
print(data.shape)
print(data.min(), data.max())
if __name__ == '__main__':
infile = sys.argv[1]
main_png(infile)