Releases: nicholas12392/nanoscipy
v3.0.16
New Features and Changes
🟩colors.py
🟩GRAY2RGB()
This new function converts a grayscale image to instead be colorized with the HEX or RGB color provided. The function has the parameters:
img
grayscale image from OpenCV
rgb_col
desired RGB color in shape (r, g, b) or hex as '#HEXCODE'
🟦setup.py
Dependencies have been changed to make the package more easily installable.
🟥functions.py
🟥file_select()
Removed FlowCal package dependency. Thus, it is no longer possible to load flow calorimetry data through the function.
v3.0.15
Solved deploy issue for v3.0.14.
v3.0.14
New features
The colors.py
has been added, which provides a set of color generator functions for data representation.
colors.osc_line()
A function that creates an oscillator line with given parameters. Returns a numpy array with the oscillator line points.
The function has the parameters:
points
The amount of points there should be on the line.
tt
The trigonometry type. Can be 'sin' or 'cos'. Default is 'sin'.
lin
The linearity. Default is 1.
gauge
Maximum amplitude span of the oscillator. Default is 0.5.
freq
The frequency of the oscillator. Default is 4.
min_shift
A minimum shift of the oscillator baseline. Default is 0.1.
colors.color_generator()
Generates an array of colors from an RGB spectrum through the oscillator line function. Returns a numpy array with the color spectrum points in the form ((R,G,B), ...). If cdict is True a the output will instead be ((R,G,B), ...), dict.
The function has the parameters:
n
Number of colors to generate.
tt
The trigonometry type for the R, G, and B channels. Can be 'sin' or 'cos'. Default is ('sin', 'sin', 'sin').
lin
Linearity for the R, G, and B channels. Default is (1, 1, 1).
gauge
Maximum amplitude span of the oscillator for the R, G, and B channels. Default is (0.5, 0.5, 0.5).
freq
Frequency of the oscillator for the R, G, and B channels. Default is (4, 4, 4).
random
If True the color spectra are generated randomly. Default is False.
rf
Upper frequency limit for the R, G, and B channels. Default is 10.
boldness
Introduces a minimim baseline for the R, G, and B channels. A higher value streamlines the color spectrum, such that a more easily pleasing spectrum is obtained. A lower value makes the colors in the spectrum more easily distinguishable. Default is 0.1.
rb
The boldness limit for the R, G, and B channels. Default is 0.4.
cdict
If True a dictionary with the function parameters is generated in addition to the colors from the generated spectrum. Default is False.
colors.color_presets()
Gives n amount of colors from a chosen color preset. Returns a numpy array with the color spectrum points in the form ((R,G,B), ...).
The function has the parameters:
n
The number of colors to generate.
preset
The preset from which the colors are generated. If preset is -1, a figure with all different presets is generated instead. Default is -1.
colors.RandomColors
A random color preset generator class.
.generate()
Generate random color preset. Creates a figure with the generated colors and defines the color parameter dictionary as ´self.cdict´.
sets
The number of presets to generate.
n
The number of colors to generate in each preset.
max_frequency
Upper frequency limit for the R, G, and B channels. Default is 10.
max_boldness
The boldness variation lower limit for the R, G, and B channels. Default is 0.4.
3.0.13
New features
mathpar.parser()
Now supports using input expressions with spaces.
unitpar.unit_abbreviator()
Now abbreviates SI unit derivatives in more situations than before.
Changes
modules.NumAn
.supported_physical_constants
Changed the way constants with units are displayed to be more in line with expectations.
Bug fixes
unitpar.unit_handler()
Fixed an issue where if multiple valid unit multiplication operations were performed in a row, the script would fail to remove the last multiplication symbol if there was a unitless quantity at the end, from the initial input equation, causing an IndexError, when solving the expression completely.
3.0.12
Bug fixes
mathpar.parser()
Fixed an issue where input expressions having the first element be '-'
would sometimes be read and computed incorrectly.
3.0.11
Bug fixes
modules.NumAn
.calc()
Fixed an issue where unitless results were saved with the extension ' a.u.'
with add_res=
, which caused issues when these new constants were used in later calculations.
3.0.10
New features
modules.NumAn
Added kwarg supp_prompt
that allows for suppressing console prompts during script runtime. Currently there is only the options 'cns_change'
, which suppresses the constant change prompts, and 'all'
, which suppresses all prompts that may occur.
.calc()
Newly computed result may be added directly from the expression itself as if defining a constant:
import nanoscipy.modules as nsm
test1 = nsm.NumAn('lambda=500 nm, na=1.4, n=1.518')
test1.add_cns('dxy=0.61lambda/(sqrt(2)na), dz=2lambdan/(sqrt(2)(na)^2)')
test1.add_cns('rxy=dxy/2, rz=dz/2')
test1.calc('V=4/3pi*(rxy)^2*(rz)')
test1.constants()
>>> Result: V = 4/3·π·(rxy)^2·(rz) = 6.805e-21 m^3
>>> | rxy = 7.702e-8 m
>>> | rz = 2.738e-7 m
>>> Currently defined constants:
>>> | lambda = 500 nm
>>> | na = 1.4
>>> | n = 1.518
>>> | dxy = 1.5404826304421216e-07 m
>>> | dz = 5.47646986653663e-07 m
>>> | rxy = 7.702413152210608e-08 m
>>> | rz = 2.738234933268315e-07 m
>>> | V = 6.804761940761147e-21 m^3
Note that this feature is overwritten by using the add_res
parameter in .calc()
:
test1.add_cns('k=34')
test1.calc('b=34k', 'g')
test1.constants()
>>> Result: g = 34·k = 1156
>>> | k = 34
>>> Currently defined constants:
>>> | k = 34
>>> | g = 1156
In addition, as seen in the example above, the 'result name' now shows up in the console print.
modules.DatAn
An early stage feature has been added, that allows for defining functions to fit data to, as in any other CAS tool. E.g.;
import nanoscipy.modules as nsm
temps = [800, 900, 1000, 1100, 1200]
chis = [(i * 10 ** -5) ** - 1 for i in (3.3, 2.1, 1.55, 1.2, 1.0)]
func = 'f(T)=(C/(T-theta))^-1'
data = nsm.DatAn(temps, chis, func, [1e-3, 1])
Rather than having to define the function as:
func = lambda T, theta, C: (C / (T - theta)) ** - 1
or
def func(T, theta, C):
return (C / (T - theta)) ** - 1
The functionality of this is that the part before '='
states which variable is varying, so in the example above 'T'
is the variable. The function name (above 'f'
) can be anything, as it is only used for display. In addition to this, the attribute func_out
has been added, and displays the function as it would be written down on paper. E.g. for the example above:
print(data.func_out)
>>> ['f(T)=(0.005711/(T-627.9))^-1']
Note that by default it rounds the values to four decimals. An option to change this will be added in the upcoming patch. Note also importantly that this is a very early stage feature, and is currently significantly slower than the normal way, and the guess values generally needs to be better than usual for it not to run into dead ends. Furthermore, this is only supported for method='curve_fit'
.
util.split()
It is now possible to do a direct replacement of the delimiter during the split with the parameter rep
. This can in principle be any var type.
util.multi_split()
Similarly, as for util.split()
a direct replacement feature has been added as the parameter rep
. Note that this must be a list, and if the length of the replacement list does not match the delimiter list, then the script will execute replacements per available replacement. That is, if items=['alpha', 'beta', 'gamma']
with reps=['α', 'δ']
then after the split, all the previous elements of 'alpha'
is now 'α'
and 'beta'
is now 'δ'
, but all 'gamma'
elements are still 'gamma'
.
Changes
util.split()
Has been changed and optimized. Should be slightly faster now.
modules.NumAn
.calc()
When overwriting constants from .calc(add_res=)
, the console prompt now shows up before the result-print, rather than directly after.
In addition, the way console printing is done has been changed completely. This should not affect anything on the user end.
Natural constants are now displayed slightly different, to set them apart from constants that may have been defined.
mathpar.parser()
Note the vision here: mathpar.parser()
should be reduced to simply the backend of the calculator, which is intended to be modules.NumAn
and therefore, the following changes have been made: The kwargs true_string
and unit_res
have been removed along with their functionality. The parameter cprint
is now a bool, and the console print will always have explicit multiplication. The reasoning behind these changes is that by reducing the mathpar.parser()
to just a backend script for modules.NumAn
, a lot of efficiency should be gained, as nothing will be checked multiple times, and checker scripts can be simplified emmensely, as much of the preparation for numerical calculation is being done by NumAn
itself.
Optimizations has also been done, and the script should be notably faster for large calculations.
unitpar.unit_parser()
The same changes has been made as the ones for mathpar.parser()
with the same vision. Additionally, cprint
is now a parameter rather than a kwarg.
Bug fixes
unitpar.unit_parser()
Fixed an infinite loop issue that would sometimes occur if there were lone units next to a '/()'
term.
modules.NuAm
.calc()
Fixed an issue where constants could not be printed in the console if they were closed off with parentheses without any mathematical operator.
v3.0.9
Bug fixes
modules.NumAn
.calc()
Fixed an issue where computations could not be done, if they had no units.
v3.0.8
Changes
Updated the README file.
modules.NumAn
The prompt message for overwriting constants has been changed slightly.
Bug fixes
modules.NumAn
Fixed an issue, where constants were sometimes saved incorrectly, if the unit identifier was something else than ' '
.
.calc()
Fixed a potential issue, where constants might not be displayed correctly after changing significant figures.
Fixed issue where constants where not displaying correctly for computed result.
Fixed an issue where constants were displayed unintendedly if they were contained in units.
v3.0.7
New features
Added a getting started with unit calculations guide in the README file.
mathpar.parser(), unitpar.unit_parser(), modules.NumAn
It is now possible to specify how many significant figures should be displayed when using cprint
with the optional argument sf
(for NumAn - this is a kwarg for unit_parser() and parser()). If set to None
there is made no attempt to change the significant figures, otherwise if set to an int, an attempt will be made to conform to that significant figure. This feature is based on the mpmath workdps
function. Note that for NumAn, this can also be specified per calculation (.calc(sf=)
). The default for NumAn is 4. For the other functions it is None.
Changes
modules.NumAn
Changed how added constants got put in a bracket, to ensure correct computation with units.
.del_cns()
Now works with *args, rather than a single argument. Thus, multiple constants can be deleted by just adding more constants to the expression, e.g. .del_cns('A', 'lambda')
will delete both constants 'A'
and 'lambda'
(before .del_cns(('A', 'lambda'))
). Note that .del_cns('A, lambda')
will work in the same way (here the delimiter ';'
may be used instead of ','
if desired).
.calc()
Changed the way constants are displayed after computations. In addition, now the script saves computed constants as input, so that they do not have to be computed every time they are used in an expression. This should increase efficiency slightly.
Changed the way constants are checked regarding being an expression or a value. This new method should be much more accurate.
Changed cprint
to kwarg rather than parameter.
mathpar.parser()
Removed rare instances of pi-prettifying.
Bug fixes
mathpar.parser()
Fixed instances where the unit 'amu'
was unintendedly swapped by the prettifier to 'aµ'
.
modules.NumAn
Fixed an issue where units were unintendedly swapped with defined constants, if the constants were in the unit, bricking calculations from that point and onwards.
.calc()
Fixed a potential issue in the way computed constants were saved.
Fixed unintended display of defined constants, if they were part of a function such as cos()
, exp()
, etc., but not in the expression itself.
Fixed issues, where cprint=None
was read as defined from __init__()
rather than as the option None
.