Conditions | 5 |
Total Lines | 57 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
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 | # Copyright (C) 2019 NRL |
||
23 | dep_str = "".join(["Deprecated routine will be removed in version 2.6.1 ", |
||
24 | "unless users express interest in keeping it"]) |
||
25 | |||
26 | def subsol(year, doy, utime): |
||
27 | """Finds subsolar geocentric longitude and latitude. |
||
28 | |||
29 | Parameters |
||
30 | ------------ |
||
31 | year : (int) |
||
32 | Calendar year between 1601 and 2100 |
||
33 | doy : (int) |
||
34 | Day of year between 1-365/366 |
||
35 | utime : (float) |
||
36 | Seconds since midnight on the specified day |
||
37 | |||
38 | Returns |
||
39 | --------- |
||
40 | sbsllon : (float) |
||
41 | Subsolar longitude in degrees E for the given date/time |
||
42 | sbsllat : (float) |
||
43 | Subsolar latitude in degrees N for the given date/time |
||
44 | |||
45 | Notes |
||
46 | -------- |
||
47 | Based on formulas in Astronomical Almanac for the year 1996, p. C24. |
||
48 | (U.S. Government Printing Office, 1994). Usable for years 1601-2100, |
||
49 | inclusive. According to the Almanac, results are good to at least 0.01 |
||
50 | degree latitude and 0.025 degrees longitude between years 1950 and 2050. |
||
51 | Accuracy for other years has not been tested. Every day is assumed to have |
||
52 | exactly 86400 seconds; thus leap seconds that sometimes occur on December |
||
53 | 31 are ignored (their effect is below the accuracy threshold of the |
||
54 | algorithm). |
||
55 | After Fortran code by A. D. Richmond, NCAR. Translated from IDL |
||
56 | by K. Laundal. |
||
57 | |||
58 | """ |
||
59 | warnings.warn(dep_str, category=FutureWarning) |
||
60 | |||
61 | # Convert from 4 digit year to 2 digit year |
||
62 | yr2 = year - 2000 |
||
63 | |||
64 | if year >= 2101: |
||
65 | aacgmv2.logger.error('subsol invalid after 2100. Input year is:', year) |
||
66 | |||
67 | # Determine if this year is a leap year |
||
68 | nleap = np.floor((year - 1601) / 4) |
||
69 | nleap = nleap - 99 |
||
70 | if year <= 1900: |
||
71 | if year <= 1600: |
||
72 | print('subsol.py: subsol invalid before 1601. Input year is:', year) |
||
73 | ncent = np.floor((year - 1601) / 100) |
||
74 | ncent = 3 - ncent |
||
75 | nleap = nleap + ncent |
||
76 | |||
77 | # Calculate some of the coefficients needed to deterimine the mean longitude |
||
78 | # of the sun and the mean anomaly |
||
79 | l_0 = -79.549 + (-0.238699 * (yr2 - 4 * nleap) + 3.08514e-2 * nleap) |
||
80 | g_0 = -2.472 + (-0.2558905 * (yr2 - 4 * nleap) - 3.79617e-2 * nleap) |
||
209 |