Strumenti Package - Application Program Interface¶
coordinate¶
Modules contains functions for converting coordinate systems.
-
element_dimension(array: <Mock name='mock.ndarray' id='139887133442568'>, values: typing.Union[int, typing.List[int]]) → int[source]¶ Return the element dimension for array if dimension matches values.
Parameters: - array (ndarray) – numpy array to test
- values – value or values of desired element dimension
Type: int or list of ints
Returns: element dimension of array
Return type: int
Raises: IndexError or ValueError
>>> element_dimension(np.array([[1, 2, 3], [4, 5, 6]]), [2, 3]) 3
>>> element_dimension(np.array([[1, 2, 3], [4, 5, 6]]), 3) 3
-
cart2pol(pts: <Mock name='mock.ndarray' id='139887133442568'>, degrees: bool = False) → <Mock name='mock.ndarray' id='139887133442568'>[source]¶ Convert Cartesian coordinates to polar or cylindrical coordinates.
Parameters: - pts (ndarray) – array of Cartesian points (x, y) or (x, y, z)
- degrees (bool) – if true results will be presented in degrees (default: False)
Returns: [radial distance rho, azimuthal angle theta, (vertical distance z)]
Return type: ndarray
>>> cart2pol(np.array([[0, 1], [-2, 0]]), degrees=True) array([[ 1., 90.], [ 2., 180.]])
>>> cart2pol(np.array([[0.5, -0.5, 4]]), degrees=True) array([[ 0.70710678, -45. , 4. ]])
-
cart2sphere(pts: <Mock name='mock.ndarray' id='139887133442568'>, degrees: bool = False) → <Mock name='mock.ndarray' id='139887133442568'>[source]¶ Convert Cartesian coordinates to spherical coordinates.
Parameters: - pts (ndarray) – array of Cartesian points (x, y, z)
- degrees (bool) – if true results will be presented in degrees (default: False)
Returns: [radial distance r, azimuthal angle theta, polar angle phi]
Return type: ndarray
>>> cart2sphere(np.array([[1, 0, 0], [1, 1, 1]]), degrees=True) array([[ 1. , 0. , 90. ], [ 1.73205081, 45. , 54.73561032]])
-
pol2cart(pts: <Mock name='mock.ndarray' id='139887133442568'>, degrees: bool = False) → <Mock name='mock.ndarray' id='139887133442568'>[source]¶ Convert polar or cylindrical coordinates to Cartesian coordinates.
Parameters: - pts (ndarray) – array of polar points (rho, theta) or cylindrical points (rho, theta, phi)
- degrees (bool) – if true results will be presented in degrees (default: False)
Returns: [x, y, (z)]
Return type: ndarray
>>> pol2cart(np.array([[2**0.5, 45], [1, 90]]), degrees=True) array([[ 1.00000000e+00, 1.00000000e+00], [ 6.12323400e-17, 1.00000000e+00]])
>>> pol2cart(np.array([[2**0.5, 45, 1], [1, 90, 2]]), degrees=True) array([[ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00], [ 6.12323400e-17, 1.00000000e+00, 2.00000000e+00]])
-
sphere2cart(pts: <Mock name='mock.ndarray' id='139887133442568'>, degrees: bool = False) → <Mock name='mock.ndarray' id='139887133442568'>[source]¶ Convert spherical coordinates to Cartesian coordinates.
Parameters: - pts (ndarray) – array of spherical coordinates
- degrees (bool) – if true results will be presented in degrees (default: False)
Returns: [x, y, z]
Return type: ndarray
>>> sphere2cart(np.array([[1, 0, 90], [1, 90, 90]]), degrees=True) array([[ 1.00000000e+00, 0.00000000e+00, 6.12323400e-17], [ 6.12323400e-17, 1.00000000e+00, 6.12323400e-17]])
notify¶
Notify Module
Functions for notifying the user are contained in this module.
-
astrix_line(qty: int = 80) → str[source]¶ Return break line of astrix characters.
Parameters: qty (int) – number of * characters to be returned Returns: - characters and a line break
Return type: str
-
center(statement: str, fill: str = '=', width: int = 60) → str[source]¶ Return statement centered by spaces and fill characters.
Parameters: - statement (str) – statement to be returned
- fill (str) – fill character to be used (default: =)
- width (int) – total width of output string (default: 60)
Returns: statement centered on line surrounded by fill characters
Return type: str
-
header(statement: str) → str[source]¶ Return a line of asterisks two blank lines and the header statement.
Parameters: statement (str) – header statement Returns: formatted header statement Return type: str
Return two blank lines the footer statement then a row of asterisks.
Parameters: statement (str) – footer statement Returns: formatted footer statement Return type: str
-
section_break(qty: int = 2) → str[source]¶ Return multiple line break characters.
Parameters: qty (int) – number of line break characters (default: 2) Returns: multiple new line characters Return type: str
-
status(statement: str, fill: str = '-', width: int = 40) → str[source]¶ Return intermediary statements.
Parameters: - statement (str) – statement to be returned
- fill (str) – fill character to be used (default: -)
- width (int) – total width of output string (default: 40)
Returns: formatted status statement
Return type: str
packages¶
Package Module
Utilities for managing Python packages.
-
class
Manage[source]¶ Bases:
objectClass will assist with managing Python packages.
Attributes: - outdated: dict outdated packages
- packages: dict all packages
- req_txt_path: str path to the file containing all package version requirements
- wheels: list path to all wheels generated by installing packages (this includes all dependencies)
- wheel_path: str path to the temporary wheelhouse directory
-
create_wheels(packages: ([<class 'str'>], [<class 'tuple'>], [<class 'list'>]))[source]¶ Create wheels for packages.
Parameters: packages – names of packages to upgrade Type: str tuple list
-
list_packages(outdated: bool = False)[source]¶ Get information on installed packages.
Parameters: outdated (bool) – if True only outdated packages will be retrieved
-
static
install_packages(packages: typing.Iterable, upgrade: bool = True)[source]¶ Install Python packages.
Note
The argument packages can be a list of package names as strings or tuples of package names with desired versions to be installed.
- List of Strings example:
- [‘numpy’, ‘scipy’]
- List of Tuples example:
- [(‘numpy’, ‘1.10.4’), (‘scipy’, ‘0.16.1’)]
Parameters: - packages (iterable) – packages to install
- upgrade (bool) – set to True if package is already installed and the version is being upgraded or False if a new package is being installed
plot¶
Plotting Module
Functions for performing tasks related to matplotlib pyplot library.
-
axis_title(title: str, units: typing.Union[str, NoneType] = None) → str[source]¶ Create string for axis title with units italicized.
Parameters: - title (str) – title of axis
- units (str) – units of axis (default: None)
Returns: formatted axis title
Return type: str
-
class
Derivative(x_points: <Mock name='mock.ndarray' id='139887133442568'>, y_points: <Mock name='mock.ndarray' id='139887133442568'>)[source]¶ Bases:
objectPlot data, 1st derivative and 2nd derivative using central difference.
Parameters: - x (ndarray) – data points for x-axis
- y (ndarray) – data points for y-axis
Attributes:
- dx: ndarray derivative of x-axis data points
- dy: ndarray derivative of y-axis data points
- ddy: ndarray 2nd derivative of y-axis data points
- plot_name: str if non None value is supplied plot file will be saved
- label_size: int axis label font size
- title_size: int title font size
- title: str plot title
- x: ndarray x-axis data points
- x_label: str x-axis label
- y: ndarray y-axis data points
- y_label: str y-axis label
psql¶
PostgreSQL Module
Utilities for interfacing with PostgreSQL databases.
-
connection(db_name: str, user: str, password: str) → <Mock name='mock.extensions.cursor' id='139887132278288'>[source]¶ Connect to PostgreSQL database and establish a cursor.
Parameters: - db_name (str) – database name
- user (str) – database user name
- password (str) – database user password
Returns: cursor to PostgreSQL database
Return type: psycopg2.extensions.cursor
-
table_create(name: str, schema: typing.List[str], serial: bool = False, unique: typing.Union[typing.List[str], NoneType] = None) → str[source]¶ Return command to create a table in a PostgreSQL database.
Parameters: - name (str) – name of table
- schema (list) – schema of table provided in name data type pairs [‘n_1, dt_1’, ‘n_2, dt_2’]
- serial (bool) – a serialized index will be created for the table and used as the primary key if True
- unique (list) – field names that define a unique record for the table
Returns: command to create a table
Return type: str
-
table_drop(name: str) → str[source]¶ Return command to drop a table from a PostgreSQL database.
Parameters: name (str) – name of table to drop Returns: command to remove table from database Return type: str
-
table_insert(name: str, field_names: typing.Union[str, typing.List[str]]) → str[source]¶ Return command to add a record into a PostgreSQL database.
Parameters: - name (str) – name of table to append
- field_names – names of fields
Type: str or list
Returns: command to append records to a table
Return type: str
Example:
import psql
cur = psql.connection(‘db’, ‘user’, ‘password’) [cur.execute(psql.table_insert(‘table’, ‘field’), (x, )) for x in values]
-
table_select(table_name: str, return_field: str = '*', search_field: typing.Union[str, NoneType] = None) → str[source]¶ Return values from a Postgres table with a given search value.
Parameters: - table_name (str) – name of table to search
- return_field (str) – field to return from table query (default: * will return all table fields)
- search_field (str) – field to search for value in table (default: None will return all table values)
Returns: value corresponding to requested field
Return type: str
Example:
import psql
cur = psql.connection(‘db’, ‘user’, ‘password’) [cur.execute(psql.table_select(‘table’, search_field=’idx’), (x, )) for x in values]