Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6530415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:45:08+00:00 2026-05-25T09:45:08+00:00

I made a program to perform some astronomical calculations. It takes only 6 parameters:

  • 0

I made a program to perform some astronomical calculations. It takes only 6 parameters: latitude , longitude, year, hour, minute and day, because

This I believe there must exist an elegant way to get the job done.

The module looks like this:

parameter1 = some1
parameter2 = some2
var_1 = some1 + some2 # or other calcs
var_2 = var1 + 'some other calcs'
var_n = opertions with some var_i with i < n

I need get some var values, so I can add getters functions like:

def f_var_2:
    return var_2

But I think this is not the Python way.

Should I define variables or functions instead?

def func_1 (some1, some2):
    return some1 + some2

def func_2 (some1, some2):
    return func_1 (some1, some2) + some other stuff

Edit to include the code and make (I hope) the right question.

import math

#values used for algorithm comprobation
#this 6 values will be read from a file
latitude = 35.5
longitude = 59.0833333333
year = 2011
hour = 17
minute = 15
day = 244

local_hour = hour + minute/60.0

#for local time 
universal_time = local_hour + 3 #at my location
#for UTC
#universal_time = local_hour

reference_year = 1949
delta = year - reference_year

leap = delta / 4

def julian_day (day, universal_time):
    return 2432916.5 + leap  + delta * 365 + day + universal_time / 24.0 

time =   julian_day(day, universal_time) - 2451545.0
mean_longitude = (280.46 + time * 0.9856474) % 360
mean_anomaly = ( 357.528 + 0.9856003 * time ) % 360

ecliptic_lon = (mean_longitude + math.sin(mean_anomaly * math.pi 
    /180) * 1.915 + 0.02 * math.sin ( mean_anomaly*math.pi/180 * 2.0 ) ) % 360

ecliptic_oblicuity = 23.429 - 0.0000004 * time

num = math.cos(ecliptic_oblicuity * math.pi/180) * math.sin(ecliptic_lon
    * math.pi / 180)

den = math.cos (ecliptic_lon * math.pi /180 )
right_ascencion = math.atan (num / den)

if den < 0 :
    right_ascencion  = (right_ascencion + math.pi)*180/math.pi
elif num < 0 :
    right_ascencion = (right_ascencion + math.pi * 2)*180/math.pi
else :
    right_ascencion = right_ascencion *180/math.pi

declination = math.asin(math.sin(ecliptic_oblicuity * math.pi / 180) * 
    math.sin(ecliptic_lon * math.pi / 180)) / math.pi * 180

Greenwich_mean_sidereal_time = (6.697375 + 0.0657098242 * time + 
    universal_time) % 24

if Greenwich_mean_sidereal_time < 0:
    Greenwich_mean_sidereal_time = Greenwich_mean_sidereal_time + 24

local_mean_sidereal_time = ((Greenwich_mean_sidereal_time + longitude / 15) %
    24) * 15

if local_mean_sidereal_time - right_ascencion < -180:
    hour_angle = local_mean_sidereal_time - right_ascencion + 360
elif local_mean_sidereal_time - right_ascencion > 180:
    hour_angle = local_mean_sidereal_time - right_ascencion - 360
else:
    hour_angle = local_mean_sidereal_time - right_ascencion

elevation = math.asin(math.sin(declination * math.pi / 180) * math.sin(latitude *
    math.pi / 180) + math.cos(declination * math.pi / 180) * math.cos(latitude *
    math.pi / 180) * math.cos(hour_angle * math.pi / 180)) / math.pi * 180

azimuth = math.asin(-math.cos(declination * math.pi / 180) * math.sin(
    hour_angle * math.pi/180) / math.cos(elevation * math.pi / 180)
    ) * 180 / math.pi

    math.sin(latitude*math.pi/180)))+180/math.pi

azimuth_corrected = 180 - azimuth
zenith_angle = 90.0 - elevation ;
cosine_zenith_angle = math.cos(zenith_angle * math.pi / 180)

def f_cosine_zenith_angle ():
    return cosine_zenith_angle

In the main program I will have a large matrix (n×m matrix, using list of lists) with the latitude and longitude and the datetime for the matrix. I apply the algorithm to calculate the cosine_zenith_angle for each element in the matrix and some times other calculations are performed.

I’m learning programming so I first made the algorithm implementation, after I put it in a module, put it in a class for encapsulation is the next step. I used the Michalski algorithm for solar position calculation. There are others algorithms and I want to keep the same API if I make other class with another algorithm. That’s is the reason to use the “getter” function. I did it this way in other language but I read this is not the Python’s way. And I want to learn Python well.

Should I make a function (public) for each intermediate calculation if I want to use it in other module? Should I keep intermediate calculations as they are now I make a getter? There are performance penalties doing intermediate calculations with functions?

Moreover, if I put every calculation in functions, I can’t call one of the last ones because it needs the results of other previous. I must modify all functions to accept all the parameters and perform the calculations backward. right? I thought about using a decorator to pass the parameters and the name of the function which produces the desired result. Will it work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:45:09+00:00Added an answer on May 25, 2026 at 9:45 am

    If I understand you correctly, you are doing something like this:

    import your_module
    your_module.parameter1 = 23
    your_module.parameter2 = 46
    the_result = your_module.f_var_2
    

    You are setting variables in your module so that some other variables change so that you can get an answer.

    You are definitely better off using functions, they were created for this purpose!

    import your_module
    the_result = your_module.f_var_1(23, 46)
    

    Of course if you need to use the same parameters many different times, you could instead use a class. You could have many instances of that class if the need arises for having different parameters in use at once. Using parameter1 as you have, it would be globally accessible which prevents different parts of your application from using the module as it wants to. Imagine if one part altered the parameter but did not expect another part to do the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple program I'm developing to perform some bandwidth tests on remote
I made a program. I also made my own file type, which the program
I made small program to divide large pictures and take part of them. When
I made a program that opens an application, sleeps the thread for 500ms then
I have made a program in c and wanted to see, how much memory
I'm a beginner in programming. I've just made a program called Guessing Game. And
I have made a registration program. Making use of mysql database. Can I still
I've made a small program which has 2 buttons and each does certain thing.
I'm trying to automate a program I made with a test suite via a
I have made my own file type (.ddd) and I made a simple program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.