GithubHelp home page GithubHelp logo

ompy's Introduction

ompy logo heading 2

Python library development, mainly mathematical tools. Intended to grow to a Python module.

Follow the blog Ompy.


Documentation

ompy


Operations and relations for angles and their different measures. (for now, to be developed).

are_bools(tuple_arg)
       It checks if items in tuple are booleans data type.

       Parameters: tuple_arg: tuple; required.
       Returns: bool. True if all items are bools. False otherwise.

       Examples:

>>> import ompy.ompy as op

>>> op.are_bools(True, 2, "Hello")
False

>>> op.are_bools(True, False, True)
True


to_dec_degrees(theta, from_sexagesimal=False, from_gradians=False, from_turns=False, from_radians=True)
       It converts the provided angle to decimal degrees.

       Parameters: theta: int, float or str; required.
       Angle to convert. If provided as str, current unit has to be sexagesimal system as respective input is to be "DdMM'SS''" or "DdMM'SS''" pattern; where D could be any digits number (under supported range), MM (whole num) and SS (could be decimal) are a 1 or 2 digit number lower than 60.
                           from_sexagesimal: bool; default False.
       Pass True if current unit to convert from is degrees, minutes and seconds (sexagesimal measurement system).

                           from_gradians: bool; default False.
       Pass True if current unit to convert from is gradians.

                           from_turns: bool; default False.
       Pass True if current unit to convert from is number of turns/revolutions.

                           from_radians: bool; default True.
       Pass True if current unit to convert from is radians.\

       Returns: float; original angle now in decimal degrees.

       Examples:

>>> import ompy.ompy as op

>>> op.to_dec_degrees(1.23456)
70.735077555671

>>> op.to_dec_degrees("12d34'56''", from_sexagesimal=True)
12.582222222222

>>> op.to_dec_degrees(12.3456, from_gradians=True)
11.11104

>>> op.to_dec_degrees(0.123456, from_turns=True)
44.44416


to_radians(theta, from_sexagesimal=False, from_gradians=False, from_turns=False, from_dec_degrees=True)
       It converts the provided angle to radians.

       Parameters: theta: int, float or str; required.
       Angle to convert. If provided as str, current unit has to be sexagesimal system as respective input is to be "DdMM'SS''" or "DdMM'SS''" pattern; where D could be any-digits number (under supported range), MM (whole num) and SS (could be decimal) are a 1 or 2 digit number lower than 60.

                           from_sexagesimal: bool; default False.
       Pass True if current unit to convert from is degrees, minutes and seconds (sexagesimal measurement system).

                           from_gradians: bool; default False.
       Pass True if current unit to convert from is gradians.

                           from_turns: bool; default False.
       Pass True if current unit to convert from is number of turns/revolutions.

                           from_dec_degrees: bool; default True.
       Pass True if current unit to convert from is decimal degrees.

       Returns: float; original angle now in radians.

       Examples:

>>> import ompy.ompy as op

>>> op.to_radians(12.3456)
0.215471368134

>>> op.to_radians("12d34'56''", from_sexagesimal=True)
0.219601204995

>>> op.to_radians(12.3456, from_gradians=True)
0.193924231321

>>> op.to_radians(0.123456, from_turns=True)
0.775696925283


to_gradians(theta, from_dec_degrees=False, from_sexagesimal=False, from_turns=False, from_radians=True)
       It converts the provided angle to gradians.

       Parameters: theta: int, float or str; required.
       Angle to convert. If provided as str, current unit has to be sexagesimal system as respective input is to be "DdMM'SS''" or "DdMM'SS''" pattern; where D could be any-digits number (under supported range), MM (whole num) and SS (could be decimal) are a 1 or 2 digit number lower than 60.

                           from_dec_degrees: bool; default False.
       Pass True if current unit to convert from is decimal degrees.

                           from_sexagesimal: bool; default False.
       Pass True if current unit to convert from is degrees, minutes and seconds (sexagesimal measurement system).

                           from_turns: bool; default False.
       Pass True if current unit to convert from is number of turns/revolutions.

                           from_radians: bool; default True.
       Pass True if current unit to convert from is radians.

       Returns: float; original angle now in gradians.

       Examples:

>>> import ompy.ompy as op

>>> op.to_gradians(1.23456)
78.594530617412

>>> op.to_gradians(12.3456, from_dec_degrees=True)
13.7173333333

>>> op.to_gradians("12d34'56''", from_sexagesimal=True)
13.98024691358

>>> op.to_gradians(0.123456, from_turns=True)
49.3824


to_turns(theta, from_dec_degrees=False, from_sexagesimal=False, from_gradians=False, from_radians=True)
       It converts the provided angle to number of equivalent turns or revolutions.

       Parameters: theta: int, float or str; required.
       Angle to convert. If provided as str, current unit has to be sexagesimal system as respective input is to be "DdMM'SS''" or "DdMM'SS''" pattern; where D could be any-digits number (under supported range), MM (whole num) and SS (could be decimal) are a 1 or 2 digit number lower than 60.

                           from_dec_degrees: bool; default False.
       Pass True if current unit to convert from is decimal degrees.

                           from_sexagesimal: bool; default False.
       Pass True if current unit to convert from is degrees, minutes and seconds (sexagesimal measurement system).

                           from_gradians: bool; default False.
       Pass True if current unit to convert from is gradians.

                           from_radians: bool; default True.
       Pass True if current unit to convert from is radians.

       Returns: float; original angle now in number of turns/revolutions.

       Examples:

>>> import ompy.ompy as op

>>> op.to_turns(1.23456)
0.196486326544

>>> op.to_turns(12.3456, from_dec_degrees=True)
0.034293333333

>>> op.to_turns("12d34'56''", from_sexagesimal=True)
0.034950617284

>>> op.to_turns(12.3456, from_gradians=True)
0.030864


to_sexagesimal(theta, from_dec_degrees=False, from_gradians=False, from_turns=False, from_radians=True)
       It converts the provided angle into the sexagesimal system, where the angle is composed by the degrees, minutes and seconds magnitudes; following the pattern D°MM'SS'' (D, MM, SS are the magnitudes; MM and SS are 1 or 2 digit numbers lower than 60).

       Parameters: theta: int or float; required.
       Angle to convert.

                           from_dec_degrees: bool; default False.
       Pass True if current unit to convert from is decimal degrees.

                           from_gradians: bool; default False.
       Pass True if current unit to convert from is gradians.

                           from_turns: bool; default False.
       Pass True if current unit to convert from is number of turns/revolutions.

                           from_radians: bool; default True.
       Pass True if current unit to convert from is radians.

       Returns: Sexagesimal angle features (angle as str and its parts according to the sexagesimal system format) from the original angle.

       'sexagesimal angle features', tuple-like; consisting on the following fieldnames and values:
              "str_" : str; converted angle following the pattern "D°MM'SS''".
              "degrees" : int; degrees section from converted angle.
              "minutes" : int; minutes section from converted angle.
              "seconds" : float; seconds section from converted angle.

       Examples:

>>> import ompy.ompy as op

>>> op.to_sexagesimal(1.23456)
SexagesimalAngle(str_="70°44'6.279200415296''", degrees=70, minutes=44, seconds=6.279200415296)

>>> op.to_sexagesimal(1.23456).str_
"70°44'6.279200415296''"

>>> op.to_sexagesimal(1.23456).degrees
70

>>> op.to_sexagesimal(1.23456).minutes
44

>>> op.to_sexagesimal(1.23456).seconds
6.279200415296


>>> op.to_sexagesimal(12.3456, from_dec_degrees=True)
SexagesimalAngle(str_="12°20'44.16''", degrees=12, minutes=20, seconds=44.16)

>>> op.to_sexagesimal(12.3456, from_gradians=True)
SexagesimalAngle(str_="11°6'39.744''", degrees=11, minutes=6, seconds=39.744)

>>> op.to_sexagesimal(0.123456, from_turns=True)
SexagesimalAngle(str_="44°26'38.976''", degrees=44, minutes=26, seconds=38.976)

cubic


Analysis for cubic equations (for now, to be developed).


cbrt(radicand)
       Calculates the real cubic root -principal value- of rational representations of real numbers.

       Parameters: radicand: int, float, fractions.Fraction; required.
       Number to take the root of.

       Returns: float; cubic root.

       Examples:

>>> import ompy.cubic as cb

>>> cb.cbrt(216)
6.0

>>> cb.cbrt(-27.0)
-3.0

>>> cb.cbrt(10)
2.154434690032


to_depressed(coef_a, coef_b, coef_c, coef_d)
       Transforms a general cubic equation to a depressed cubic equation. It takes general equation coefficients 'a', 'b', 'c', 'd' and returns depressed equation coefficients 'p', 'q'.

       Parameters: coef_a: int, float; required (it cannot be 0).

                           coef_b: int, float; required.

                           coef_c: int, float; required.

                           coef_d: int, float; required.

       Returns: tuple. [0]: coefficient 'p', [1]: coefficient 'q'.

       Examples:

>>> import ompy.cubic as cb

>>> cb.to_depressed(1, -3, -3, 1)
(-6.0, -4.0)

>>> cb.to_depressed(1, 1, 1, 1)
(0.6666666666666667, 0.7407407407407407)

>>> cb.to_depressed(1, 0, 2, 3)
(2.0, 3.0)

>>> cb.to_depressed(2, 0, 0, 0)
(0.0, 0.0)


cbdelta(coef_p, coef_q, as_frac=False)
       Calculates the cubic discriminant (delta) for a depressed cubic equation

       Parameters: coef_p: int, float, fractions.Fraction; required. Coefficient 'p' from depressed equation.

                           coef_q: int, float, fractions.Fraction; required. Coefficient 'q' from depressed equation.

                           as_frac: bool (True or False); optional. False by default. Object type to be returned.

       Returns: Cubic delta number.
       fractions.Fraction object if as_frac passed as True, float otherwise.

       Examples:

>>> import ompy.cubic as cb

>>> cb.cbdelta(3, 4)
20.0

>>> cb.cbdelta(-3, -2)
0.0

>>> cb.delta(5.55555, -4.44444)
-5.6495085912265

>>> cb.cbdelta(-11, 8)
Fraction(-3596, 27)


depressed_roots(coef_p, coef_q, symbolic)
       For depressed cubic equations returns a tuple with its roots.

       Parameters: coef_p: int, float, fractions.Fraction; required.
       Coefficient 'p' from depressed equation.

                           coef_q: int, float, fractions.Fraction; required.
       Coefficient 'q' from depressed equation.

                           symbolic: bool (True or False) ; optional. False by default. For requesting symbolic math output.

       Returns: Equation roots.

       sympy objects display; if symbolic passed as True.

       tuple otherwise:

              [0] : str; first root, represents a real number.
              [1] : str; second root, represents a real or complex number.
              [2] : str; third root, represents a real or complex number.

       Examples:

>>> import ompy.cubic as cb

>>> cb.depressed_roots(-3, -2)
('2.0', '-1.0', '-1.0')


>>> cb.depressed_roots(1, 0)
('0.0', '-0.0 + 1.0i', '-0.0 - 1.0i')

>>> cb.depressed_roots(0, 1)
('-1.0', '0.5 + 0.86602540378i', '0.5 - 0.86602540378i')

>>> cb.depressed_roots(1.11111, 2.22222)
('-1.02650941551',
 '0.513254707755 + 1.37891304479i',
 '0.513254707755 - 1.37891304479i')

depressed_roots symbolic code example2

roots(coef_a, coef_b, coef_c, coef_d)
       Calculates cubic general equations roots.

       Parameters: coef_a: int, float, fractions.Fraction; required (it cannot be 0).
       Equation coefficient 'a'.

                           coef_b: int, float, fractions.Fraction; required.
       Equation coefficient 'b'.

                           coef_c: int, float, fractions.Fraction; required.
       Equation coefficient 'c'.

                           coef_d: int, float, fractions.Fraction; required.
       Equation coefficient 'd'.

                           symbolic: bool (True or False) ; optional. False by default. For requesting symbolic math output.

       Returns: Equation roots.

       sympy objects display; if symbolic passed as True.

       Tuple otherwise:

              [0] : str; first root, represents a real number.
              [1] : str; second root, represents a real or complex number.
              [2] : str; third root, represents a real or complex number.

       Examples:

>>> import ompy.cubic as cb

>>> cb.roots(1, -15, 75, -125)
('5.0', '5.0', '5.0')

>>> cb.roots(2, -3, -11, 6)
('3.0', '-2.0', '0.5')

>>> cb.roots(3, 0, 0, 0)
(0.0, 0.0, 0.0)

>>> cb.roots(1, 2, 3, 4)
('-1.6506291914',
 '-0.1746854043 + 1.5468688872i',
 '-0.1746854043 - 1.5468688872i')

roots symbolic code example2

[WORK IN PROGRESS]

Citations and credits

SymPy

To cite SymPy in publications use

Meurer A, Smith CP, Paprocki M, Čertík O, Kirpichev SB, Rocklin M, Kumar A, Ivanov S, Moore JK, Singh S, Rathnayake T, Vig S, Granger BE, Muller RP, Bonazzi F, Gupta H, Vats S, Johansson F, Pedregosa F, Curry MJ, Terrel AR, Roučka Š, Saboo A, Fernando I, Kulal S, Cimrman R, Scopatz A. (2017) SymPy: symbolic computing in Python. PeerJ Computer Science 3:e103 https://doi.org/10.7717/peerj-cs.103

SymPy is BSD licensed, so you are free to use it whatever you like, be it academic, commercial, creating forks or derivatives, as long as you copy the BSD statement if you redistribute it (see the LICENSE file for details). That said, although not required by the SymPy license, if it is convenient for you, please cite SymPy when using it in your work and also consider contributing all your changes back, so that we can incorporate it and all of us will benefit in the end.

Copyright (c) 2006-2021 SymPy Development Team

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

  a. Redistributions of source code must retain the above copyright notice,
     this list of conditions and the following disclaimer.
  b. Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in the
     documentation and/or other materials provided with the distribution.
  c. Neither the name of SymPy nor the names of its contributors
     may be used to endorse or promote products derived from this software
     without specific prior written permission.


THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

--------------------------------------------------------------------------------

Patches that were taken from the Diofant project (https://github.com/diofant/diofant)
are licensed as:

Copyright (c) 2006-2018 SymPy Development Team,
              2013-2021 Sergey B Kirpichev

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

  a. Redistributions of source code must retain the above copyright notice,
     this list of conditions and the following disclaimer.
  b. Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in the
     documentation and/or other materials provided with the distribution.
  c. Neither the name of Diofant or SymPy nor the names of its contributors
     may be used to endorse or promote products derived from this software
     without specific prior written permission.


THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

--------------------------------------------------------------------------------

Submodules taken from the multipledispatch project (https://github.com/mrocklin/multipledispatch)
are licensed as:

Copyright (c) 2014 Matthew Rocklin

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

  a. Redistributions of source code must retain the above copyright notice,
     this list of conditions and the following disclaimer.
  b. Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in the
     documentation and/or other materials provided with the distribution.
  c. Neither the name of multipledispatch nor the names of its contributors
     may be used to endorse or promote products derived from this software
     without specific prior written permission.


THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

--------------------------------------------------------------------------------

The files under the directory sympy/parsing/autolev/tests/pydy-example-repo
are directly copied from PyDy project and are licensed as:

Copyright (c) 2009-2021, PyDy Authors
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
  notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in the
  documentation and/or other materials provided with the distribution.
* Neither the name of this project nor the names of its contributors may be
  used to endorse or promote products derived from this software without
  specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL PYDY AUTHORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

ompy's People

Contributors

alejandropenaloza avatar

Stargazers

 avatar

ompy's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.