Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel-p committed Aug 9, 2024
2 parents 70c0781 + 03b9e42 commit 6e23f6a
Show file tree
Hide file tree
Showing 13 changed files with 418 additions and 213 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">
<br>
<img src="/docs/_static/asteca_icon.webp" alt="UCC" width="200"/>
<img src="https://raw.githubusercontent.com/asteca/ASteCA/main/docs/_static/asteca_icon.webp" alt="asteca" width="200"/>
<br>
</div>

Expand Down
20 changes: 19 additions & 1 deletion asteca/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
from .likelihood import Likelihood as likelihood
from . import plot as plot

import os
from contextlib import suppress
import importlib.metadata
from pathlib import Path
import requests


__all__ = ["cluster", "membership", "isochrones", "synthetic", "likelihood", "plot"]
Expand All @@ -18,7 +20,6 @@ def extract_version() -> str:
found in nearby pyproject.toml
https://stackoverflow.com/a/76206192/1391441
"""
with suppress(FileNotFoundError, StopIteration):
pp_file = Path(__file__).parent.parent / "pyproject.toml"
Expand All @@ -35,3 +36,20 @@ def extract_version() -> str:


__version__ = extract_version()

# Check if an updated version exists.
# If this file exists, skip update check
if os.path.isfile("asteca_disable_check.txt") is False:
# Get the latest version from PyPI
pypi_url = "https://pypi.org/pypi/asteca/json"
pypi_response = requests.get(pypi_url, timeout=3)
pypi_data = pypi_response.json()
new_v = pypi_data["info"]["version"]

# Parse and compare versions
if new_v != __version__:
print("\n--------------------------------------------------")
print(f"New version of ASteCA is available: {__version__} -> {new_v}")
print(" Update with: pip install --upgrade asteca\n")
print(" See what's new at: http://asteca.github.io/")
print("--------------------------------------------------\n")
13 changes: 4 additions & 9 deletions asteca/isochrones.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import numpy as np
from .modules import isochrones_priv

Expand All @@ -15,8 +14,8 @@ class Isochrones:
`MIST <https://waps.cfa.harvard.edu/MIST/>`__, or
`BASTI <http://basti-iac.oa-abruzzo.inaf.it/isocs.html>`__.
:type model: str
:param isochs_path: Path to the folder that contains the files for the theoretical
isochrones
:param isochs_path: Path to the file or folder that contains the files for the
theoretical isochrones
:type isochs_path: str
:param magnitude: Magnitude's filter name as defined in the theoretical isochrones.
Example for Gaia's ``G`` magnitude: ``"Gmag"``
Expand Down Expand Up @@ -116,10 +115,6 @@ def __init__(
f"Model '{self.model}' not recognized. Should be one of {models}"
)

# Check path to isochrones
if os.path.isdir(self.isochs_path) is False:
raise ValueError(f"Path '{self.isochs_path}' not found")

print("\nInstantiating isochrones...")
# Load isochrone files
self.theor_tracks, self.color_filters, self.met_age_dict, N_isoch_files = (
Expand Down Expand Up @@ -162,13 +157,13 @@ def _func_z_to_FeH(self, z_to_FeH):
# Replace old values
self.met_age_dict["met"] = feh_r

def _min_max(self) -> tuple[float]:
def _min_max(self) -> tuple[float, float, float, float]:
"""Return the minimum and maximum values for the metallicity and age defined
in the theoretical isochrones.
:return: Tuple of (minimum_metallicity, maximum_metallicity, minimum_age,
maximum_age)
:rtype: tuple[float]
:rtype: tuple[float, float, float, float]
"""
zmin = self.met_age_dict["met"].min()
zmax = self.met_age_dict["met"].max()
Expand Down
2 changes: 1 addition & 1 deletion asteca/modules/fastmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def get_dims_norm(N_cluster, lon, lat, pmRA, pmDE, plx, xy_c, vpd_c, plx_c, st_i
# dims_norm = 2 * np.nanmedian(abs(data_mvd[st_idx]), 0)

# Use the IQR
dims_norm = np.nanpercentile(data_mvd[st_idx, :], [25, 75], axis=0).ptp(axis=0)
dims_norm = np.ptp(np.nanpercentile(data_mvd[st_idx, :], [25, 75], axis=0), axis=0)

data_norm = data_mvd / dims_norm
return data_norm
Expand Down
44 changes: 26 additions & 18 deletions asteca/modules/isochrones_priv.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}


def load(self) -> tuple[np.ndarray, list, dict]:
def load(self) -> tuple[np.ndarray, list, dict, int]:
r"""Load the theoretical isochrones and return a dictionary with the data.
Returns
Expand Down Expand Up @@ -92,28 +92,33 @@ def get_columns(self) -> tuple[list, str, str, str]:

def extract_paths(self) -> list:
r"""Extract isochrone files from `isochs_path`."""
f_paths = []
# Iterate over files in directory
for path, folders, files in os.walk(self.isochs_path):
# Skip hidden folders
if path.split("/")[-1].startswith("."):
continue
for filename in files:
# Skip hidden files
if not filename.startswith("."):
f_paths.append(os.path.join(path, filename))

if len(f_paths) == 0:
raise FileNotFoundError(
f"No files found in isochrones path '{self.isochs_path}'"
)

# Check if path is to file or folder
if os.path.isfile(self.isochs_path):
f_paths = [self.isochs_path]
else:
f_paths = []
# Iterate over files in directory
for path, folders, files in os.walk(self.isochs_path):
# Skip hidden folders
if path.split("/")[-1].startswith("."):
continue
for filename in files:
# Skip hidden files
if not filename.startswith("."):
f_paths.append(os.path.join(path, filename))

if len(f_paths) == 0:
raise FileNotFoundError(
f"No files found in isochrones path '{self.isochs_path}'"
)

return f_paths


def read(
model, N_interp, parsec_rm_stage_9, f_paths, met_col, age_col, cols_keep
) -> tuple[list, list]:
) -> dict:
""" """

group_col = {"PARSEC": met_col, "MIST": age_col, "BASTI": None}
Expand Down Expand Up @@ -185,7 +190,7 @@ def read(
def get_header(file_path):
"""Iterate through each line in the file to get the header"""
with open(file_path, mode="r") as f_iso:
full_header = []
full_header, column_names = [], ""
for i, line in enumerate(f_iso):
# Skip BASTI lines that look like this
if line.startswith("#====="):
Expand All @@ -195,6 +200,9 @@ def get_header(file_path):
break
column_names = line

if column_names == "":
raise ValueError(f"Could not extract header from file: {file_path}")

column_names = column_names.replace("#", "").split()

return column_names, full_header
Expand Down
13 changes: 13 additions & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
.. :changelog:
`[v0.5.8] <https://github.com/asteca/asteca/releases/tag/v0.5.8>`__ - 2024-08-09
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

- Downgraded the versions of almost all the required packages to play nice with
Google Colab
- Fix `AttributeError: `ptp` was removed from the ndarray class in NumPy 2.0. Use
np.ptp(arr, ...) instead.` for newer versions of `numpy`
- Allow `isochrones` to load single files, not just paths to folders
- Added an update notifier to `__init__.py` (added `requests` as requirement)



`[v0.5.7] <https://github.com/asteca/asteca/releases/tag/v0.5.7>`__ - 2024-07-31
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Expand Down
Binary file removed docs/_static/asteca_icon.png
Binary file not shown.
6 changes: 2 additions & 4 deletions docs/basic/cluster_load.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ or a color-magnitude plot with the :py:func:`asteca.plot.cluster` function:

.. code-block:: python
import matplotlib.pyplot as plt
ax = plt.subplot(111)
ax = my_cluster.clustplot(ax1)
ax = plt.subplot()
asteca.plot.cluster(my_cluster, ax)
plt.show()
which should results in something like this:
Expand Down
2 changes: 1 addition & 1 deletion docs/basic/isochrones_load.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Where:

- ``model`` : Model used to generate the isochrones. Must be one of the three
allowed models
- ``isochs_path`` : Path to the folder where the isochrone file(s) is(are) stored
- ``isochs_path`` : Path to the file or folder where the isochrone file(s) is(are) stored
- ``magnitude`` : Name of the magnitude column in the isochrone file(s)
- ``color`` : Name of the two filters that make up the color. Names must be
**in the proper order**, i.e. such that the color name is generated by subtracting
Expand Down
20 changes: 18 additions & 2 deletions docs/contents/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,24 @@
Installation
############

I recommend using the `conda`_ package and environment manager to install **ASteCA**
in an isolated Python environment. To install ``conda``, follow these steps:
**ASteCA** can be installed locally or in a
`Google Colaboratory <https://colab.google/>`_ notebook. To install in Google
Colaboratory use the following command in a new notebook:

.. code-block:: bash
!pip install asteca
To check that the installation was successful, import **ASteCA** and print the
installed version number with:

.. code-block:: bash
import asteca
asteca.__version__
If you want to install the package locally, I recommend using the `conda`_ package and environment manager to install **ASteCA** in an isolated Python environment.
To install with ``conda``, follow these steps:

1. Go to https://conda.io/miniconda.html and download the appropriate version
for your system. I will assume in what follows that you are running a 64 bit Linux
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extinction, distance, metallicity, age, binarity, mass, etc..


.. important::
Version |ProjectVersion| released on the 31st of July, 2024. See :ref:`changelog`
Version |ProjectVersion| released on the 9th of August, 2024. See :ref:`changelog`
for a detailed list of the changes implemented.


Expand Down
Loading

0 comments on commit 6e23f6a

Please sign in to comment.