From 6288b684c170a933cd594536d45dc827d9df59f1 Mon Sep 17 00:00:00 2001 From: Petia Yanchulova Merica-Jones Date: Thu, 23 May 2024 14:29:56 -0400 Subject: [PATCH] replace pkg_resources with importlib_resources --- beast/physicsmodel/stars/ezmist/mist.py | 7 +++---- beast/physicsmodel/stars/ezpadova/parsec.py | 8 ++++---- beast/tools/compare_spec_type.py | 13 ++++++------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/beast/physicsmodel/stars/ezmist/mist.py b/beast/physicsmodel/stars/ezmist/mist.py index ef996bd45..241e741c2 100644 --- a/beast/physicsmodel/stars/ezmist/mist.py +++ b/beast/physicsmodel/stars/ezmist/mist.py @@ -8,7 +8,7 @@ :author: MF """ -from pkg_resources import resource_filename +from importlib_resources import files, as_file from urllib import request from urllib.request import urlopen @@ -20,12 +20,11 @@ py3k = True -localpath = resource_filename("beast", "physicsmodel/stars/ezmist") +localpath = str(files('beast.physicsmodel.stars.ezmist').joinpath('mist.json')) -with open(localpath + "/mist.json") as f: +with open(localpath) as f: _cfg = json.load(f) - # Help messages # ------------- diff --git a/beast/physicsmodel/stars/ezpadova/parsec.py b/beast/physicsmodel/stars/ezpadova/parsec.py index 06007338c..44989f88d 100644 --- a/beast/physicsmodel/stars/ezpadova/parsec.py +++ b/beast/physicsmodel/stars/ezpadova/parsec.py @@ -5,8 +5,8 @@ :version: 1.1 :author: MF """ - -from pkg_resources import resource_filename +import beast +from importlib_resources import files, as_file from urllib.parse import urlencode from urllib import request @@ -21,9 +21,9 @@ py3k = True -localpath = resource_filename("beast", "physicsmodel/stars/ezpadova") +localpath = str(files('beast.physicsmodel.stars.ezpadova').joinpath('parsec.json')) -with open(localpath + "/parsec.json") as f: +with open(localpath) as f: _cfg = json.load(f) map_carbon_stars = _cfg["map_carbon_stars"] map_phot = _cfg["map_phot"] diff --git a/beast/tools/compare_spec_type.py b/beast/tools/compare_spec_type.py index 4a4f0134d..e1ab630b4 100644 --- a/beast/tools/compare_spec_type.py +++ b/beast/tools/compare_spec_type.py @@ -1,7 +1,7 @@ import numpy as np from collections import defaultdict from scipy.interpolate import RegularGridInterpolator -import pkg_resources +from importlib_resources import files from astropy.table import Table from astropy.coordinates import SkyCoord @@ -258,9 +258,9 @@ def setup_teff_table(): function to interpolate across the T_eff table """ - # read in the table - data_path = pkg_resources.resource_filename("beast", "tools/data/") - teff_table = Table.read(data_path + "effective_temperature.txt", format="ascii") + data_path = str(files("beast.tools.data").joinpath("effective_temperature.txt")) + print(data_path) + teff_table = Table.read(data_path, format="ascii") # make each row a number rather than a letter+number teff_table["row_id"] = np.zeros(len(teff_table)) for i in range(len(teff_table)): @@ -299,9 +299,8 @@ def setup_logg_table(): function to interpolate across the log(g) table """ - # read in the table - data_path = pkg_resources.resource_filename("beast", "tools/data/") - logg_table = Table.read(data_path + "surface_gravity.txt", format="ascii") + data_path = str(files("beast.tools.data").joinpath("surface_gravity.txt")) + logg_table = Table.read(data_path, format="ascii") # make each row a number rather than a letter+number logg_table["row_id"] = np.zeros(len(logg_table)) for i in range(len(logg_table)):