import numpy as np
import xarray as xr
# ----------------------------------------------------------------------------------------------------------------------
[docs]
def yesno(text):
'''
Function to interact with the terminal and decide for different options when running ForMoSA (Loop to repeat question if answer is different to 'y' or 'n).
Args:
text (str): (y/n) answer in the terminall in interactive mode
Returns:
asw (str): answer y or n
Author: Simon Petrus
'''
print(text)
asw = input()
if asw in ['y', 'n']:
return asw
else:
return yesno()
# ----------------------------------------------------------------------------------------------------------------------
[docs]
def decoupe(second):
"""
Re-arranged a number of seconds in the hours-minutes-seconds format.
Args:
second (float): number of second
Returns:
- float : hours
- float : minutes
- float : seconds
Author: Simon Petrus
"""
hour = second / 3600
second %= 3600
minute = second / 60
second %= 60
return hour, minute, second
# ----------------------------------------------------------------------------------------------------------------------
[docs]
def find_nearest(array, value):
"""
Return the indice of the closest values from a desire value in an array.
Args:
array (array): Array to explore
value (float): Desire value
Returns:
- idx (int) : Indice of the closest values from the desire value
Author: Simon Petrus
"""
idx = (np.abs(array - value)).argmin()
return idx
# ----------------------------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------