Skip to content

Commit

Permalink
Merge branch 'devel'. Bring 'main' to version 1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
MLWinther committed Mar 20, 2024
2 parents 6e0df7e + 846d188 commit bb936fc
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 52 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![ADS](https://img.shields.io/badge/ads-2022MNRAS.509.4344A-blue.svg)](https://ui.adsabs.harvard.edu/abs/2022MNRAS.509.4344A/abstract)
[![DOI](https://img.shields.io/badge/doi-10.1093/mnras/stab2911-orange.svg)](https://doi.org/10.1093/mnras/stab2911)

Current stable version: v1.4.0
Current stable version: v1.4.1

**Important note:** BASTA is currently developed for Python 3.12, but Python >= 3.9 should in principle suffice. *Please be aware that Python 3.12 will not* work if you need to fit glitches (please see the installation instructions) due to to known build issues in NumPy/f2py (as the glitch fitting relies on Fortran-routines) and we recommend 3.11 in that case.

Expand Down
2 changes: 1 addition & 1 deletion basta/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.4.0"
__version__ = "1.4.1"
166 changes: 119 additions & 47 deletions basta/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,11 @@ def read_allseismic(
def freqs_ascii_to_xml(
directory,
starid,
freqsfile: str | None = None,
covfile: str | None = None,
ratiosfile: str | None = None,
cov010file: str | None = None,
cov02file: str | None = None,
symmetric_errors=True,
check_radial_orders=False,
quiet=False,
Expand Down Expand Up @@ -984,11 +989,16 @@ def freqs_ascii_to_xml(
"""

# (Potential) filepaths
freqsfile = os.path.join(directory, starid + ".fre")
covfile = os.path.join(directory, starid + ".cov")
ratiosfile = os.path.join(directory, starid + ".ratios")
cov010file = os.path.join(directory, starid + ".cov010")
cov02file = os.path.join(directory, starid + ".cov02")
if freqsfile is None:
freqsfile = os.path.join(directory, starid + ".fre")
if covfile is None:
covfile = os.path.join(directory, starid + ".cov")
if ratiosfile is None:
ratiosfile = os.path.join(directory, starid + ".ratios")
if cov010file is None:
cov010file = os.path.join(directory, starid + ".cov010")
if cov02file is None:
cov02file = os.path.join(directory, starid + ".cov02")

# Flags for existence of ratios and covariances
cov_flag, ratios_flag, cov010_flag, cov02_flag = 1, 1, 1, 1
Expand Down Expand Up @@ -1237,8 +1247,8 @@ def freqs_ascii_to_xml(


def _read_freq_ascii(
filename,
symmetric_errors=True,
filename: str,
symmetric_errors: bool = True,
):
"""
Read individual frequencies from an ascii file
Expand All @@ -1260,45 +1270,95 @@ def _read_freq_ascii(
"""
cols = []
data = np.genfromtxt(filename, dtype=None, encoding=None, names=True)

rdict = {
"frequency": {
"dtype": "float",
"recognisednames": [
"f",
"freq",
"freqs",
"frequency",
"modefrequency",
],
},
"order": {
"dtype": "int",
"recognisednames": [
"n",
"ns",
"order",
"radialorder",
],
},
"degree": {
"dtype": "int",
"recognisednames": [
"l",
"ls",
"ell",
"ells",
"degree",
"angulardegree",
],
},
"error": {
"dtype": "float",
"recognisednames": [
"error",
"err",
"e",
"uncertainty",
"uncert",
],
},
"error_plus": {
"dtype": "float",
"recognisednames": [
"error_plus",
"err_plus",
"error_upper",
"upper_error",
],
},
"error_minus": {
"dtype": "float",
"recognisednames": [
"error_minus",
"err_minus",
"error_lower",
"lower_error",
],
},
"flag": {
"dtype": "int",
"recognisednames": [
"flag",
],
},
"frequency_mode": {
"dtype": "float",
"recognisednames": [
"frequency_mode",
],
},
}

for colname in data.dtype.names:
if colname.lower() in ["f", "freq", "frequency"]:
cols.append(
("frequency", "float"),
)
elif colname.lower() in ["n", "order"]:
cols.append(
("order", "int"),
)
elif colname.lower() in ["l", "ell", "degree"]:
cols.append(
("degree", "int"),
)
elif colname.lower() in ["error_plus", "err_plus", "error_upper"]:
cols.append(
("error_plus", "float"),
)
elif colname.lower() in ["error_minus", "err_minus", "error_lower"]:
cols.append(
("error_minus", "float"),
)
elif colname.lower() in [
"error",
"err",
]:
cols.append(("error", "float"))
elif colname.lower() in [
"flag",
]:
cols.append(("flag", "int"))
elif colname.lower() in [
"frequency_mode",
]:
cols.append(("frequency_mode", "float"))
else:
param = [p for p in rdict if colname.lower() in rdict[p]["recognisednames"]]
if not param:
raise ValueError(f"BASTA cannot recognize {colname}")
assert len(param) == 1, (colname, param)
cols.append((param[0], rdict[param[0]]["dtype"]))

sym = np.any([col[0] == "error" for col in cols])
asym = all(item in col[0] for col in l for item in ["error_plus", "error_minus"])
asym = all(
[
item in col[0]
for col in cols
for item in rdict["error_plus"]["recognisednames"]
]
)
if not sym ^ asym:
if sym | asym:
raise ValueError(
Expand All @@ -1318,10 +1378,22 @@ def _read_freq_ascii(
)

if not np.any(["order" in col[0] for col in cols]):
print("BASTA did not find n orders, they are generated")
freqcol = [col for col in data.dtype.names if col in ["f", "freq", "frequency"]]
assert len(freqcol) == 1, print(freqcol)
dnu = data[freqcol[0]][1] - data[freqcol[0]][0]
print("BASTA did not find column with radial orders, they will be generated")

freqcol = [
col
for col in data.dtype.names
if col in rdict["frequency"]["recognisednames"]
]
lcol = [
col for col in data.dtype.names if col in rdict["degree"]["recognisednames"]
]
assert len(freqcol) == 1, freqcol
assert len(lcol) == 1, lcol
mask = data[lcol[0]] == 0
l0s = data[freqcol[0]][mask]
assert len(l0s) > 1, "More than 1 l=0 mode is required for estimation of dnu"
dnu = np.median(np.diff(l0s))
ns = np.asarray(data[freqcol[0]]) // dnu - 1
from numpy.lib.recfunctions import append_fields

Expand All @@ -1330,7 +1402,7 @@ def _read_freq_ascii(
return freqs


def _read_freq_cov_ascii(filename):
def _read_freq_cov_ascii(filename: str):
"""
Read covariance and correlations for individual frequencies from an
ascii file
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
author = "The BASTA Team"

# The short X.Y version.
version = "1.4.0"
version = "1.4.1"

# The full version, including alpha/beta/rc tags.
release = "1.4.0"
release = "1.4.1"


# -- General configuration ------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ BASTA is a Python-based fitting tool designed to determine properties of stars u
models. It calculates the probability density function of a given stellar property based on a set of observational
constraints defined by the user.

Current stable version: v1.4.0
Current stable version: v1.4.1

*Please follow the repository on* `GitHub <https://github.com/BASTAcode/BASTA>`_ *to get notifications on new releases: Click "Watch" then "Custom" and tick "Releases.*

Expand Down

0 comments on commit bb936fc

Please sign in to comment.