pyIslam
pyIslam copied to clipboard
Avoid using single char name
Hi, Abdelhak.
I plan to refactor my Rust port. Primarily the baselib.
I am having a hard time understanding the equation because of single variable names such:
- https://github.com/abougouffa/pyIslam/blob/eb5cd7af0f4ad2e63e5f07054de690c76454b3ba/pyIslam/baselib.py#L24
Are you able to rename those single-char names to a more descriptive name?
def equation_of_time(jd):
'''Get equation of time'''
n = jd - 2451544.5
g = 357.528 + 0.9856003 * n
c = 1.9148 * dsin(g) + 0.02 * dsin(2 * g) + 0.0003 * dsin(3 * g)
lamda = 280.47 + 0.9856003 * n + c
r = (-2.468 * dsin(2 * lamda)
+ 0.053 * dsin(4 * lamda)
+ 0.0014 * dsin(6 * lamda))
return (c + r) * 4
jd would be julian_day, but I have no clue about n, g, c, etc.
Is the source also using a single char name?
🆙
Hey!
Sure, I can help with that. Renaming the variables definitely makes the code easier to understand. Here’s what I’d understand/ suggest:
jd→julian_day: This is the Julian Date (a continuous count of days).n→days_since_j2000: This is how many days have passed since the J2000 epoch (January 1, 2000).g→mean_anomaly: The Earth's mean anomaly, or its position in its orbit around the Sun.c→eccentricity_correction: The correction for Earth's elliptical orbit.lamda→mean_longitude_of_sun: The Sun's position along its orbit.r→orbital_irregularities_correction: This adjusts for small irregularities in Earth’s orbit.
So, it might look something like this:
def equation_of_time(julian_day):
'''Get equation of time in minutes'''
days_since_j2000 = julian_day - 2451544.5
mean_anomaly = 357.528 + 0.9856003 * days_since_j2000
eccentricity_correction = 1.9148 * dsin(mean_anomaly) + 0.02 * dsin(2 * mean_anomaly) + 0.0003 * dsin(3 * mean_anomaly)
mean_longitude_of_sun = 280.47 + 0.9856003 * days_since_j2000 + eccentricity_correction
orbital_irregularities_correction = (-2.468 * dsin(2 * mean_longitude_of_sun)
+ 0.053 * dsin(4 * mean_longitude_of_sun)
+ 0.0014 * dsin(6 * mean_longitude_of_sun))
return (eccentricity_correction + orbital_irregularities_correction) * 4