Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1044 get rid of all global variables and move to a config data class #1077

Conversation

Little-Ryugu
Copy link
Collaborator

@Little-Ryugu Little-Ryugu commented Dec 5, 2024

Fixes #1044
Fixes #1015
Created a new data class called auxiliaryConfigs. This data class contains the default filenames and URLs that Sorcha needs for ephemeris generation. These default filenames and URLs can be overwritten in the [AUXILIARY] section of the config file when running Sorcha. This data class replaces the global variables for these files.

Review Checklist for Source Code Changes

  • Does pip install still work?
  • Have you written a unit test for any new functions?
  • Do all the units tests run successfully?
  • Does Sorcha run successfully on a test set of input files/databases?
  • Have you used black on the files you have updated to confirm python programming style guide enforcement?

This dataclass takes in filename and urls from the AUXILILARY section of the config file. If AUXILIARY section does not exist, default filenames and URLs are instead used.
changed function make_retriever use the config dataclass auxiliary. Went through the ephemeris files and updated this funtion. Completely removed all the global variables in similation_data_files.py.
removed global variables being imported
@mschwamb
Copy link
Collaborator

mschwamb commented Dec 5, 2024

The review needs to check sorcha bootstrap works so does sorcha run with the aux files already downloaded, and also sorcha run with the files needing to be downloaded. @Little-Ryugu has tested this locally

@mschwamb
Copy link
Collaborator

mschwamb commented Dec 5, 2024

@bernardinelli would you be able to test and see how we would test this on an order version of the files inputting in the config file?

@Little-Ryugu
Copy link
Collaborator Author

An example of the config file format for initialising a new file.

[AUXILIARY]
#Using file de432.bsp instead of the default file for de440s.
#filename
de440s = de432.bsp
#url of file
de440s_url = https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/planets/de432.bsp

@mschwamb mschwamb removed the request for review from astronomerritt December 10, 2024 11:32
@@ -820,6 +1015,9 @@ class sorchaConfigs:
expert: expertConfigs = None
"""expertConfigs dataclass which stores the keywords from the EXPERT section of the config file."""

auxiliary: auxiliaryConfigs = None
"""auxiliaryConfigs dataclass which stores the keywords from the AUXILILARY section of the config file."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo AUXILILARY :D

@@ -129,35 +125,42 @@ def parse_orbit_row(row, epochJD_TDB, ephem, sun_dict, gm_sun, gm_total):
return tuple(np.concatenate([equatorial_coords, equatorial_velocities]))


default = sorchaConfigs()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are now global variables because the are outside of any function. Can you have oc_file=None and if it's None then you create default? within class Obsevatory

@@ -129,35 +125,42 @@ def parse_orbit_row(row, epochJD_TDB, ephem, sun_dict, gm_sun, gm_total):
return tuple(np.concatenate([equatorial_coords, equatorial_velocities]))


default = sorchaConfigs()
default.auxiliary = auxiliaryConfigs() # using the default observatory_codes in the auxiliaryConfigs class
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are now global variables because the are outside of any function. Can you have oc_file=None and if it's None then you create default? within class Obsevatory

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need all of default or can you just make an
auxConfig = auxiliaryConfigs() and send that around. If we're not using any part of sconfigs other than auxConfig bits i'd just send that through

class Observatory:
"""
Class containing various utility tools related to the calculation of the observatory position
"""

def __init__(self, args, oc_file=OBSERVATORY_CODES):
def __init__(self, args, sconfigs, oc_file=default.auxiliary.observatory_codes):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if sconfigs is None than you set oc_file- do you really need to set oc_file here with a global?

retriever = make_retriever(args.ar_data_file_path)
planets_file_path = retriever.fetch(JPL_PLANETS)
small_bodies_file_path = retriever.fetch(JPL_SMALL_BODIES)
retriever = make_retriever(sconfigs, args.ar_data_file_path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd consider only passing it the ephemeris config bits since we use this in bootstrap utility where we don't have a config file class loaded since it's doesn't read one in @bernardinelli what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes sense. One way to do this would be to have an independent class or dictionary or something has only the ephemeris stuff, so that it can also be created independently in bootstrap. Or if sconfigs doesn't need to have everything set up, it'd accomplish the same thing (with no need to change the code)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently I commented and did not finish the review so no one could see me comments. Thanks @Little-Ryugu for pointing that out. - there is a smaller ephemeris auxiliary file class instance that is made within the sconfigs class so we should just be able to pass the ephemeris auxiliary file class here

Changed make_retriever to only take aux config. Removed global variable in  for class Observatory.
changed functions create_assist_ephemeris and furnish_spiceypy to only get the aux data class. Also added comment in bootstrap.py on how to download new files
@mschwamb mschwamb self-requested a review December 18, 2024 16:09
Copy link
Collaborator

@mschwamb mschwamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me as intended

@Little-Ryugu Little-Ryugu merged commit 6ff172b into main Dec 18, 2024
7 checks passed
@mschwamb mschwamb deleted the 1044-get-rid-of-all-global-variables-and-move-to-a-config-data-class branch January 18, 2025 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants