-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Adding PVGIS horizon data retrieval method #1395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
539bc5c
85754b5
4985e9c
132ab4e
64bbc97
19e1073
d563a81
e9856da
c392e29
e8d6100
3dca8bb
93d914d
5c1bc2d
eb8f8c5
5a3c9cc
515ed85
1c3a398
a191d2d
82ba2a5
ca2eec3
996b3f9
3717186
f9a2193
989b700
02082ee
206f979
156e964
c674bb5
3a2cab9
78f6c1d
641bf53
3d310c6
c7b65b3
288390b
e8d8795
a2496e5
d36c508
60ba9cb
7b9d528
709493e
fa14c67
97ee479
43951a2
6f9ad5e
8e01b57
7b99b8d
9ea61e2
e23d58c
801f4d3
860f484
bcca59b
6cfb0c4
d5cd1af
53d9e6c
c831107
17e4f92
c176d9b
0d2a061
6980a4d
cf21974
0fb9e05
7736e35
7f84531
cb7eb41
25baf2b
b9edf25
d15c7ff
2bf5cb2
89e53d9
e13e322
50e79cd
75a9407
d860570
8aedbe6
62237e2
bef7c81
d9689d3
302abb0
4ad491b
7901797
af8988f
f58f8d7
a305ab6
15e5c9c
482bc23
94fee4c
a8c7693
2eea384
bf34256
01893d8
d978b2c
b693813
8de2506
6425884
568c9cd
fb3d571
d3bc17b
ec52f59
a696faf
b65d58b
d008dab
22e0988
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -24,7 +24,8 @@ def latlong(ds): | |||||
Returns | ||||||
------- | ||||||
lat,long : tuple | ||||||
Tuple of np.array of latitude,longitude corresponding to the pixels in the GeoTiff | ||||||
Tuple of np.array of latitude,longitude | ||||||
corresponding to the pixels in the GeoTiff | ||||||
|
||||||
''' | ||||||
|
||||||
|
@@ -35,9 +36,9 @@ def latlong(ds): | |||||
miny = gt[3] + width*gt[4] + height*gt[5] | ||||||
maxx = gt[0] + width*gt[1] + height*gt[2] | ||||||
maxy = gt[3] | ||||||
lat = np.linspace(miny,maxy,height) | ||||||
long = np.linspace(minx,maxx,width) | ||||||
return (lat,long) | ||||||
lat = np.linspace(miny, maxy, height) | ||||||
long = np.linspace(minx, maxx, width) | ||||||
return (lat, long) | ||||||
|
||||||
|
||||||
def load_DEM(filepath): | ||||||
|
@@ -83,20 +84,30 @@ def get_pixel_coords(lat, lon, DEM_path): | |||||
of the raster corresponding to latitiude and longitude | ||||||
''' | ||||||
img = geoio.GeoImage(DEM_path) | ||||||
return map(int, img.proj_to_raster(lon,lat)) | ||||||
return map(int, img.proj_to_raster(lon, lat)) | ||||||
|
||||||
|
||||||
def _point_symmetry(x, y): | ||||||
r""" | ||||||
Reflect a point 8 ways to form a circle. | ||||||
r"""Reflect a point 8 ways to form a circle. | ||||||
Parameters | ||||||
bgpierc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
---------- | ||||||
x : numeric | ||||||
x point of the circle | ||||||
y: numeric | ||||||
y point of the circle | ||||||
|
||||||
Returns | ||||||
------- | ||||||
points : list | ||||||
List of reflected points | ||||||
""" | ||||||
return [( x, y), | ||||||
( y, x), | ||||||
(-x, y), | ||||||
(-y, x), | ||||||
8000 | ( x, -y), | |||||
( y, -x), | ||||||
(-x, -y), | ||||||
return [(x, y), | ||||||
(y, x), | ||||||
(-x, y), | ||||||
(-y, x), | ||||||
(x, -y), | ||||||
(y, -x), | ||||||
(-x, -y), | ||||||
(-y, -x)] | ||||||
|
||||||
|
||||||
|
@@ -140,12 +151,12 @@ def _bresenham_circ(r, center = (0,0)): | |||||
x += 1 | ||||||
points.extend(_point_symmetry(x, y)) | ||||||
points = np.array(points) | ||||||
newx = points[:,0] + center[0] | ||||||
newy = points[:,1] + center[1] | ||||||
return np.vstack((newx,newy)) | ||||||
newx = points[:, 0] + center[0] | ||||||
newy = points[:, 1] + center[1] | ||||||
return np.vstack((newx, newy)) | ||||||
|
||||||
|
||||||
def _pol2cart(r,theta): | ||||||
def _pol2cart(r, theta): | ||||||
r'''Converts polar to cartesian | ||||||
Parameters | ||||||
---------- | ||||||
|
@@ -191,11 +202,12 @@ def _cart2pol(x, y): | |||||
return r, theta | ||||||
|
||||||
|
||||||
def _sort_circ(pts, center = (0,0), az_len = 360): | ||||||
def _sort_circ(pts, center=(0,0), az_len=360): | ||||||
r'''Sort and resample points on a circle such that the zeroth element is | ||||||
due east and the points move around the circle counter clockwise. | ||||||
While in polar domain, resample points using FFT to obtain desired number of bins, | ||||||
typically 360, for degrees around the circle. | ||||||
While in polar domain, resample points using FFT to | ||||||
obtain desired number of bins,typically 360, for | ||||||
degrees around the circle. | ||||||
|
||||||
Parameters | ||||||
---------- | ||||||
|
@@ -215,18 +227,18 @@ def _sort_circ(pts, center = (0,0), az_len = 360): | |||||
pts[1] -= center[1] | ||||||
r, theta = _cart2pol(pts[0], pts[1]) | ||||||
stacked = np.vstack((theta, r)) | ||||||
sort = np.sort(stacked, axis = 1) | ||||||
sort = resample(sort, az_len, axis = 1) | ||||||
sort = np.sort(stacked, axis=1) | ||||||
sort = resample(sort, az_len, axis=1) | ||||||
theta = sort[0] | ||||||
r = sort[1] | ||||||
x, y = _pol2cart(r,theta) | ||||||
x, y = _pol2cart(r, theta) | ||||||
x += center[0] | ||||||
y += center[1] | ||||||
return np.vstack((x, y)).astype(int) | ||||||
|
||||||
|
||||||
def horizon_map(dem_pixel, dem_path, dem_res = 30.0, | ||||||
view_distance=500, az_len = 36): | ||||||
def horizon_map(dem_pixel, dem_path, dem_res=30.0, | ||||||
view_distance=500, az_len=36): | ||||||
r"""Finds the horizon at point on a dem in pixel coordinates dem_pixel | ||||||
bgpierc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
Parameters | ||||||
|
@@ -256,14 +268,14 @@ def horizon_map(dem_pixel, dem_path, dem_res = 30.0, | |||||
# retrive data from the DEM | ||||||
elevation, lat, long = load_DEM(dem_path) | ||||||
|
||||||
azimuth = np.linspace(0,360,az_len) | ||||||
azimuth = np.linspace(0, 360, az_len) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here,
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, off-by-one. Good catch. Changed to be in range [0,360) |
||||||
|
||||||
# Use Midpoint Circle Algo/ Bresenham's circle | ||||||
pts = _bresenham_circ(view_distance,dem_pixel) | ||||||
pts = _bresenham_circ(view_distance, dem_pixel) | ||||||
|
||||||
# sort circle points and resample to desired number of points (az_len) | ||||||
pts = _sort_circ(pts, center = dem_pixel, az_len = az_len) | ||||||
x0,y0 = dem_pixel | ||||||
pts = _sort_circ(pts, center=dem_pixel, az_len=az_len) | ||||||
x0, y0 = dem_pixel | ||||||
profile = np.zeros(azimuth.shape) | ||||||
elevation_angles = np.zeros(azimuth.shape) | ||||||
x_bound, y_bound = elevation.shape | ||||||
|
@@ -288,15 +300,14 @@ def horizon_map(dem_pixel, dem_path, dem_res = 30.0, | |||||
rr, cc = line(source_lon, source_lat, target_lon, target_lat) | ||||||
|
||||||
# get the highest elevation on the line | ||||||
elvs = elevation[rr, cc] | ||||||
elvs_on_line = elevation[rr,cc] | ||||||
idx = np.stack((rr, cc), axis = -1) | ||||||
elvs_on_line = elevation[rr, cc] | ||||||
idx = np.stack((rr, cc), axis=-1) | ||||||
highest_elv = np.max(elvs_on_line) | ||||||
highest_point = idx[np.argmax(elvs_on_line)] | ||||||
high_x, high_y = tuple(highest_point) | ||||||
|
||||||
# convert from altitude in m to elevation degrees. | ||||||
xdist = np.abs(highest_point[0] - x0) | ||||||
xdist = np.abs(highest_point[0]-x0) | ||||||
ydist = highest_elv - elevation[y0][x0] | ||||||
elv_ang = np.arctan(ydist/xdist) | ||||||
bgpierc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
elevation_angles[az] = np.rad2deg(elv_ang) | ||||||
|
@@ -448,4 +459,4 @@ def dni_horizon_adjustment(horizon_angles, solar_zenith, solar_azimuth): | |||||
horizon_zenith = 90 - horizon_angles[rounded_solar_azimuth] | ||||||
mask = solar_zenith > horizon_zenith | ||||||
adjustment[mask] = 0 | ||||||
return adjustment | ||||||
return adjustment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add the unit and sign convention? I assume latitude, longitude are degrees.decimal degrees and negative longitude is west of the prime meridian. This info may be better in a Notes section than in the description of the output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, your assumption is correct, I added it to be explicit.