Skip to content

Commit

Permalink
replace pkg_resources with importlib_resources
Browse files Browse the repository at this point in the history
  • Loading branch information
petiay committed May 23, 2024
1 parent b41914c commit 6288b68
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
7 changes: 3 additions & 4 deletions beast/physicsmodel/stars/ezmist/mist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
# -------------

Expand Down
8 changes: 4 additions & 4 deletions beast/physicsmodel/stars/ezpadova/parsec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
Expand Down
13 changes: 6 additions & 7 deletions beast/tools/compare_spec_type.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)):
Expand Down Expand Up @@ -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)):
Expand Down

0 comments on commit 6288b68

Please sign in to comment.