Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions GEMstack/mathutils/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ def point_segment_distance(x,a,b) -> Tuple[float,float]:
udotv = np.dot(u,v)
if udotv < 0:
return vector_norm(u),0
elif udotv > vnorm:
elif udotv > vnorm**2:
return vector_norm(vector_sub(x,b)),1
else:
param = udotv/vnorm
return vector_norm(vector_sub(u,vector_mul(v,param/vnorm))),param
param = udotv/vnorm**2
return vector_norm(vector_sub(u,vector_mul(v,param))),param

def rotate2d(point, angle : float, origin=None):
"""Rotates a point about the origin by an angle"""
Expand Down
22 changes: 16 additions & 6 deletions GEMstack/utils/settings.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import json
from ..knowledge import defaults
import copy
from typing import List,Union,Any

SETTINGS = None

def load_settings():
def load_settings(settings_file : str = None):
"""Loads the settings object for the first time.

Order of operations is to look into defaults.SETTINGS, and then
look through the command line arguments to determine whether the user has
overridden any settings using --KEY=VALUE.
Order of operations is:
- If settings_file is given, load it.
- Otherwise, get the settings from defaults.SETTINGS
- Look through the command line arguments to determine whether the user has
overridden any settings using --KEY=VALUE.
"""
global SETTINGS
if SETTINGS is not None:
return
import os
import sys
SETTINGS = copy.deepcopy(defaults.SETTINGS)
if settings_file is not None:
from .config import load_config_recursive
import os
print("**************************************************************")
print("Loading global settings from",settings_file)
print("**************************************************************")
SETTINGS = load_config_recursive(os.path.abspath(settings_file))
else:
from ..knowledge import defaults
SETTINGS = copy.deepcopy(defaults.SETTINGS)
for arg in sys.argv:
if arg.startswith('--'):
k,v = arg.split('=',1)
Expand Down
12 changes: 9 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@
import sys

if __name__=='__main__':
#check for settings override
for arg in sys.argv[1:]:
if arg.startswith('--settings='):
settings.load_settings(arg[11:])
break
#get launch file
launch_file = None
for arg in sys.argv[1:]:
if arg.startswith('--run='):
launch_file = arg[9:]
launch_file = arg[6:]
break
elif not arg.startswith('--'):
launch_file = arg
break
if launch_file is None:
runconfig = settings.get('run',None)
if runconfig is None:
print("Usage: python3 [--key1=value1 --key2=value2] LAUNCH_FILE.yaml")
print(" Current settings are found in knowledge/defaults/current.yaml")
print("Usage: python3 [--key1=value1 --key2=value2] [--settings=SETTINGS_OVERRIDE.yaml] LAUNCH_FILE.yaml")
print(" Default settings are found in knowledge/defaults/current.yaml")
exit(1)
else:
print("Using default run configuration in knowledge/defaults/current.yaml")
Expand Down
Loading