-
Notifications
You must be signed in to change notification settings - Fork 18
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
Changes from 12 commits
f75e72d
22e1663
6768188
ab2b214
dba96ff
dd4dde2
82c92d9
3098b60
2345ca5
c857857
552e768
d4cf482
7e006bc
331b122
c1d880d
914398b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,10 @@ | |
import numpy as np | ||
import spiceypy as spice | ||
from pooch import Decompress | ||
|
||
from sorcha.utilities.sorchaConfigs import sorchaConfigs, auxiliaryConfigs | ||
from sorcha.ephemeris.simulation_constants import RADIUS_EARTH_KM | ||
from sorcha.ephemeris.simulation_geometry import ecliptic_to_equatorial | ||
from sorcha.ephemeris.simulation_data_files import ( | ||
OBSERVATORY_CODES, | ||
OBSERVATORY_CODES_COMPRESSED, | ||
make_retriever, | ||
) | ||
from sorcha.ephemeris.simulation_data_files import make_retriever | ||
from sorcha.ephemeris.orbit_conversion_utilities import universal_cartesian | ||
|
||
|
||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need all of default or can you just make an |
||
|
||
|
||
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
""" | ||
Initialization method | ||
|
||
Parameters | ||
---------- | ||
args : dictionary or `sorchaArguments` object | ||
dictionary of command-line arguments. | ||
sconfigs: dataclass | ||
Dataclass of configuration file arguments. | ||
oc_file : str | ||
Path for the file with observatory codes | ||
""" | ||
self.observatoryPositionCache = {} # previously calculated positions to speed up the process | ||
|
||
if oc_file == OBSERVATORY_CODES: | ||
retriever = make_retriever(args.ar_data_file_path) | ||
if oc_file == sconfigs.auxiliary.observatory_codes: | ||
retriever = make_retriever(sconfigs, args.ar_data_file_path) | ||
|
||
# is the file available locally, if so, return the full path | ||
if os.path.isfile(os.path.join(retriever.abspath, OBSERVATORY_CODES)): | ||
obs_file_path = retriever.fetch(OBSERVATORY_CODES) | ||
if os.path.isfile(os.path.join(retriever.abspath, sconfigs.auxiliary.observatory_codes)): | ||
obs_file_path = retriever.fetch(sconfigs.auxiliary.observatory_codes) | ||
|
||
# if the file is not local, download, and decompress it, then return the path. | ||
else: | ||
obs_file_path = retriever.fetch( | ||
OBSERVATORY_CODES_COMPRESSED, processor=Decompress(name=OBSERVATORY_CODES) | ||
sconfigs.auxiliary.observatory_codes_compressed, | ||
processor=Decompress(name=sconfigs.auxiliary.observatory_codes), | ||
) | ||
|
||
else: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,13 +11,7 @@ | |
import numpy as np | ||
|
||
from sorcha.ephemeris.simulation_constants import * | ||
from sorcha.ephemeris.simulation_data_files import ( | ||
make_retriever, | ||
JPL_PLANETS, | ||
JPL_SMALL_BODIES, | ||
META_KERNEL, | ||
ORDERED_KERNEL_FILES, | ||
) | ||
from sorcha.ephemeris.simulation_data_files import make_retriever | ||
|
||
from sorcha.ephemeris.simulation_geometry import ( | ||
barycentricObservatoryRates, | ||
|
@@ -32,9 +26,12 @@ | |
from sorcha.utilities.generate_meta_kernel import build_meta_kernel_file | ||
|
||
|
||
def create_assist_ephemeris(args) -> tuple: | ||
def create_assist_ephemeris(args, sconfigs) -> tuple: | ||
"""Build the ASSIST ephemeris object | ||
|
||
Parameter | ||
--------- | ||
sconfigs: dataclass | ||
Dataclass of configuration file arguments. | ||
Returns | ||
--------- | ||
Ephem : ASSIST ephemeris obejct | ||
|
@@ -46,9 +43,9 @@ def create_assist_ephemeris(args) -> tuple: | |
""" | ||
pplogger = logging.getLogger(__name__) | ||
|
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
planets_file_path = retriever.fetch(sconfigs.auxiliary.jpl_planets) | ||
small_bodies_file_path = retriever.fetch(sconfigs.auxiliary.jpl_small_bodies) | ||
ephem = Ephem(planets_path=planets_file_path, asteroids_path=small_bodies_file_path) | ||
gm_sun = ephem.get_particle("Sun", 0).m | ||
gm_total = sum(sorted([ephem.get_particle(i, 0).m for i in range(27)])) | ||
|
@@ -59,27 +56,31 @@ def create_assist_ephemeris(args) -> tuple: | |
return ephem, gm_sun, gm_total | ||
|
||
|
||
def furnish_spiceypy(args): | ||
def furnish_spiceypy(args, sconfigs): | ||
""" | ||
Builds the SPICE kernel, downloading the required files if needed | ||
Parameters | ||
----------- | ||
sconfigs: dataclass | ||
Dataclass of configuration file arguments. | ||
""" | ||
# The goal here would be to download the spice kernel files (if needed) | ||
# Then call spice.furnish(<filename>) on each of those files. | ||
|
||
pplogger = logging.getLogger(__name__) | ||
|
||
retriever = make_retriever(args.ar_data_file_path) | ||
retriever = make_retriever(sconfigs, args.ar_data_file_path) | ||
|
||
for kernel_file in ORDERED_KERNEL_FILES: | ||
for kernel_file in sconfigs.auxiliary.ordered_kernel_files: | ||
retriever.fetch(kernel_file) | ||
|
||
# check if the META_KERNEL file exists. If it doesn't exist, create it. | ||
if not os.path.exists(os.path.join(retriever.abspath, META_KERNEL)): | ||
build_meta_kernel_file(retriever) | ||
if not os.path.exists(os.path.join(retriever.abspath, sconfigs.auxiliary.meta_kernel)): | ||
build_meta_kernel_file(sconfigs, retriever) | ||
|
||
# try to get the META_KERNEL file. If it's not there, error out. | ||
try: | ||
meta_kernel = retriever.fetch(META_KERNEL) | ||
meta_kernel = retriever.fetch(sconfigs.auxiliary.meta_kernel) | ||
except ValueError: | ||
pplogger.error( | ||
"ERROR: furnish_spiceypy: Must create meta_kernel.txt by running `bootstrap_sorcha_data_files` on the command line." | ||
|
@@ -181,11 +182,11 @@ def precompute_pointing_information(pointings_df, args, sconfigs): | |
pointings_df : pandas dataframe | ||
The original dataframe with several additional columns of precomputed values. | ||
""" | ||
ephem, _, _ = create_assist_ephemeris(args) | ||
ephem, _, _ = create_assist_ephemeris(args, sconfigs) | ||
|
||
furnish_spiceypy(args) | ||
furnish_spiceypy(args, sconfigs) | ||
obsCode = sconfigs.simulation.ar_obs_code | ||
observatories = Observatory(args) | ||
observatories = Observatory(args, sconfigs) | ||
|
||
# vectorize the calculation to get x,y,z vector from ra/dec | ||
vectors = ra_dec2vec( | ||
|
There was a problem hiding this comment.
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