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 Apr 18, 2024
2 parents 1c7bdc4 + 0cb3e06 commit 2111a16
Show file tree
Hide file tree
Showing 224 changed files with 24,493 additions and 100,864 deletions.
23 changes: 16 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
# ignore everything in root
/*
# except for this file
!asteca.py
# except for these files
!README.md
!CHANGELOG.rst
!LICENSE.txt
# and this folder
!/packages
# But do ignore these files
!poetry.lock
!pyproject.toml
!.readthedocs.yaml

# and these folderers
!/asteca
!/docs

# But ignore these files
*.pyc
*.pickle

# and ignore these folders
/docs/build/*
/docs/autoapi/*
# Jupyter Notebook
.ipynb_checkpoints
35 changes: 35 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Read the Docs configuration file for Sphinx projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.12"
# You can also specify other tool versions:
# nodejs: "20"
# rust: "1.70"
# golang: "1.20"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py
# You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
# builder: "dirhtml"
# Fail on all warnings to avoid broken references
# fail_on_warning: true

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: docs/requirements.txt
695 changes: 21 additions & 674 deletions LICENSE.txt

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@

# ASteCA [Automated Stellar Cluster Analysis]
[![AA](https://img.shields.io/badge/A%26A-576--A6,%202015-yellowgreen.svg)][1]
[![License](https://img.shields.io/badge/license-GPLv3-red.svg)][2]
[![License](https://img.shields.io/badge/license-MIT-blue)][2]

The ASteCA package is designed to fully automatize the usual tests
applied on star clusters in order to estimate their characteristics and
fundamental parameters. The package is still be *under heavy development*.
For an up to date description please refer to the
[documentation][3]. The latest release can be accessed [here][4].
**ASteCA** is a package designed to automatize the usual analysis applied on star
clusters, in order to estimate their characteristics and fundamental parameters.

If you use this package please cite its accompanying [article][1] using the
Install with:

```
pip install asteca
```

See the [documentation](https://asteca.github.io) for more details. If you use this
package in your research, please cite its accompanying [article][1] using the following
Bibtex:

````
Expand All @@ -27,7 +31,7 @@ Bibtex:
````

[1]: http://www.aanda.org/articles/aa/abs/2015/04/aa24946-14/aa24946-14.html
[2]: http://www.gnu.org/licenses/gpl-3.0.en.html
[2]: https://opensource.org/license/mit/
[3]: http://asteca.github.io
[4]: https://github.com/asteca/asteca/releases/latest

Expand Down
5 changes: 0 additions & 5 deletions asteca.py

This file was deleted.

32 changes: 32 additions & 0 deletions asteca/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from .isochrones import isochrones
from .synthetic import synthetic
from .cluster import cluster
from .likelihood import likelihood

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


def extract_version() -> str:
"""Returns either the version of the installed package or the one
found in nearby pyproject.toml
https://stackoverflow.com/a/76206192/1391441
"""
with suppress(FileNotFoundError, StopIteration):
pp_file = Path(__file__).parent.parent / "pyproject.toml"
with open(pp_file, encoding="utf-8") as pyproject_toml:
version = (
next(line for line in pyproject_toml if line.startswith("version"))
.split("=")[1]
.strip("'\"\n ")
)
return f"{version}"
# return importlib.metadata.version(__package__
# or __name__.split(".", maxsplit=1)[0])
return importlib.metadata.version(__package__ or __name__)


__version__ = extract_version()
168 changes: 168 additions & 0 deletions asteca/cluster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
from dataclasses import dataclass
from typing import Optional
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt


@dataclass
class cluster:
r"""Define a ``cluster`` object.
Parameters
----------
cluster_df : pd.DataFrame
pandas DataFrame with the cluster's loaded data
magnitude : str
Name of the DataFrame column that contains the magnitude
e_mag : str
Name of the DataFrame column that contains the magnitude's uncertainty
color : str
Name of the DataFrame column that contains the color
e_color : str
Name of the DataFrame column that contains the color's uncertainty
ra: str, optional, default=None
Name of the DataFrame column that contains the right ascension (RA)
dec: str, optional, default=None
Name of the DataFrame column that contains the declination (DEC)
plx: str, optional, default=None
Name of the DataFrame column that contains the parallax
pmra: str, optional, default=None
Name of the DataFrame column that contains the RA proper motion
pmde: str, optional, default=None
Name of the DataFrame column that contains the DEC proper motion
color2: str, optional, default=None
Name of the DataFrame column that contains the second color
e_color2: str, optional, default=None
Name of the DataFrame column that contains the second color's uncertainty
"""
cluster_df: pd.DataFrame
magnitude: str
e_mag: str
color: str
e_color: str
ra: Optional[str] = None
dec: Optional[str] = None
plx: Optional[str] = None
pmra: Optional[str] = None
pmde: Optional[str] = None
color2: Optional[str] = None
e_color2: Optional[str] = None

def __post_init__(self):
# Load photometry
self._load()

def _load(self):
"""
The photometry is store with a '_p' to differentiate from the self.magnitude,
self.color, etc that are defined with the class is called.
"""
print("Reading and processing cluster data")

self.mag_p = np.array(self.cluster_df[self.magnitude])
self.e_mag_p = np.array(self.cluster_df[self.e_mag])

self.colors_p = [np.array(self.cluster_df[self.color])]
if self.color2 is not None:
self.colors_p.append(np.array(self.cluster_df[self.color2]))
self.e_colors_p = [np.array(self.cluster_df[self.e_color])]
if self.e_color2 is not None:
self.e_colors_p.append(np.array(self.cluster_df[self.e_color2]))

if self.ra is not None:
self.ra_v = self.cluster_df[self.ra]
self.dec_v = self.cluster_df[self.dec]

print("Cluster object generated\n")

def radecplot(self):
r"""Generate a (RA, DEC) plot.
Returns
-------
matplotlib.axis
Matplotlib axis object
"""
ra = self.ra_v # cluster_df[self.ra].values
dec = self.dec_v # cluster_df[self.dec].values
mag = self.mag_p # self.cluster_df[self.magnitude].values

msk = ~np.isnan(mag)
ra = ra[msk]
dec = dec[msk]
mag = mag[msk]

# Mag to flux
sizes = 10 ** (mag / -2.5)
# Normalize to 1
sizes /= sizes.max()
# Set min, max
sizes = 1 + 75 * sizes

f, ax = plt.subplots()
plt.scatter(ra, dec, s=sizes, c="k", alpha=0.7)
plt.xlabel("RA")
plt.ylabel("DEC")
plt.gca().invert_xaxis()

return ax

def clustplot(self, ax=None, binar_prob=None):
r"""Generate a color-magnitude plot.
Parameters
----------
ax : matplotlib.axis, optional, default=None
Matplotlib axis where to draw the plot
binar_prob : numpy.array, optional, default=None
Array with probabilities of being a binary system for each observed star
Returns
-------
matplotlib.axis
Matplotlib axis object
"""
if ax is None:
f, ax = plt.subplots()

if binar_prob is not None:
msk_binar = binar_prob > 0.5

mag_col = self.magnitude
col_col = self.color

if binar_prob is None:
ax.scatter(
self.colors_p[0],
self.mag_p,
c="green",
alpha=0.5,
label=f"Observed, N={len(self.mag_p)}",
)
else:
ax.scatter(
self.colors_p[0][~msk_binar],
self.mag_p[~msk_binar],
c="green",
alpha=0.5,
label=f"Observed (single), N={len(self.mag_p[~msk_binar])}",
)
ax.scatter(
self.colors_p[0][msk_binar],
self.mag_p[msk_binar],
c="red",
alpha=0.5,
label=f"Observed (binary), N={len(self.mag_p[msk_binar])}",
)

ax.set_ylim(max(self.mag_p) + .5, min(self.mag_p) - .5)
ax.set_xlabel(col_col)
ax.set_ylabel(mag_col)
ax.legend()

return ax
Loading

0 comments on commit 2111a16

Please sign in to comment.