Skip to content

Commit

Permalink
Merge pull request #1330 from knutfrode/dev
Browse files Browse the repository at this point in the history
Raising now error instead of warning if all elements are seeded on la…
  • Loading branch information
knutfrode authored Jun 25, 2024
2 parents 6aaece5 + 4b372db commit 3fa90ae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions opendrift/models/basemodel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,8 @@ def closest_ocean_points(self, lon, lat):
time=land_reader.start_time)[0]['land_binary_mask']
if landgrid.min() == 1 or np.isnan(landgrid.min()):
logger.warning('No ocean pixels nearby, cannot move elements.')
if land.min() == 1:
raise ValueError('All elements seeded on land')
return lon, lat

oceangridlons = longrid[landgrid == 0]
Expand Down
14 changes: 11 additions & 3 deletions opendrift/scripts/opendrift_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,9 @@ def __init__(self):
self.text = tk.Text(self.output, wrap="word", height=18)
self.text.grid(row=60, columnspan=6, sticky='nsw')
self.text.tag_configure("stderr", foreground="#b22222")
sys.stdout = TextRedirector(self.text, "stdout")
sys.stderr = TextRedirector(self.text, "stderr")
if os.getenv('OPENDRIFT_GUI_OUTPUT', 'gui') == 'gui':
sys.stdout = TextRedirector(self.text, "stdout")
sys.stderr = TextRedirector(self.text, "stderr")
s = tk.Scrollbar(self)
s.grid(row=60, column=6, sticky='ns')
s.config(command=self.text.yview)
Expand Down Expand Up @@ -567,7 +568,7 @@ def set_model(self, model, rebuild_gui=True):
self.config_input_var[i] = tk.StringVar()
vcmd = (tab.register(self.validate_config),
'%P', '%s', key)
max_length = sc[i].get('max_length') or 12
max_length = sc[key].get('max_length') or 12
max_length = np.minimum(max_length, 64)
self.config_input[i] = tk.Entry(
tab, textvariable=self.config_input_var[i],
Expand Down Expand Up @@ -891,4 +892,11 @@ def main():
OpenDriftGUI().mainloop()

if __name__ == '__main__':

# Add any argument to redirect output to terminal instead of GUI window.
# TODO: must be a better way to pass arguments to Tkinter?
if len(sys.argv) > 1:
os.environ['OPENDRIFT_GUI_OUTPUT'] = 'terminal'
else:
os.environ['OPENDRIFT_GUI_OUTPUT'] = 'gui'
OpenDriftGUI().mainloop()

0 comments on commit 3fa90ae

Please sign in to comment.