util.py¶
-
lib.util.
arccosd
(digit)¶ This function calculates the inverse cosine of a number.
- Parameters
digit (float) – Number between -1 and 1.
- Returns
The inverse cosine of the number in degrees.
- Return type
float
-
lib.util.
arcsind
(digit)¶ This function calculates the inverse sine of a number.
- Parameters
digit (float) – Number between -1 and 1.
- Returns
The inverse sine of the number in degrees.
- Return type
float
-
lib.util.
arctand
(digit)¶ This function calculates the inverse tangent of a number.
- Parameters
digit (float) – Number.
- Returns
The inverse tangent of the number in degrees.
- Return type
float
-
lib.util.
changeExt2tif
(filepath)¶ This function changes the extension of a file path to .tif.
- Parameters
filepath (str) – Path to the file.
- Returns
New path with .tif as extension.
- Return type
str
-
lib.util.
changem
(A, newval, oldval)¶ This function replaces existing values oldval in a data array A by new values newval.
oldval and newval must have the same size.
- Parameters
A (numpy array) – Input matrix.
newval (numpy array) – Vector of new values to be set.
oldval (numpy array) – Vector of old values to be replaced.
- Return Out
The updated array.
- Return type
numpy array
-
lib.util.
char_range
(c1, c2)¶ This function creates a generator to iterate between the characters c1 and c2, including the latter.
- Parameters
c1 (char) – First character in the iteration.
c2 (char) – Last character in the iteration (included).
- Returns
Generator to iterate between the characters c1 and c2.
- Return type
python generator
-
lib.util.
cosd
(alpha)¶ This function calculates the cosine of an angle in degrees.
- Parameters
alpha (float) – Angle in degrees.
- Returns
The cosine of the angle.
- Return type
float
-
lib.util.
create_json
(filepath, param, param_keys, paths, paths_keys)¶ Creates a metadata JSON file containing information about the file in filepath by storing the relevant keys from both the param and path dictionaries.
- Parameters
filepath (string) – Path to the file for which the JSON file will be created.
param (dict) – Dictionary of dictionaries containing the user input parameters and intermediate outputs.
param_keys (list of strings) – Keys of the parameters to be extracted from the param dictionary and saved into the JSON file.
paths (dict) – Dictionary of dictionaries containing the paths for all files.
paths_keys (list of strings) – Keys of the paths to be extracted from the paths dictionary and saved into the JSON file.
- Returns
The JSON file will be saved in the desired path filepath.
- Return type
None
-
lib.util.
display_progress
(message, progress_stat)¶ This function displays a progress bar for long computations. To be used as part of a loop or with multiprocessing.
- Parameters
message (string) – Message to be displayed with the progress bar.
progress_stat (tuple(int, int)) – Tuple containing the total length of the calculation and the current status or progress.
- Returns
The status bar is printed.
- Return type
None
-
lib.util.
field_exists
(field_name, shp_path)¶ This function returns whether the specified field exists or not in the shapefile linked by a path.
- Parameters
field_name (str) – Name of the field to be checked for.
shp_path (str) – Path to the shapefile.
- Returns
True
if it exists orFalse
if it doesn’t exist.- Return type
bool
-
lib.util.
hourofmonth
()¶ This function calculates the rank within a year of the first hour of each month.
- Returns
The rank of the first hour of each month.
- Return type
list
-
lib.util.
ind2sub
(array_shape, ind)¶ This function converts linear indices to subscripts.
- Parameters
array_shape (tuple (int, int)) – Dimensions of the array (# of rows, # of columns).
ind – Linear index.
- Returns
Tuple of indices in each dimension (row index, column index).
- Return type
tuple(int, int)
-
lib.util.
intersection
(lst1, lst2)¶ This function calculates the intersection between two lists.
- Parameters
lst1 (list) – First list of elements.
lst2 (list) – Second list of elements.
- Return lst3
The unique elements that exist in both lists, without repetition.
- Return type
list
-
lib.util.
limit_cpu
(check)¶ This functions sets the priority of a process for CPU time and RAM allocation at two levels: average or below average.
- Parameters
check (boolean) – If
True
, the process is set a below average priority rating allowing other programs to run undisturbed. ifFalse
, the process is given the same priority as all other user processes currently running on the machine, leading to faster calculation times.- Returns
The priority of the process is set.
- Return type
None
-
lib.util.
resizem
(A_in, row_new, col_new)¶ This function resizes regular data grid, by copying and pasting parts of the original array.
- Parameters
A_in (numpy array) – Input matrix.
row_new (integer) – New number of rows.
col_new (integer) – New number of columns.
- Return A_out
Resized matrix.
- Return type
numpy array
-
lib.util.
sind
(alpha)¶ This function calculates the sine of an angle in degrees.
- Parameters
alpha (float) – Angle in degrees.
- Returns
The sine of the angle.
- Return type
float
-
lib.util.
sumnorm_MERRA2
(A, m, n, res_low, res_desired)¶ This function calculates the average of high resolution data if it is aggregated into a lower resolution.
- Parameters
A (numpy array) – High-resolution data.
m (int) – Number of rows in the low resolution.
n (int) – Number of columns in the low resolution.
res_low (numpy array) – Numpy array with with two numbers. The first number is the resolution in the vertical dimension (in degrees of latitude), the second is for the horizontal dimension (in degrees of longitude).
res_desired (numpy array) – Numpy array with with two numbers. The first number is the resolution in the vertical dimension (in degrees of latitude), the second is for the horizontal dimension (in degrees of longitude).
- Return s
Aggregated average of A on the low resolution.
- Return type
numpy array
-
lib.util.
tand
(alpha)¶ This function calculates the tangent of an angle in degrees.
- Parameters
alpha (float) – Angle in degrees.
- Returns
The tangent of the angle.
- Return type
float
-
lib.util.
timecheck
(*args)¶ This function prints information about the progress of the script by displaying the function currently running, and optionally an input message, with a corresponding timestamp. If more than one argument is passed to the function, it will raise an exception.
- Parameters
args (string) – Message to be displayed with the function name and the timestamp (optional).
- Returns
The time stamp is printed.
- Return type
None
- Raise
Too many arguments have been passed to the function, the maximum is only one string.