Skip to content

Commit

Permalink
Merge pull request #104 from NASA-AMMOS/aux-updates
Browse files Browse the repository at this point in the history
Minor updates to auxiliary and other helper scripts
  • Loading branch information
jtroberts authored Sep 14, 2021
2 parents 41a54e9 + 3ee5f16 commit 991e01c
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 21 deletions.
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ Missions
Missions_rel
Missions_dev
.env
**/.git
**/.git
data
*DS_Store
*__pycache__
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
/src/pre/tools.js

/build/*
/data/*
*__pycache__

sessions

Expand Down
11 changes: 8 additions & 3 deletions auxiliary/bulk_tiles/bulk_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ def process_tiffs(input_dir, process_dir, colormap_dir, legends_dir, prefix=''):
colormap_key = os.path.basename(colormap_file).split('_')[1].split('.')[0]
colormap_dict[colormap_key] = colormap_file
else:
print('Error: ' + colormap_dir + ' directory does not exist')
sys.exit()
print('Warning: ' + colormap_dir + ' directory does not exist')
print('Processing without colormap')
# sys.exit()
if not os.path.exists(process_dir):
os.makedirs(process_dir)
for input_file in input_files:
Expand Down Expand Up @@ -203,6 +204,10 @@ def create_configs(output_dirs, json_config, prefix):

# Generate JSON layer configurations if specified
if args.json_config is not None:
create_configs(output_dirs, args.json_config, args.prefix)
if args.prefix != '':
json_config = args.json_config.replace('.json', '_' + args.prefix + '.json')
else:
json_config = args.json_config
create_configs(output_dirs, json_config, args.prefix)

sys.exit()
4 changes: 2 additions & 2 deletions auxiliary/rasterstotiles/rasterstotiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ def tile(raster, outputDir=None):
# reproject to EPSG:4326 if it's a projection we can't handle downstream
projection = osr.SpatialReference(wkt=ds.GetProjection()).GetName()
if projection == "unnamed":
gdal_warp = "gdalwarp -t_srs EPSG:4326 " + raster + " " + raster[:-4] + "_espg4326" + raster[-4:]
gdal_warp = "gdalwarp -t_srs EPSG:4326 " + raster + " " + raster[:-4] + "_epsg4326" + raster[-4:]
print(gdal_warp)
raster = raster[:-4] + "_espg4326" + raster[-4:]
raster = raster[:-4] + "_epsg4326" + raster[-4:]
gdal_warp_process = subprocess.Popen(gdal_warp, shell=True)
gdal_warp_process.wait()
ds = gdal.Open(raster)
Expand Down
20 changes: 10 additions & 10 deletions auxiliary/rastertolegend/color_relief_slope.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
95 158 1 66
85 213 62 79
75 244 109 67
65 253 174 97
55 254 224 139
45 230 245 152
35 171 221 164
25 102 194 165
15 50 136 189
5 94 79 162
95% 158 1 66
85% 213 62 79
75% 244 109 67
65% 253 174 97
55% 254 224 139
45% 230 245 152
35% 171 221 164
25% 102 194 165
15% 50 136 189
5% 94 79 162
nv 0 0 0 0
67 changes: 64 additions & 3 deletions private/api/great_circle_calculator/great_circle_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,82 @@
_degrees_to_radians
from .__error_checking import _error_check_point
from ._constants import *
from math import atan
from math import atan2
from math import cos
from math import radians
from math import sin
from math import sqrt
from math import tan


def distance_between_points(p1, p2, unit='meters', haversine=True):
def distance_between_points(p1, p2, unit='meters', haversine=True, vincenty=False):
""" This function computes the distance between two points in the unit given in the unit parameter. It will
calculate the distance using the haversine unless the user specifies haversine to be False. Then law of cosines
will be used
:param p1: tuple point of (lon, lat)
:param p2: tuple point of (lon, lat)
:param unit: unit of measurement. List can be found in constants.eligible_units
:param haversine: True (default) uses haversine distance, False uses law of cosines
:param vincenty: False (default) uses vincenty distance, False haversine
:return: Distance between p1 and p2 in the units specified.
"""
lon1, lat1 = _point_to_radians(_error_check_point(p1))
lon2, lat2 = _point_to_radians(_error_check_point(p2))
r_earth = getattr(radius_earth, unit, 'meters')


if vincenty: # from https://nathanrooy.github.io/posts/2016-12-18/vincenty-formula-with-python/

maxIter=200
tol=10**-12
a=6378137.0 # radius at equator in meters (WGS-84)
f=1/298.257223563 # flattening of the ellipsoid (WGS-84)
b=(1-f)*a

phi_1,L_1,=[lon1, lat1] # (lat=L_?,lon=phi_?)
phi_2,L_2,=[lon2, lat2]

u_1=atan((1-f)*tan(radians(phi_1)))
u_2=atan((1-f)*tan(radians(phi_2)))

L=radians(L_2-L_1)

Lambda=L # set initial value of lambda to L

sin_u1=sin(u_1)
cos_u1=cos(u_1)
sin_u2=sin(u_2)
cos_u2=cos(u_2)

#--- BEGIN ITERATIONS -----------------------------+
iters=0
for i in range(0,maxIter):
iters+=1

cos_lambda=cos(Lambda)
sin_lambda=sin(Lambda)
sin_sigma=sqrt((cos_u2*sin(Lambda))**2+(cos_u1*sin_u2-sin_u1*cos_u2*cos_lambda)**2)
cos_sigma=sin_u1*sin_u2+cos_u1*cos_u2*cos_lambda
sigma=atan2(sin_sigma,cos_sigma)
sin_alpha=(cos_u1*cos_u2*sin_lambda)/sin_sigma
cos_sq_alpha=1-sin_alpha**2
cos2_sigma_m=cos_sigma-((2*sin_u1*sin_u2)/cos_sq_alpha)
C=(f/16)*cos_sq_alpha*(4+f*(4-3*cos_sq_alpha))
Lambda_prev=Lambda
Lambda=L+(1-C)*f*sin_alpha*(sigma+C*sin_sigma*(cos2_sigma_m+C*cos_sigma*(-1+2*cos2_sigma_m**2)))

# successful convergence
diff=abs(Lambda_prev-Lambda)
if diff<=tol:
break

u_sq=cos_sq_alpha*((a**2-b**2)/b**2)
A=1+(u_sq/16384)*(4096+u_sq*(-768+u_sq*(320-175*u_sq)))
B=(u_sq/1024)*(256+u_sq*(-128+u_sq*(74-47*u_sq)))
delta_sig=B*sin_sigma*(cos2_sigma_m+0.25*B*(cos_sigma*(-1+2*cos2_sigma_m**2)-(1/6)*B*cos2_sigma_m*(-3+4*sin_sigma**2)*(-3+4*cos2_sigma_m**2)))

return b*A*(sigma-delta_sig) # output distance in meters

if haversine:
# Haversine
d_lat, d_lon = lat2 - lat1, lon2 - lon1
Expand Down Expand Up @@ -88,7 +149,7 @@ def intermediate_point(p1, p2, fraction=0.5):
"""
lon1, lat1 = _point_to_radians(_error_check_point(p1))
lon2, lat2 = _point_to_radians(_error_check_point(p2))
delta = distance_between_points(p1, p2) / radius_earth.meters
delta = distance_between_points(p1, p2, vincenty=False) / radius_earth.meters
a = sin((1 - fraction) * delta) / sin(delta)
b = sin(fraction * delta) / sin(delta)
x = a * cos(lat1) * cos(lon1) + b * cos(lat2) * cos(lon2)
Expand Down
5 changes: 5 additions & 0 deletions run/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,11 @@ setups.getBackendSetups(function (setups) {
app.get("/docs", ensureUser(), ensureGroup(permissions.users), (req, res) => {
res.render("docs", {});
});

//help
app.get("/help", ensureUser(), ensureGroup(permissions.users), (req, res) => {
res.render("help", {});
});

// API
//TEST
Expand Down
11 changes: 9 additions & 2 deletions src/essence/Basics/Map_/Map_.js
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,13 @@ function makeLayer(layerObj) {
feature.style.fillopacity != null
? feature.style.fillopacity
: fiO

// Check for radius property if radius=1 (default/prop:radius)
layerObj.style.radius =
layerObj.radius == 1
? parseFloat(feature.properties['radius'])
: layerObj.radius

var noPointerEventsClass =
feature.style && feature.style.nointeraction
? ' noPointerEvents'
Expand Down Expand Up @@ -1095,8 +1102,8 @@ function makeLayer(layerObj) {
icon: L.divIcon({
className: 'leafletMarkerShape',
iconSize: [
(layerObj.radius + pixelBuffer) * 2,
(layerObj.radius + pixelBuffer) * 2,
(featureStyle.radius + pixelBuffer) * 2,
(featureStyle.radius + pixelBuffer) * 2,
],
html: svg,
}),
Expand Down

0 comments on commit 991e01c

Please sign in to comment.