# poliastro/poliastro

src/poliastro/twobody/orbit.py

### Summary

F
4 days

#### File `orbit.py` has 1224 lines of code (exceeds 350 allowed). Consider refactoring. Open

``````from typing import List, Union
from warnings import warn

import numpy as np
from astropy import time, units as u``````
Found in src/poliastro/twobody/orbit.py - About 2 days to fix

#### `Orbit` has 33 functions (exceeds 20 allowed). Consider refactoring. Open

``````class Orbit:
"""Position and velocity of a body with respect to an attractor
at a given time (epoch).

Regardless of how the Orbit is created, the implicit``````
Found in src/poliastro/twobody/orbit.py - About 4 hrs to fix

#### Cyclomatic complexity is too high in method heliosynchronous. (16) Open

``````    @classmethod
def heliosynchronous(
cls,
attractor,
a=None,``````

## Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

#### Cyclomatic complexity is too high in method frozen. (13) Open

``````    @classmethod
@u.quantity_input(
)
def frozen(``````

## Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

#### Cyclomatic complexity is too high in method from_classical. (8) Open

``````    @classmethod
def from_classical(
cls,
attractor,``````

## Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

#### Cyclomatic complexity is too high in method change_attractor. (8) Open

``````    def change_attractor(self, new_attractor, force=False):
"""Changes orbit attractor.

Only changes from attractor to parent or the other way around are allowed.

``````

## Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

#### Cyclomatic complexity is too high in method from_sbdb. (6) Open

``````    @classmethod
def from_sbdb(cls, name, **kwargs):
"""Return osculating `Orbit` by using `SBDB` from Astroquery.

Parameters``````

## Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

#### Function `heliosynchronous` has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open

``````    def heliosynchronous(
cls,
attractor,
a=None,
ecc=None,``````
Found in src/poliastro/twobody/orbit.py - About 1 hr to fix

# Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

### A method's cognitive complexity is based on a few simple rules:

• Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
• Code is considered more complex for each "break in the linear flow of the code"
• Code is considered more complex when "flow breaking structures are nested"

#### Consider simplifying this complex logical expression. Open

``````                if (a is None) and (ecc is None) and (inc is None):
# We check sufficient number of parameters
raise ValueError(
"At least two parameters of the set {a, ecc, inc} are required."
)``````
Found in src/poliastro/twobody/orbit.py - About 1 hr to fix

#### Function `frozen` has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open

``````    def frozen(
cls,
attractor,
alt,
inc=None,``````
Found in src/poliastro/twobody/orbit.py - About 1 hr to fix

# Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

### A method's cognitive complexity is based on a few simple rules:

• Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
• Code is considered more complex for each "break in the linear flow of the code"
• Code is considered more complex when "flow breaking structures are nested"

#### Function `from_classical` has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open

``````    def from_classical(
cls,
attractor,
a,
ecc,``````
Found in src/poliastro/twobody/orbit.py - About 45 mins to fix

# Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

### A method's cognitive complexity is based on a few simple rules:

• Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
• Code is considered more complex for each "break in the linear flow of the code"
• Code is considered more complex when "flow breaking structures are nested"

#### Function `change_attractor` has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open

``````    def change_attractor(self, new_attractor, force=False):
"""Changes orbit attractor.

Only changes from attractor to parent or the other way around are allowed.

``````
Found in src/poliastro/twobody/orbit.py - About 45 mins to fix

# Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

### A method's cognitive complexity is based on a few simple rules:

• Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
• Code is considered more complex for each "break in the linear flow of the code"
• Code is considered more complex when "flow breaking structures are nested"

#### Function `synchronous` has 10 arguments (exceeds 9 allowed). Consider refactoring. Open

``    def synchronous(``
Found in src/poliastro/twobody/orbit.py - About 35 mins to fix

#### Function `heliosynchronous` has 10 arguments (exceeds 9 allowed). Consider refactoring. Open

``    def heliosynchronous(``
Found in src/poliastro/twobody/orbit.py - About 35 mins to fix

#### Function `frozen` has 10 arguments (exceeds 9 allowed). Consider refactoring. Open

``    def frozen(``
Found in src/poliastro/twobody/orbit.py - About 35 mins to fix

#### Function `from_sbdb` has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open

``````    def from_sbdb(cls, name, **kwargs):
"""Return osculating `Orbit` by using `SBDB` from Astroquery.

Parameters
----------``````
Found in src/poliastro/twobody/orbit.py - About 35 mins to fix

# Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

### A method's cognitive complexity is based on a few simple rules:

• Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
• Code is considered more complex for each "break in the linear flow of the code"
• Code is considered more complex when "flow breaking structures are nested"

#### FIXME found Open

``        # FIXME: Refactor this insanity to remove a lot of back and forth``
Found in src/poliastro/twobody/orbit.py by fixme

#### TODO found Open

``            # TODO: The attractor is not really the Sun, but the Solar System``
Found in src/poliastro/twobody/orbit.py by fixme

#### HACK found Open

``        # HACK: Only needed for Orbit.from_body_ephem``
Found in src/poliastro/twobody/orbit.py by fixme

#### TODO found Open

``        # TODO: Perhaps this should be public API as well?``
Found in src/poliastro/twobody/orbit.py by fixme

#### TODO found Open

``            # TODO: The attractor is in fact the Earth-Moon Barycenter``
Found in src/poliastro/twobody/orbit.py by fixme

#### HACK found Open

``        self._frame = None  # HACK: Only needed for Orbit.from_body_ephem``
Found in src/poliastro/twobody/orbit.py by fixme