PLOTTING UTILITY FUNCTIONS

created on October 27th 2021 by M. Reichmann

Base Directory

The analysis and conversion scripts need to know out where the config files (i.e. main.ini) are located and where to store the process data. For the pip installed packages an ANALYSIS_DIR variable should be set before starting the script.

Global External Variables

Global Internal Variables

Currently Unused Global Variable

print(f'{GREEN}green {RED} red {ENDC}no color {CYAN} cyan {ENDC} no color {WHITE} white {ENDC} no color {UP1} up1 {ERASE} erase {ENDC} no color {YELLOW} yellow')
green  red no color  cyan  no color  white  no color  up1  erase  no color  yellow

source

get_t_str

 get_t_str ()

returns current hour:minute:second

Example:

get_t_str()
'09:05:31'

source

colored

 colored (txt, color=None)

returns colored text for printing, resetting the color at the end

Examples:

print(colored('I am red', RED))
print(colored('I am green', GREEN))
print(colored('I am cyan', CYAN))
I am red
I am green
I am cyan

source

prnt_msg

 prnt_msg (txt:str, head:str='', color=None, blank_lines:int=0,
           endl:bool=True, prnt:bool=True)

prints the message with a header of a certain color and a current time stamp

Type Default Details
txt str message to print
head str Header to the message
color NoneType None Color of the header
blank_lines int 0 number of blank lines before the message
endl bool True add end line charachter
prnt bool True print the message?
prnt_msg("No news is a good news", 'NEWS', GREEN, 1 )

NEWS:     16:43:40 --> No news is a good news

source

info

 info (txt:str, blank_lines:int=0, endl:bool=True, prnt:bool=True)

prints out message with a green INFO heading and a current time stamp.

Returns current time

Type Default Details
txt str message to print
blank_lines int 0 number of blank lines to follow
endl bool True add end line charachter
prnt bool True print the message?
info("No info at this time")
INFO:     16:43:40 --> No info at this time
1686667420.451434

source

add_to_info

 add_to_info (t:float, msg:str='Done', color=None, prnt:bool=True)

Prints colored message and a time difference between the inputed time and current time

Type Default Details
t float time in float point format since the Epoch
msg str Done Message to print
color NoneType None
prnt bool True
add_to_info(1686581447, 'Done', GREEN)
Done (85973.46 s)

source

warning

 warning (txt:str, blank_lines:int=0, prnt=True)

Prints yellow colored warning message with a timestamp

Type Default Details
txt str warning to print
blank_lines int 0 number of bank lines to follow
prnt bool True print?
warning("This is the last warning!")
WARNING:  16:43:40 --> This is the last warning!

source

critical

 critical (txt)

source

get_stat

 get_stat (status)

returns the state of Draw class options


source

choose

 choose (v, default, decider='None', *args, **kwargs)

Returns the first object if the decider not None and the object itself is not None, otherwise returns the second default element, optionally passes arguments if the returned object is a function

Type Default Details
v first object
default default object
decider str None Decider
args
kwargs

usage examples:

First object not None so choose it

choose('2018', '2019')
'2018'

The first object is None so choose the default second object, since the decider is None

choose(None, '2018')
'2018'

The first object is None but the decider is not so choose the first object

print(choose(None, '2018', 1))
None

source

round_up_to

 round_up_to (num, val:int=1)

rounds up an int or float to a digit indicacted by val

Type Default Details
num number to round up
val int 1 the order to which round up 1, 10, 100, …

example:

round_up_to(44334.444, 100)
44400

source

do

 do (fs, pars, exe=-1)

source

do_nothing

 do_nothing ()

source

is_iter

 is_iter (v)

source

is_ufloat

 is_ufloat (value)

source

uarr2n

 uarr2n (x)

source

uarr2s

 uarr2s (arr)

source

arr2u

 arr2u (x, ex)

source

add_err

 add_err (u, e)

source

add_perr

 add_perr (u, e)

source

eff2u

 eff2u (eff)

source

make_ufloat

 make_ufloat (n, s=0)

source

make_list

 make_list (value)

source

prep_kw

 prep_kw (dic, **default)

source

get_kw

 get_kw (kw, kwargs, default=None)

source

rm_key

 rm_key (d, *key)

source

mean_sigma

 mean_sigma (values, weights=None, err=True)

Return the weighted average and standard deviation. values, weights – Numpy ndarrays with the same shape.


source

calc_eff

 calc_eff (k=0, n=0, values=None)

source

cart2pol

 cart2pol (x, y)

source

pol2cart

 pol2cart (rho, phi)

source

get_x

 get_x (x1, x2, y1, y2, y)

source

get_y

 get_y (x1, x2, y1, y2, x)

source

ensure_dir

 ensure_dir (path)

source

remove_file

 remove_file (*file_path, string=None, warn=True)

source

correlate

 correlate (l1, l2)

source

add_spaces

 add_spaces (s)

source

sum_times

 sum_times (t, fmt='%H:%M:%S')

source

load_json

 load_json (filename)

source

Config

 Config (file_name:str, section:str=None, from_json:bool=False,
         required:bool=False, **kwargs)

ConfigParser implementing interpolation.

Type Default Details
file_name str Path to the config file
section str None section in the config file
from_json bool False load config from a json file
required bool False If the config file is required then throw an error if the file doesn’t exist
kwargs

source

AsymVar

 AsymVar (value, err_down, err_up, fmt='.2f')

Initialize self. See help(type(self)) for accurate signature.


source

aufloat

 aufloat (n, s0=0, s1=0)

source

add_asym_error

 add_asym_error (v, s0=0, s1=0)

source

download_file

 download_file (server:str, loc:str, target:str, out:bool=True)

Downloads a file using rsync in archive mode a, transforming symlinks into referent file L keeping partialy transfered files and displaying the progress P. Increased verbosity v

Type Default Details
server str remote_host/server address where the file is located
loc str path/to/remote_file on the server
target str path/to/local_directory
out bool True print out the progress is True