odak.tools
odak.tools
Provides necessary definitions for general tools used across the library.
latex
¶
A class to work with latex documents.
Source code in odak/tools/latex.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
__init__(filename)
¶
Parameters:
-
filename
–Source filename (i.e. sample.tex).
Source code in odak/tools/latex.py
get_line(line_id=0)
¶
Definition to get a specific line by inputting a line nunber.
Returns:
-
line
(str
) –Requested line.
-
content_type
(str
) –Line's content type (e.g., latex, comment, text).
Source code in odak/tools/latex.py
get_line_count()
¶
Definition to get the line count.
Returns:
-
line_count
(int
) –Number of lines in the loaded latex document.
set_latex_dictonaries(begin_dictionary, end_dictionary, syntax_dictionary)
¶
Set document specific dictionaries so that the lines could be labelled in accordance.
Parameters:
-
begin_dictionary
–Pythonic list containing latex syntax for begin commands (i.e. \begin{align}).
-
end_dictionary
–Pythonic list containing latex syntax for end commands (i.e. \end{table}).
-
syntax_dictionary
–Pythonic list containing latex syntax (i.e. \item).
Source code in odak/tools/latex.py
markdown
¶
A class to work with markdown documents.
Source code in odak/tools/markdown.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
__init__(filename)
¶
Parameters:
-
filename
–Source filename (i.e. sample.md).
Source code in odak/tools/markdown.py
get_line(line_id=0)
¶
Definition to get a specific line by inputting a line nunber.
Returns:
-
line
(str
) –Requested line.
-
content_type
(str
) –Line's content type (e.g., markdown, comment, text).
Source code in odak/tools/markdown.py
get_line_count()
¶
Definition to get the line count.
Returns:
-
line_count
(int
) –Number of lines in the loaded markdown document.
set_dictonaries(begin_dictionary, end_dictionary, syntax_dictionary)
¶
Set document specific dictionaries so that the lines could be labelled in accordance.
Parameters:
-
begin_dictionary
–Pythonic list containing markdown syntax for beginning of blocks (e.g., code, html).
-
end_dictionary
–Pythonic list containing markdown syntax for end of blocks (e.g., code, html).
-
syntax_dictionary
–Pythonic list containing markdown syntax (i.e. \item).
Source code in odak/tools/markdown.py
batch_of_rays(entry, exit)
¶
Definition to generate a batch of rays with given entry point(s) and exit point(s). Note that the mapping is one to one, meaning nth item in your entry points list will exit from nth item in your exit list and generate that particular ray. Note that you can have a combination like nx3 points for entry or exit and 1 point for entry or exit. But if you have multiple points both for entry and exit, the number of points have to be same both for entry and exit.
Parameters:
-
entry
–Either a single point with size of 3 or multiple points with the size of nx3.
-
exit
–Either a single point with size of 3 or multiple points with the size of nx3.
Returns:
-
rays
(ndarray
) –Generated batch of rays.
Source code in odak/tools/sample.py
blur_gaussian(field, kernel_length=[21, 21], nsigma=[3, 3])
¶
A definition to blur a field using a Gaussian kernel.
Parameters:
-
field
–MxN field.
-
kernel_length
(list
, default:[21, 21]
) –Length of the Gaussian kernel along X and Y axes.
-
nsigma
–Sigma of the Gaussian kernel along X and Y axes.
Returns:
-
blurred_field
(ndarray
) –Blurred field.
Source code in odak/tools/matrix.py
box_volume_sample(no=[10, 10, 10], size=[100.0, 100.0, 100.0], center=[0.0, 0.0, 0.0], angles=[0.0, 0.0, 0.0])
¶
Definition to generate samples in a box volume.
Parameters:
-
no
–Number of samples.
-
size
–Physical size of the volume.
-
center
–Center location of the volume.
-
angles
–Tilt of the volume.
Returns:
-
samples
(ndarray
) –Samples generated.
Source code in odak/tools/sample.py
check_directory(directory)
¶
Definition to check if a directory exist. If it doesn't exist, this definition will create one.
Parameters:
-
directory
–Full directory path.
Source code in odak/tools/file.py
circular_sample(no=[10, 10], radius=10.0, center=[0.0, 0.0, 0.0], angles=[0.0, 0.0, 0.0])
¶
Definition to generate samples inside a circle over a surface.
Parameters:
-
no
–Number of samples.
-
radius
–Radius of the circle.
-
center
–Center location of the surface.
-
angles
–Tilt of the surface.
Returns:
-
samples
(ndarray
) –Samples generated.
Source code in odak/tools/sample.py
circular_uniform_random_sample(no=[10, 50], radius=10.0, center=[0.0, 0.0, 0.0], angles=[0.0, 0.0, 0.0])
¶
Definition to generate sample inside a circle uniformly but randomly.
Parameters:
-
no
–Number of samples.
-
radius
–Radius of the circle.
-
center
–Center location of the surface.
-
angles
–Tilt of the surface.
Returns:
-
samples
(ndarray
) –Samples generated.
Source code in odak/tools/sample.py
circular_uniform_sample(no=[10, 50], radius=10.0, center=[0.0, 0.0, 0.0], angles=[0.0, 0.0, 0.0])
¶
Definition to generate sample inside a circle uniformly.
Parameters:
-
no
–Number of samples.
-
radius
–Radius of the circle.
-
center
–Center location of the surface.
-
angles
–Tilt of the surface.
Returns:
-
samples
(ndarray
) –Samples generated.
Source code in odak/tools/sample.py
closest_point_to_a_ray(point, ray)
¶
Definition to calculate the point on a ray that is closest to given point.
Parameters:
-
point
–Given point in X,Y,Z.
-
ray
–Given ray.
Returns:
-
closest_point
(ndarray
) –Calculated closest point.
Source code in odak/tools/vector.py
convert_bytes(num)
¶
A definition to convert bytes to semantic scheme (MB,GB or alike). Inspired from https://stackoverflow.com/questions/2104080/how-can-i-check-file-size-in-python#2104083.
Parameters:
-
num
–Size in bytes
Returns:
-
num
(float
) –Size in new unit.
-
x
(str
) –New unit bytes, KB, MB, GB or TB.
Source code in odak/tools/file.py
convert_to_numpy(a)
¶
A definition to convert Torch to Numpy.
Parameters:
-
a
–Input Torch array.
Returns:
-
b
(ndarray
) –Converted array.
Source code in odak/tools/conversions.py
convert_to_torch(a, grad=True)
¶
A definition to convert Numpy arrays to Torch.
Parameters:
-
a
–Input Numpy array.
-
grad
–Set if the converted array requires gradient.
Returns:
-
c
(Tensor
) –Converted array.
Source code in odak/tools/conversions.py
convolve2d(field, kernel)
¶
Definition to convolve a field with a kernel by multiplying in frequency space.
Parameters:
-
field
–Input field with MxN shape.
-
kernel
–Input kernel with MxN shape.
Returns:
-
new_field
(ndarray
) –Convolved field.
Source code in odak/tools/matrix.py
copy_file(source, destination, follow_symlinks=True)
¶
Definition to copy a file from one location to another.
Parameters:
-
source
–Source filename.
-
destination
–Destination filename.
-
follow_symlinks
(bool
, default:True
) –Set to True to follow the source of symbolic links.
Source code in odak/tools/file.py
create_empty_list(dimensions=[1, 1])
¶
A definition to create an empty Pythonic list.
Parameters:
-
dimensions
–Dimensions of the list to be created.
Returns:
-
new_list
(list
) –New empty list.
Source code in odak/tools/matrix.py
create_ray_from_two_points(x0y0z0, x1y1z1)
¶
Definition to create a ray from two given points. Note that both inputs must match in shape.
Parameters:
-
x0y0z0
–List that contains X,Y and Z start locations of a ray (3). It can also be a list of points as well (mx3). This is the starting point.
-
x1y1z1
–List that contains X,Y and Z ending locations of a ray (3). It can also be a list of points as well (mx3). This is the end point.
Returns:
-
ray
(ndarray
) –Array that contains starting points and cosines of a created ray.
Source code in odak/raytracing/ray.py
crop_center(field, size=None)
¶
Definition to crop the center of a field with 2Mx2N size. The outcome is a MxN array.
Parameters:
-
field
–Input field 2Mx2N array.
Returns:
-
cropped
(ndarray
) –Cropped version of the input field.
Source code in odak/tools/matrix.py
cross_product(vector1, vector2)
¶
Definition to cross product two vectors and return the resultant vector. Used method described under: http://en.wikipedia.org/wiki/Cross_product
Parameters:
-
vector1
–A vector/ray.
-
vector2
–A vector/ray.
Returns:
-
ray
(ndarray
) –Array that contains starting points and cosines of a created ray.
Source code in odak/tools/vector.py
distance_between_point_clouds(points0, points1)
¶
A definition to find distance between every point in one cloud to other points in the other point cloud.
Parameters:
-
points0
–Mx3 points.
-
points1
–Nx3 points.
Returns:
-
distances
(ndarray
) –MxN distances.
Source code in odak/tools/vector.py
distance_between_two_points(point1, point2)
¶
Definition to calculate distance between two given points.
Parameters:
-
point1
–First point in X,Y,Z.
-
point2
–Second point in X,Y,Z.
Returns:
-
distance
(float
) –Distance in between given two points.
Source code in odak/tools/vector.py
expanduser(filename)
¶
Definition to decode filename using namespaces and shortcuts.
Parameters:
-
filename
–Filename.
Returns:
-
new_filename
(str
) –Filename.
Source code in odak/tools/file.py
generate_2d_gaussian(kernel_length=[21, 21], nsigma=[3, 3])
¶
Generate 2D Gaussian kernel. Inspired from https://stackoverflow.com/questions/29731726/how-to-calculate-a-gaussian-kernel-matrix-efficiently-in-numpy
Parameters:
-
kernel_length
(list
, default:[21, 21]
) –Length of the Gaussian kernel along X and Y axes.
-
nsigma
–Sigma of the Gaussian kernel along X and Y axes.
Returns:
-
kernel_2d
(ndarray
) –Generated Gaussian kernel.
Source code in odak/tools/matrix.py
generate_bandlimits(size=[512, 512], levels=9)
¶
A definition to calculate octaves used in bandlimiting frequencies in the frequency domain.
Parameters:
-
size
–Size of each mask in octaves.
Returns:
-
masks
(ndarray
) –Masks (Octaves).
Source code in odak/tools/matrix.py
grid_sample(no=[10, 10], size=[100.0, 100.0], center=[0.0, 0.0, 0.0], angles=[0.0, 0.0, 0.0])
¶
Definition to generate samples over a surface.
Parameters:
-
no
–Number of samples.
-
size
–Physical size of the surface.
-
center
–Center location of the surface.
-
angles
–Tilt of the surface.
Returns:
-
samples
(ndarray
) –Samples generated.
Source code in odak/tools/sample.py
list_files(path, key='*.*', recursive=True)
¶
Definition to list files in a given path with a given key.
Parameters:
-
path
–Path to a folder.
-
key
–Key used for scanning a path.
-
recursive
–If set True, scan the path recursively.
Returns:
-
files_list
(ndarray
) –list of files found in a given path.
Source code in odak/tools/file.py
load_dictionary(filename)
¶
Definition to load a dictionary (JSON) file.
Parameters:
-
filename
–Filename.
Returns:
-
settings
(dict
) –Dictionary read from the file.
Source code in odak/tools/file.py
load_image(fn, normalizeby=0.0, torch_style=False)
¶
Definition to load an image from a given location as a Numpy array.
Parameters:
-
fn
–Filename.
-
normalizeby
–Value to to normalize images with. Default value of zero will lead to no normalization.
-
torch_style
–If set True, it will load an image mxnx3 as 3xmxn.
Returns:
-
image
(ndarray
) –Image loaded as a Numpy array.
Source code in odak/tools/file.py
nufft2(field, fx, fy, size=None, sign=1, eps=10 ** -12)
¶
A definition to take 2D Non-Uniform Fast Fourier Transform (NUFFT).
Parameters:
-
field
–Input field.
-
fx
–Frequencies along x axis.
-
fy
–Frequencies along y axis.
-
size
–Size.
-
sign
–Sign of the exponential used in NUFFT kernel.
-
eps
–Accuracy of NUFFT.
Returns:
-
result
(ndarray
) –Inverse NUFFT of the input field.
Source code in odak/tools/matrix.py
nuifft2(field, fx, fy, size=None, sign=1, eps=10 ** -12)
¶
A definition to take 2D Adjoint Non-Uniform Fast Fourier Transform (NUFFT).
Parameters:
-
field
–Input field.
-
fx
–Frequencies along x axis.
-
fy
–Frequencies along y axis.
-
size
–Shape of the NUFFT calculated for an input field.
-
sign
–Sign of the exponential used in NUFFT kernel.
-
eps
–Accuracy of NUFFT.
Returns:
-
result
(ndarray
) –NUFFT of the input field.
Source code in odak/tools/matrix.py
point_to_ray_distance(point, ray_point_0, ray_point_1)
¶
Definition to find point's closest distance to a line represented with two points.
Parameters:
-
point
–Point to be tested.
-
ray_point_0
(ndarray
) –First point to represent a line.
-
ray_point_1
(ndarray
) –Second point to represent a line.
Returns:
-
distance
(float
) –Calculated distance.
Source code in odak/tools/vector.py
quantize(image_field, bits=4)
¶
Definitio to quantize a image field (0-255, 8 bit) to a certain bits level.
Parameters:
-
image_field
(ndarray
) –Input image field.
-
bits
–A value in between 0 to 8. Can not be zero.
Returns:
-
new_field
(ndarray
) –Quantized image field.
Source code in odak/tools/matrix.py
random_sample_point_cloud(point_cloud, no, p=None)
¶
Definition to pull a subset of points from a point cloud with a given probability.
Parameters:
-
point_cloud
–Point cloud array.
-
no
–Number of samples.
-
p
–Probability list in the same size as no.
Returns:
-
subset
(ndarray
) –Subset of the given point cloud.
Source code in odak/tools/sample.py
read_PLY(fn, offset=[0, 0, 0], angles=[0.0, 0.0, 0.0], mode='XYZ')
¶
Definition to read a PLY file and extract meshes from a given PLY file. Note that rotation is always with respect to 0,0,0.
Parameters:
-
fn
–Filename of a PLY file.
-
offset
–Offset in X,Y,Z.
-
angles
–Rotation angles in degrees.
-
mode
–Rotation mode determines ordering of the rotations at each axis. There are XYZ,YXZ,ZXY and ZYX modes.
Returns:
-
triangles
(ndarray
) –Triangles from a given PLY file. Note that the triangles coming out of this function isn't always structured in the right order and with the size of (MxN)x3. You can use numpy's reshape to restructure it to mxnx3 if you know what you are doing.
Source code in odak/tools/asset.py
read_PLY_point_cloud(filename)
¶
Definition to read a PLY file as a point cloud.
Parameters:
-
filename
–Filename of a PLY file.
Returns:
-
point_cloud
(ndarray
) –An array filled with poitns from the PLY file.
Source code in odak/tools/asset.py
read_text_file(filename)
¶
Definition to read a given text file and convert it into a Pythonic list.
Parameters:
-
filename
–Source filename (i.e. test.txt).
Returns:
-
content
(list
) –Pythonic string list containing the text from the file provided.
Source code in odak/tools/file.py
resize_image(img, target_size)
¶
Definition to resize a given image to a target shape.
Parameters:
-
img
–MxN image to be resized. Image must be normalized (0-1).
-
target_size
–Target shape.
Returns:
-
img
(ndarray
) –Resized image.
Source code in odak/tools/file.py
rotate_point(point, angles=[0, 0, 0], mode='XYZ', origin=[0, 0, 0], offset=[0, 0, 0])
¶
Definition to rotate a given point. Note that rotation is always with respect to 0,0,0.
Parameters:
-
point
–A point.
-
angles
–Rotation angles in degrees.
-
mode
–Rotation mode determines ordering of the rotations at each axis. There are XYZ,YXZ,ZXY and ZYX modes.
-
origin
–Reference point for a rotation.
-
offset
–Shift with the given offset.
Returns:
-
result
(ndarray
) –Result of the rotation
-
rotx
(ndarray
) –Rotation matrix along X axis.
-
roty
(ndarray
) –Rotation matrix along Y axis.
-
rotz
(ndarray
) –Rotation matrix along Z axis.
Source code in odak/tools/transformation.py
rotate_points(points, angles=[0, 0, 0], mode='XYZ', origin=[0, 0, 0], offset=[0, 0, 0])
¶
Definition to rotate points.
Parameters:
-
points
–Points.
-
angles
–Rotation angles in degrees.
-
mode
–Rotation mode determines ordering of the rotations at each axis. There are XYZ,YXZ,ZXY and ZYX modes.
-
origin
–Reference point for a rotation.
-
offset
–Shift with the given offset.
Returns:
-
result
(ndarray
) –Result of the rotation
Source code in odak/tools/transformation.py
rotmatx(angle)
¶
Definition to generate a rotation matrix along X axis.
Parameters:
-
angle
–Rotation angles in degrees.
Returns:
-
rotx
(ndarray
) –Rotation matrix along X axis.
Source code in odak/tools/transformation.py
rotmaty(angle)
¶
Definition to generate a rotation matrix along Y axis.
Parameters:
-
angle
–Rotation angles in degrees.
Returns:
-
roty
(ndarray
) –Rotation matrix along Y axis.
Source code in odak/tools/transformation.py
rotmatz(angle)
¶
Definition to generate a rotation matrix along Z axis.
Parameters:
-
angle
–Rotation angles in degrees.
Returns:
-
rotz
(ndarray
) –Rotation matrix along Z axis.
Source code in odak/tools/transformation.py
same_side(p1, p2, a, b)
¶
Definition to figure which side a point is on with respect to a line and a point. See http://www.blackpawn.com/texts/pointinpoly/ for more. If p1 and p2 are on the sameside, this definition returns True.
Parameters:
-
p1
–Point(s) to check.
-
p2
–This is the point check against.
-
a
–First point that forms the line.
-
b
–Second point that forms the line.
Source code in odak/tools/vector.py
save_dictionary(settings, filename)
¶
Definition to load a dictionary (JSON) file.
Parameters:
-
settings
–Dictionary read from the file.
-
filename
–Filename.
Source code in odak/tools/file.py
save_image(fn, img, cmin=0, cmax=255, color_depth=8)
¶
Definition to save a Numpy array as an image.
Parameters:
-
fn
–Filename.
-
img
–A numpy array with NxMx3 or NxMx1 shapes.
-
cmin
–Minimum value that will be interpreted as 0 level in the final image.
-
cmax
–Maximum value that will be interpreted as 255 level in the final image.
-
color_depth
–Pixel color depth in bits, default is eight bits.
Returns:
-
bool
(bool
) –True if successful.
Source code in odak/tools/file.py
shell_command(cmd, cwd='.', timeout=None, check=True)
¶
Definition to initiate shell commands.
Parameters:
-
cmd
–Command to be executed.
-
cwd
–Working directory.
-
timeout
–Timeout if the process isn't complete in the given number of seconds.
-
check
–Set it to True to return the results and to enable timeout.
Returns:
-
proc
(Popen
) –Generated process.
-
outs
(str
) –Outputs of the executed command, returns None when check is set to False.
-
errs
(str
) –Errors of the executed command, returns None when check is set to False.
Source code in odak/tools/file.py
size_of_a_file(file_path)
¶
A definition to get size of a file with a relevant unit.
Parameters:
-
file_path
–Path of the file.
Returns:
-
a
(float
) –Size of the file.
-
b
(str
) –Unit of the size (bytes, KB, MB, GB or TB).
Source code in odak/tools/file.py
sphere_sample(no=[10, 10], radius=1.0, center=[0.0, 0.0, 0.0], k=[1, 2])
¶
Definition to generate a regular sample set on the surface of a sphere using polar coordinates.
Parameters:
-
no
–Number of samples.
-
radius
–Radius of a sphere.
-
center
–Center of a sphere.
-
k
–Multipliers for gathering samples. If you set k=[1,2] it will draw samples from a perfect sphere.
Returns:
-
samples
(ndarray
) –Samples generated.
Source code in odak/tools/sample.py
sphere_sample_uniform(no=[10, 10], radius=1.0, center=[0.0, 0.0, 0.0], k=[1, 2])
¶
Definition to generate an uniform sample set on the surface of a sphere using polar coordinates.
Parameters:
-
no
–Number of samples.
-
radius
–Radius of a sphere.
-
center
–Center of a sphere.
-
k
–Multipliers for gathering samples. If you set k=[1,2] it will draw samples from a perfect sphere.
Returns:
-
samples
(ndarray
) –Samples generated.
Source code in odak/tools/sample.py
tilt_towards(location, lookat)
¶
Definition to tilt surface normal of a plane towards a point.
Parameters:
-
location
–Center of the plane to be tilted.
-
lookat
–Tilt towards this point.
Returns:
-
angles
(list
) –Rotation angles in degrees.
Source code in odak/tools/transformation.py
write_PLY(triangles, savefn='output.ply')
¶
Definition to generate a PLY file from given points.
Parameters:
-
triangles
–List of triangles with the size of Mx3x3.
-
savefn
–Filename for a PLY file.
Source code in odak/tools/asset.py
write_PLY_from_points(points, savefn='output.ply')
¶
Definition to generate a PLY file from given points.
Parameters:
-
points
–List of points with the size of MxNx3.
-
savefn
–Filename for a PLY file.
Source code in odak/tools/asset.py
write_to_text_file(content, filename, write_flag='w')
¶
Defininition to write a Pythonic list to a text file.
Parameters:
-
content
–Pythonic string list to be written to a file.
-
filename
–Destination filename (i.e. test.txt).
-
write_flag
–Defines the interaction with the file. The default is "w" (overwrite any existing content). For more see: https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files
Source code in odak/tools/file.py
zero_pad(field, size=None, method='center')
¶
Definition to zero pad a MxN array to 2Mx2N array.
Parameters:
-
field
–Input field MxN array.
-
size
–Size to be zeropadded.
-
method
–Zeropad either by placing the content to center or to the left.
Returns:
-
field_zero_padded
(ndarray
) –Zeropadded version of the input field.
Source code in odak/tools/matrix.py
read_PLY(fn, offset=[0, 0, 0], angles=[0.0, 0.0, 0.0], mode='XYZ')
¶
Definition to read a PLY file and extract meshes from a given PLY file. Note that rotation is always with respect to 0,0,0.
Parameters:
-
fn
–Filename of a PLY file.
-
offset
–Offset in X,Y,Z.
-
angles
–Rotation angles in degrees.
-
mode
–Rotation mode determines ordering of the rotations at each axis. There are XYZ,YXZ,ZXY and ZYX modes.
Returns:
-
triangles
(ndarray
) –Triangles from a given PLY file. Note that the triangles coming out of this function isn't always structured in the right order and with the size of (MxN)x3. You can use numpy's reshape to restructure it to mxnx3 if you know what you are doing.
Source code in odak/tools/asset.py
read_PLY_point_cloud(filename)
¶
Definition to read a PLY file as a point cloud.
Parameters:
-
filename
–Filename of a PLY file.
Returns:
-
point_cloud
(ndarray
) –An array filled with poitns from the PLY file.
Source code in odak/tools/asset.py
write_PLY(triangles, savefn='output.ply')
¶
Definition to generate a PLY file from given points.
Parameters:
-
triangles
–List of triangles with the size of Mx3x3.
-
savefn
–Filename for a PLY file.
Source code in odak/tools/asset.py
write_PLY_from_points(points, savefn='output.ply')
¶
Definition to generate a PLY file from given points.
Parameters:
-
points
–List of points with the size of MxNx3.
-
savefn
–Filename for a PLY file.
Source code in odak/tools/asset.py
convert_to_numpy(a)
¶
A definition to convert Torch to Numpy.
Parameters:
-
a
–Input Torch array.
Returns:
-
b
(ndarray
) –Converted array.
Source code in odak/tools/conversions.py
convert_to_torch(a, grad=True)
¶
A definition to convert Numpy arrays to Torch.
Parameters:
-
a
–Input Numpy array.
-
grad
–Set if the converted array requires gradient.
Returns:
-
c
(Tensor
) –Converted array.
Source code in odak/tools/conversions.py
check_directory(directory)
¶
Definition to check if a directory exist. If it doesn't exist, this definition will create one.
Parameters:
-
directory
–Full directory path.
Source code in odak/tools/file.py
convert_bytes(num)
¶
A definition to convert bytes to semantic scheme (MB,GB or alike). Inspired from https://stackoverflow.com/questions/2104080/how-can-i-check-file-size-in-python#2104083.
Parameters:
-
num
–Size in bytes
Returns:
-
num
(float
) –Size in new unit.
-
x
(str
) –New unit bytes, KB, MB, GB or TB.
Source code in odak/tools/file.py
copy_file(source, destination, follow_symlinks=True)
¶
Definition to copy a file from one location to another.
Parameters:
-
source
–Source filename.
-
destination
–Destination filename.
-
follow_symlinks
(bool
, default:True
) –Set to True to follow the source of symbolic links.
Source code in odak/tools/file.py
expanduser(filename)
¶
Definition to decode filename using namespaces and shortcuts.
Parameters:
-
filename
–Filename.
Returns:
-
new_filename
(str
) –Filename.
Source code in odak/tools/file.py
list_files(path, key='*.*', recursive=True)
¶
Definition to list files in a given path with a given key.
Parameters:
-
path
–Path to a folder.
-
key
–Key used for scanning a path.
-
recursive
–If set True, scan the path recursively.
Returns:
-
files_list
(ndarray
) –list of files found in a given path.
Source code in odak/tools/file.py
load_dictionary(filename)
¶
Definition to load a dictionary (JSON) file.
Parameters:
-
filename
–Filename.
Returns:
-
settings
(dict
) –Dictionary read from the file.
Source code in odak/tools/file.py
load_image(fn, normalizeby=0.0, torch_style=False)
¶
Definition to load an image from a given location as a Numpy array.
Parameters:
-
fn
–Filename.
-
normalizeby
–Value to to normalize images with. Default value of zero will lead to no normalization.
-
torch_style
–If set True, it will load an image mxnx3 as 3xmxn.
Returns:
-
image
(ndarray
) –Image loaded as a Numpy array.
Source code in odak/tools/file.py
read_text_file(filename)
¶
Definition to read a given text file and convert it into a Pythonic list.
Parameters:
-
filename
–Source filename (i.e. test.txt).
Returns:
-
content
(list
) –Pythonic string list containing the text from the file provided.
Source code in odak/tools/file.py
resize_image(img, target_size)
¶
Definition to resize a given image to a target shape.
Parameters:
-
img
–MxN image to be resized. Image must be normalized (0-1).
-
target_size
–Target shape.
Returns:
-
img
(ndarray
) –Resized image.
Source code in odak/tools/file.py
save_dictionary(settings, filename)
¶
Definition to load a dictionary (JSON) file.
Parameters:
-
settings
–Dictionary read from the file.
-
filename
–Filename.
Source code in odak/tools/file.py
save_image(fn, img, cmin=0, cmax=255, color_depth=8)
¶
Definition to save a Numpy array as an image.
Parameters:
-
fn
–Filename.
-
img
–A numpy array with NxMx3 or NxMx1 shapes.
-
cmin
–Minimum value that will be interpreted as 0 level in the final image.
-
cmax
–Maximum value that will be interpreted as 255 level in the final image.
-
color_depth
–Pixel color depth in bits, default is eight bits.
Returns:
-
bool
(bool
) –True if successful.
Source code in odak/tools/file.py
shell_command(cmd, cwd='.', timeout=None, check=True)
¶
Definition to initiate shell commands.
Parameters:
-
cmd
–Command to be executed.
-
cwd
–Working directory.
-
timeout
–Timeout if the process isn't complete in the given number of seconds.
-
check
–Set it to True to return the results and to enable timeout.
Returns:
-
proc
(Popen
) –Generated process.
-
outs
(str
) –Outputs of the executed command, returns None when check is set to False.
-
errs
(str
) –Errors of the executed command, returns None when check is set to False.
Source code in odak/tools/file.py
size_of_a_file(file_path)
¶
A definition to get size of a file with a relevant unit.
Parameters:
-
file_path
–Path of the file.
Returns:
-
a
(float
) –Size of the file.
-
b
(str
) –Unit of the size (bytes, KB, MB, GB or TB).
Source code in odak/tools/file.py
write_to_text_file(content, filename, write_flag='w')
¶
Defininition to write a Pythonic list to a text file.
Parameters:
-
content
–Pythonic string list to be written to a file.
-
filename
–Destination filename (i.e. test.txt).
-
write_flag
–Defines the interaction with the file. The default is "w" (overwrite any existing content). For more see: https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files
Source code in odak/tools/file.py
A class to work with latex documents.
Source code in odak/tools/latex.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
__init__(filename)
¶
Parameters:
-
filename
–Source filename (i.e. sample.tex).