fit_point_source()   B
last analyzed

Complexity

Conditions 5

Size

Total Lines 67
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 39
dl 0
loc 67
rs 8.4773
c 0
b 0
f 0
cc 5
nop 9

How to fix   Long Method    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
from ..HAL import HAL
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
3
from threeML import DataList, JointLikelihood
0 ignored issues
show
introduced by
third party import "from threeML import DataList, JointLikelihood" should be placed before "from ..HAL import HAL"
Loading history...
4
5
6
def fit_point_source(roi,
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
best-practice introduced by
Too many arguments (9/5)
Loading history...
Comprehensibility introduced by
This function exceeds the maximum number of variables (19/15).
Loading history...
7
                     maptree,
8
                     response,
9
                     point_source_model,
10
                     bin_list,
11
                     confidence_intervals=False,
12
                     liff=False,
13
                     pixel_size=0.17,
14
                     verbose=False):
15
16
    data_radius = roi.data_radius.to("deg").value
17
18
    if not liff:
19
20
        # This is a 3ML plugin
21
        hawc = HAL("HAWC",
22
                   maptree,
23
                   response,
24
                   roi,
25
                   flat_sky_pixels_size=pixel_size)
26
27
        hawc.set_active_measurements(bin_list=bin_list)
28
29
    else:
30
31
        from threeML import HAWCLike
0 ignored issues
show
Bug introduced by
The name HAWCLike does not seem to exist in module threeML.
Loading history...
32
33
        hawc = HAWCLike("HAWC",
34
                        maptree,
35
                        response,
36
                        fullsky=True)
37
38
        hawc.set_bin_list(bin_list)
39
40
        ra_roi, dec_roi = roi.ra_dec_center
41
42
        hawc.set_ROI(ra_roi, dec_roi, data_radius)
43
44
    if not liff:
45
46
        hawc.display()
47
48
    data = DataList(hawc)
49
50
    jl = JointLikelihood(point_source_model, data, verbose=verbose)
0 ignored issues
show
Coding Style Naming introduced by
Variable name "jl" doesn't conform to snake_case naming style ('(([a-z_][a-z0-9_]2,30)|(_[a-z0-9_]*)|(__[a-z][a-z0-9_]+__))$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
51
52
    point_source_model.display(complete=True)
53
54
    try:
55
56
        jl.set_minimizer("minuit")
57
58
    except:
0 ignored issues
show
Coding Style Best Practice introduced by
General except handlers without types should be used sparingly.

Typically, you would use general except handlers when you intend to specifically handle all types of errors, f.e. when logging. Otherwise, such general error handlers can mask errors in your application that you want to know of.

Loading history...
59
60
        jl.set_minimizer("minuit")
61
62
    param_df, like_df = jl.fit()
63
64
    if confidence_intervals:
65
66
        ci = jl.get_errors()
0 ignored issues
show
Coding Style Naming introduced by
Variable name "ci" doesn't conform to snake_case naming style ('(([a-z_][a-z0-9_]2,30)|(_[a-z0-9_]*)|(__[a-z][a-z0-9_]+__))$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
67
68
    else:
69
70
        ci = None
0 ignored issues
show
Coding Style Naming introduced by
Variable name "ci" doesn't conform to snake_case naming style ('(([a-z_][a-z0-9_]2,30)|(_[a-z0-9_]*)|(__[a-z][a-z0-9_]+__))$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
71
72
    return param_df, like_df, ci, jl.results
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...