ezpadova package#

Submodules#

ezpadova.config module#

Configuration file for the EzPadova package.

It provides functions to update the configuration from the CMD webpage and validate query parameters for isochrone generation. It also contains the default values for the configuration parameters.

generate_doc()[source]#

Generate the documentation from the config variable.

Returns:

The generated documentation in markdown format.

Return type:

str

reload_configuration()[source]#

Reloads the configuration from a JSON file.

This function determines the base directory of the current file and constructs the path to the configuration file named ‘config.json’. If the configuration file exists, it loads the configuration from the file and updates the global configuration dictionary. If the configuration file does not exist, it calls the update_config function to create a new configuration and writes it to the ‘config.json’ file.

Raises:
  • FileNotFoundError – If the configuration file does not exist and update_config: fails to create a new configuration.

  • json.JSONDecodeError – If the configuration file contains invalid JSON.:

update_config()[source]#

Update the configuration of the package from parsing the website

validate_query_parameter(**kw)[source]#

Validates the query parameters for isochrone generation.

Parameters:

kw (dict) –

A dictionary of keyword arguments containing the following keys

  • isoc_agelow : float, Lower age limit.

  • isoc_ageupp : float, Upper age limit.

  • isoc_lagelow : float, Lower log age limit.

  • isoc_lageupp : float, Upper log age limit.

  • isoc_zlow : float, Lower metallicity (Z) limit.

  • isoc_zupp : float, Upper metallicity (Z) limit.

  • isoc_metlow : float, Lower [M/H] limit.

  • isoc_metupp : float, Upper [M/H] limit.

  • photsys_file : str, Photometric system file.

  • imf_file : str, Initial Mass Function (IMF) file.

  • track_parsec : str, PARSEC track identifier.

  • track_omegai : float, Initial rotation velocity.

  • track_colibri : str, COLIBRI track identifier.

  • dust_sourceC : str, Dust source for carbon stars.

  • dust_sourceM : str, Dust source for M-type stars.

  • extinction_coeff : str, Extinction coefficient.

  • extinction_curve : str, Extinction curve.

  • kind_LPV : str, Long Period Variable (LPV) kind.

  • photsys_version : str, Photometric system version.

Raises:

ValueError – If any of the parameters are invalid or out of the expected range.

ezpadova.deprecated module#

Deprecated functions from previous version that are kept here for backward compatibility.

get_Z_isochrones(z0, z1, dz, age_yr=None, logage=None, ret_table=True, **kwargs)[source]#

Retrieve isochrones for a given metallicity range and age.

Parameters:
  • z0 (float) – Lower bound of the metallicity range in Z units.

  • z1 (float) – Upper bound of the metallicity range in Z units.

  • dz (float) – Step size for the metallicity range in Z units.

  • age_yr (float, optional) – Age in years. Either age_yr or logage must be provided, but not both.

  • logage (float, optional) – Logarithm of the age. Either age_yr or logage must be provided, but not both.

  • ret_table (bool, optional) – If True, return the result as a DataFrame. Default is True.

  • kwargs (dict) – Additional keyword arguments to be passed to the get_isochrones function.

Returns:

Isochrones data, format depends on ret_table parameter.

Return type:

pd.DataFrame or bytes

Raises:

ValueError – If neither age_yr nor logage is provided, or if both are provided.

Deprecated since version 2.0: get_Z_isochrones is deprecated and will be removed in a future version. Use ezpadova.parsec.get_isochrones() instead.

get_one_isochrone(age_yr=None, Z=None, logage=None, MH=None, ret_table=True, **kwargs)[source]#

Get one isochrone at a given time and metallicity content.

Parameters:
  • age_yr (float, optional) – Age in years. Either age_yr or logage must be provided, but not both.

  • Z (float, optional) – Metallicity. Either Z or MH must be provided, but not both.

  • logage (float, optional) – Logarithm of age. Either logage or age_yr must be provided, but not both.

  • MH (float, optional) – Metallicity in terms of [M/H]. Either MH or Z must be provided, but not both.

  • ret_table (bool, optional) – If True, return the result as a DataFrame. Default is True.

  • kwargs (dict) – Additional keyword arguments to be passed to the get_isochrones function.

Returns:

The isochrone data, format depends on ret_table parameter.

Return type:

pd.DataFrame or bytes

Raises:
  • ValueError – If neither age_yr nor logage is provided.

  • ValueError – If both age_yr and logage are provided.

  • ValueError – If neither Z nor MH is provided.

  • ValueError – If both Z and MH are provided.

Deprecated since version 2.0: get_one_isochrone is deprecated and will be removed in a future version. Use ezpadova.parsec.get_isochrones() instead.

get_t_isochrones(logt0, logt1, dlogt, Z=None, MH=None, ret_table=True, **kwargs)[source]#

Retrieve isochrones for a given age range and metallicity.

Parameters:
  • logt0 (float) – Lower bound of the age range in log10(years).

  • logt1 (float) – Upper bound of the age range in log10(years).

  • dlogt (float) – Step size for the age range in log10(years).

  • Z (float, optional) – Metallicity. Either Z or MH must be provided, but not both.

  • MH (float, optional) – Metallicity in terms of [M/H]. Either Z or MH must be provided, but not both.

  • ret_table (bool, optional) – If True, return the result as a DataFrame. Default is True.

  • kwargs (dict) – Additional keyword arguments to be passed to the get_isochrones function.

Returns:

Isochrones data, format depends on ret_table parameter.

Return type:

pd.DataFrame or bytes

Raises:

ValueError – If neither Z nor MH is provided, or if both are provided.

Deprecated since version 2.0: get_t_isochrones is deprecated and will be removed in a future version. Use ezpadova.parsec.get_isochrones() instead.

ezpadova.interpolate module#

A quick isochrone interpolator from PARSEC cmd input file.

>>> iso = QuickIsochrone("filename.txt")
>>> cluster_logAge = 8.3
>>> cluster_mh = -0.2
>>> cluster_isochrone = iso(cluster_logAge, cluster_mh)
class QuickInterpolator[source]#

Bases: object

Quick and “no so dirty” isochrone interpolation

Isochrones are defined by (logAge, MH, evolution state) triplet. The latter dimension is indicated by label in the parsec isochrones. However, only integers are reported.

For any input (logAge, MH) pair, we first bracket these values with the available models.

Each of the 4 neighbor combinations corresponding to a single isochrone, we recompute the float values of label into evol.

Finally, using the 4 isochrones we interpolate any quantity from (logAge, MH, evol) input dimensions. The interpolation uses LinearNDInterpolator.

__init__(fname)[source]#

Initialize the interpolation object with isochrone data.

Parameters:

fname (Union[str, pd.DataFrame]) – If a string is provided, it should be the file path to a file containing isochrone data. If a pandas DataFrame is provided, it should contain the isochrone data directly.

data#

The isochrone data indexed by ‘logAge’ and ‘MH’.

Type:

pd.DataFrame

coords#

A dictionary containing unique values of ‘logAge’ and ‘MH’ from the isochrone data.

Type:

dict

ndim#

The number of dimensions in the coordinates.

Type:

int

interpolation_keys#

A tuple containing the keys used for interpolation: ‘logAge’, ‘MH’, ‘evol’.

Type:

tuple

static add_evolution_phase(iso, inplace=False)[source]#

Add evol field which expands label into continuous quantities

Parameters:
  • iso (DataFrame) –

  • inplace (bool) –

Return type:

DataFrame

get_bracket_coordinates(*args)[source]#

Get the 4 coordinate pairs around the input (logAge, MH)

Return type:

Sequence[Number]

get_closest(logAge, MH)[source]#

Returns the table corresponding to the closest isochrone from (logAge, MH)

Parameters:
  • logAge (float) –

  • MH (float) –

Return type:

DataFrame

get_closest_coordinates(*args)[source]#

returns the closest (logAge, MH) from the input coordinates

Return type:

Sequence[Number]

static get_interp_data(iso)[source]#

Extract interpolation dimensions: (logAge, MH, evol)

Parameters:

iso (DataFrame) –

Return type:

array

ezpadova.parsec module#

Module for querying the CMD website and parsing the results.

build_query(**kwargs)[source]#

Update parameters to match the website requirements.

This function takes keyword arguments, updates them with default values from the configuration, and modifies certain keys to match the expected format required by the website.

Parameters:

kwargs (dict) – Arbitrary keyword arguments that will be used to update the default configuration values and passed as values to the online form.

Returns:

A dictionary of updated parameters with keys modified to match the website’s requirements.

Return type:

dict

get_isochrones(age_yr=None, Z=None, logage=None, MH=None, default_ranges=False, return_df=True, **kwargs)[source]#

Retrieve isochrones based on specified parameters.

Parameters:
  • age_yr (Tuple[float, float, float] | None) – A triplet of numbers representing the lower bound, upper bound, and step size for age in years. Either age_yr or logage must be provided, but not both.

  • Z (Tuple[float, float, float] | None) – A triplet of numbers representing the lower bound, upper bound, and step size for metallicity Z. Either Z or MH must be provided, but not both.

  • logage (Tuple[float, float, float] | None) – A triplet of numbers representing the lower bound, upper bound, and step size for logarithmic age. Either logage or age_yr must be provided, but not both.

  • MH (Tuple[float, float, float] | None) – A triplet of numbers representing the lower bound, upper bound, and step size for metallicity [M/H]. Either MH or Z must be provided, but not both.

  • default_ranges (bool, optional) – If True, use the default parameter ranges. Default is False.

  • return_df (bool, optional) – If True, return the result as a pandas DataFrame. If False, return the raw bytes. Default is True.

  • kwargs (dict) – Additional keyword arguments to pass to the query.

Returns:

The queried isochrones, either as a pandas DataFrame or raw bytes, depending on the value of return_df.

Return type:

pd.DataFrame | bytes

Raises:

ValueError – If the provided parameters are inconsistent or invalid.

parse_result(data, comment='#')[source]#

Parses the input data and returns a pandas DataFrame.

Parameters:
  • data (str | bytes | BufferedReader) – The input data to be parsed. It can be a string, bytes, or a BufferedReader object.

  • comment (str) – The character used to denote comment lines in the input data. Default is ‘#’.

Returns:

A pandas DataFrame containing the parsed data. The DataFrame will have an attribute ‘comment’ which contains the comment lines from the input data.

Return type:

pd.DataFrame

Note

  • If the input data is a BufferedReader, it will be read and decoded as ‘utf-8’.

  • The function assumes that the header line is the first non-comment line in the input data.

  • The DataFrame is created by reading the input data with pandas.read_csv, using whitespace as the delimiter.

  • The comment lines from the input data are stored in the ‘comment’ attribute of the DataFrame.

query(**kwargs)[source]#

Query the CMD webpage with the given parameters.

This function sends a POST request to the CMD webpage specified in the configuration and retrieves the resulting data. The data is then processed and returned as bytes. If the server response is incorrect or if there is an issue with the data retrieval, a RuntimeError is raised.

Parameters:

**kwargs – Arbitrary keyword arguments to be included in the query.

Returns:

The retrieved data from the CMD webpage.

Return type:

bytes

Raises:

RuntimeError – If the server response is incorrect or if there is an issue with data retrieval.

resample_evolution_label(data)[source]#

Resample the evolution label in the given DataFrame.

This function processes the input DataFrame by grouping it based on ‘logAge’ and ‘MH’ columns, and then resamples the ‘label’ column to add a continuous ‘evol’ column. The ‘evol’ column represents the evolution field with continuous quantities.

Parameters:

data (pd.DataFrame) – The input DataFrame containing the ‘logAge’, ‘MH’, and ‘label’ columns.

Returns:

The DataFrame with the added ‘evol’ column containing continuous quantities.

Return type:

pd.DataFrame

ezpadova.test_config module#

ezpadova.tools module#

This module contains utility functions used by the ezpadova package.

dedent(text)[source]#

Remove any common leading whitespace from every line in text.

This can be used to make triple-quoted strings line up with the left edge of the display, while still presenting them in the source code in indented form.

Note that tabs and spaces are both treated as whitespace, but they are not equal: the lines “ hello” and “thello” are considered to have no common leading whitespace.

Entirely blank lines are normalized to a newline character.

Parameters:

text (str) –

Return type:

str

deprecated_replacedby(replace_by)[source]#

This is a decorator which can be used to mark functions as deprecated.

Parameters:

replace_by (str) – The name of the function that should be used instead of the deprecated one.

Returns:

A decorator that can be applied to functions to mark them as deprecated.

Return type:

function

Example

@deprecated_replacedby('new_function')
def old_function():
    '''This is the old function.'''
    pass

# When old_function is called, a DeprecationWarning will be issued, and the docstring will be updated to indicate the deprecation.
get_file_archive_type(filename, stream=False)[source]#

Detect the type of a potentially compressed file.

This function checks the beginning of a file to determine if it is compressed using gzip, bzip2, or zip formats. It returns the corresponding file type if a compression is detected, otherwise it returns None.

Parameters:
  • filename (str | BytesIO) – The path to the file or a BytesIO stream to check.

  • stream (bool) – If True, filename is treated as a BytesIO stream. If False, filename is treated as a file path.

Returns:

The type of compression detected (‘gz’, ‘bz2’, ‘zip’), or None if

no compression is detected.

Return type:

str | None