pyIslam icon indicating copy to clipboard operation
pyIslam copied to clipboard

Avoid using single char name

Open azzamsa opened this issue 3 years ago • 2 comments

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?

azzamsa avatar Dec 17 '22 22:12 azzamsa

🆙

OdyAsh avatar Feb 15 '25 06:02 OdyAsh

Hey!

Sure, I can help with that. Renaming the variables definitely makes the code easier to understand. Here’s what I’d understand/ suggest:

  • jdjulian_day: This is the Julian Date (a continuous count of days).
  • ndays_since_j2000: This is how many days have passed since the J2000 epoch (January 1, 2000).
  • gmean_anomaly: The Earth's mean anomaly, or its position in its orbit around the Sun.
  • ceccentricity_correction: The correction for Earth's elliptical orbit.
  • lamdamean_longitude_of_sun: The Sun's position along its orbit.
  • rorbital_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

aljasem-tech avatar Nov 16 '25 13:11 aljasem-tech