From 963a1ab2f036d9af9bbf7550e75ac99db1a3e885 Mon Sep 17 00:00:00 2001 From: Nikhil Rao <44057004+AnonNick@users.noreply.github.com> Date: Thu, 5 Jun 2025 10:41:34 -0400 Subject: [PATCH] Added datafiles to package and removed KAIPYHOME --- MANIFEST.in | 1 + kaipy/cdaweb_utils.py | 16 +++++++--------- kaipy/scripts/datamodel/helioSatComp.py | 7 +++---- kaipy/scripts/quicklook/heliomovie.py | 8 ++++---- setup.py | 4 +++- 5 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..d3275a9 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include kaipy/satcomp/sc_helio.json \ No newline at end of file diff --git a/kaipy/cdaweb_utils.py b/kaipy/cdaweb_utils.py index b60e393..db4f9f5 100644 --- a/kaipy/cdaweb_utils.py +++ b/kaipy/cdaweb_utils.py @@ -2,6 +2,7 @@ import datetime import os import sys +import importlib.resources as pkg_resources # Import supplemental modules. from astropy.coordinates import SkyCoord @@ -16,6 +17,7 @@ from sunpy.coordinates import frames # Import project modules. import kaipy.kaiTools as kaiTools import kaipy.satcomp.scutils as scutils +from kaipy.satcomp import satcomp # """Simple utilitiles for fetching data from CDAWeb. @@ -34,6 +36,8 @@ import kaipy.satcomp.scutils as scutils # Format string for CDAWeb datetime strings. CDAWEB_DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ" +# Get the sc_helio.json file from the package and return a temporary file path. +sc_helio_json_path = pkg_resources.files(satcomp).joinpath("sc_helio.json") def fetch_satellite_geographic_position(spacecraft, when): """Fetch the geographic position of a satellite at a specified time. @@ -433,9 +437,7 @@ def fetch_helio_spacecraft_HGS_trajectory(spacecraft, t_start, t_end, mjdc): Tuple[np.array, np.array, np.array]: Cartesian coordinates (x, y, z) of the spacecraft in the HGS frame. """ # Read the CDAWeb spacecraft database. - spacecraft_data_file = os.path.join( - os.environ["KAIPYHOME"], "kaipy", "satcomp", "sc_helio.json" - ) + spacecraft_data_file = sc_helio_json_path sc_info = scutils.getScIds(spacecraft_data_file=spacecraft_data_file) # Create the CDAWeb connection. @@ -507,9 +509,7 @@ def fetch_helio_spacecraft_trajectory(sc_id, t_start, t_end): Tuple[np.array, np.array, np.array]: Cartesian coordinates (x, y, z) of the spacecraft in the HGS frame. """ # Read the CDAWeb spacecraft database. - sc_metadata_path = os.path.join( - os.environ["KAIPYHOME"], "kaipy", "satcomp", "sc_helio.json" - ) + sc_metadata_path = sc_helio_json_path sc_metadata = scutils.getScIds(spacecraft_data_file=sc_metadata_path) # Create the CDAWeb connection. @@ -545,9 +545,7 @@ def ingest_helio_spacecraft_trajectory(sc_id, sc_data, MJDc): z (dm.dmarray): The z-coordinate in the GH(MJDc) frame. """ # Read the CDAWeb spacecraft database. - sc_metadata_path = os.path.join( - os.environ["KAIPYHOME"], "kaipy", "satcomp", "sc_helio.json" - ) + sc_metadata_path = sc_helio_json_path sc_metadata = scutils.getScIds(spacecraft_data_file=sc_metadata_path) # Determine the coordinate system used by the CDAWeb ephemeris. diff --git a/kaipy/scripts/datamodel/helioSatComp.py b/kaipy/scripts/datamodel/helioSatComp.py index 7777873..9ffb941 100755 --- a/kaipy/scripts/datamodel/helioSatComp.py +++ b/kaipy/scripts/datamodel/helioSatComp.py @@ -18,6 +18,7 @@ Mike Wiltberger import argparse from argparse import RawTextHelpFormatter import os +import importlib.resources as pkg_resources # Third-party modules import numpy as np @@ -28,7 +29,7 @@ import kaipy.kaiH5 as kaiH5 import kaipy.kaiViz as kv import kaipy.kaiTools as kaiTools import kaipy.satcomp.scutils as scutils - +from kaipy import satcomp # Program constants. @@ -55,9 +56,7 @@ default_numSeg = 1 default_path = os.getcwd() # Path to file of heliospheric spacecraft metadata. -helio_sc_metadata_path = os.path.join( - os.environ["KAIPYHOME"], "kaipy", "satcomp", "sc_helio.json" -) +helio_sc_metadata_path = pkg_resources.files(satcomp).joinpath("sc_helio.json") def create_command_line_parser(): diff --git a/kaipy/scripts/quicklook/heliomovie.py b/kaipy/scripts/quicklook/heliomovie.py index 95f1707..722486e 100755 --- a/kaipy/scripts/quicklook/heliomovie.py +++ b/kaipy/scripts/quicklook/heliomovie.py @@ -60,6 +60,7 @@ Eric Winter (eric.winter@jhuapl.edu) import argparse import os import subprocess +import importlib.resources as pkg_resources # Import supplemental modules. import astropy.time @@ -78,6 +79,7 @@ import kaipy.gamhelio.heliosphere as hsph import kaipy.kaiH5 as kh5 import kaipy.kaiTools as ktools import kaipy.kaiViz as kv +from kaipy import satcomp from kaipy.satcomp import scutils @@ -106,9 +108,7 @@ default_movie_format = "mp4" valid_movie_formats = ("gif", "mp4") # Path to spacecraft metadata file. -sc_metadata_path = os.path.join( - os.environ["KAIPYHOME"], "kaipy", "satcomp", "sc_helio.json" -) +sc_metadata_path = pkg_resources.files(satcomp).joinpath("sc_helio.json") # Figure sizes by plot type, (width, height) in inches. figure_sizes = { @@ -124,7 +124,7 @@ figure_sizes = { # List of colors to use for spacecraft position dots. SPACECRAFT_COLORS = list(mpl.colors.TABLEAU_COLORS.keys()) - + def create_command_line_parser(): """ Create the command-line argument parser. diff --git a/setup.py b/setup.py index 1c9d5a3..ae04d11 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,9 @@ setup( url='https://bitbucket.org/aplkaiju/kaipy/src/master/', packages=find_packages(), include_package_data=True, - package_data={'kaipy': ['scripts/*', 'scripts/*/*']}, + package_data={'kaipy': ['scripts/*', 'scripts/*/*'], + 'kaipy.satcomp': ['sc_helio.json'] + }, python_requires='>=3.9,<=3.13', install_requires=[ 'alive_progress',