Skip to main content

Galaxian Luminosity Function Constructor package using the 1/Vmax estimator and Schechter model.

Project description

Luminosity Function Constructor and Modeller

This package allows the user to construct and model Galaxian Luminosity Functions using the 1/Vmax estimator and Schechter function.

PyPI PyPI - Python Version PyPI - Downloads GitHub issues GitHub stars GitHub forks GitHub license

Installation

Use the package manager pip to install lumfunc.

pip install lumfunc

Keep the package up to date to access all commands.

pip install --upgrade lumfunc

Usage

Import the module in your Python code.

import lumfunc as lf

Load the catalogued data from survey. Usually stored in .fits or .csv files.

import numpy as np
import pandas as pd

# test data (photometric galaxian survey)
data_table = pd.read_csv('test_catalogue.csv')
RA_list = np.array(data_table['RA'])
Dec_list = np.array(data_table['Dec'])
r_app_mag_list = np.array(data_table['r_mag'])
r_app_mag_err_list = np.array(data_table['r_mag_err'])
z_photo_list = np.array(data_table['z_photo'])
get_maggy( ): Convert the measurements of flux in magnitudes to maggies for use with kcorrect_python:

Return maggies from magnitudes.

r_maggies_list = lf.get_maggy(r_app_mag_list) 
print(r_maggies_list[0:4])
# returns 
# [1.83315843e-08 2.27614539e-08 1.33659552e-08 1.13031632e-07]

# rudimentarily:
lf.get_maggy(np.array([19.342, 19.107, 19.685, 17.367]))
# returns
# array([1.83315843e-08, 2.27614539e-08, 1.33659552e-08, 1.13031632e-07])

get_maggy_inv_var( ): Convert the magnitude errors to maggy inverse variances for use with kcorrect_python

Return maggy inverse variances from maggies and magnitude errors.

r_maggy_inv_var_list = lf.get_maggy_inv_var(r_maggies_list, r_app_mag_err_list)
print(r_maggy_inv_var_list[0:4])
# returns 
# [2.19244475e+20 5.68838063e+20 4.12409497e+20 9.22674759e+19]

# rudimentarily:
lf.get_maggy_inv_var(np.array([1.83315843e-08, 2.27614539e-08, 1.33659552e-08, 1.13031632e-07]),
                     np.array([0.004, 0.002, 0.004, 0.001]))
# returns
# array([2.19244474e+20, 5.68838064e+20, 4.12409494e+20, 9.22674766e+19])

get_rest_mag( ): Convert the measured apparent magnitudes into rest-frame magnitudes using the catalogue data and output from kcorrect_python functions

Load maggy ratios output file from kcorrect_python.

maggy_ratios_table = pd.read_csv('test_maggy_ratios.csv', delimiter=' ')
r_maggy_ratio_list = np.array(maggy_ratios_table['maggy_ratio'])

Return rest-frame magnitudes from the apparent magnitudes, redshifts and maggy ratios.

r_rest_mag_list = lf.get_rest_mag(z_photo_list, r_app_mag_list, r_maggy_ratio_list)
print(r_rest_mag_list[0:4])
# returns 
# [-22.89979359 -21.51881811 -23.02717126 -20.79614551]

# rudimentarily:
lf.get_rest_mag(np.array([0.42, 0.24, 0.46, 0.09]),
                np.array([19.342, 19.107, 19.685, 17.367]),
                np.array([0.67165941, 0.81335927, 0.54066526, 0.91925443]))
# returns
# array([-22.8997936 , -21.51881811, -23.02717126, -20.79614551])

get_volume( ): Convert the survey area in square degrees and respective redshift of each data point into comoving volumes. So, estimate Vmax from Zmax values

Return comoving volume from the survey area and redshifts.

survey_area = 100.0 #sq. degrees
V_list = lf.get_volume(survey_area, z_photo_list)
print(V_list[:4])
# returns 
# [43208407.50293904 9274338.02683353 54988309.45363603 546254.32632565]

# rudimentarily:
lf.get_volume(100.0, np.array([0.42, 0.24, 0.46, 0.09]))
# returns
# array([43208407.50293904, 9274338.02683353, 54988309.45363603, 546254.32632565])

get_binned_phi( ): Bin and weigh galaxy counts per magnitude by :"1/Vmax"

Return M, M errors and phi from the rest-frame magnitudes, Vmax values and number of bins.

n_bins = 10
M_list, M_err_list, phi_list = lf.get_binned_phi(r_rest_mag_list, V_list, n_bins)
print(M_list)
# returns
# [-27.75116273 -26.26581137 -24.78046    -23.29510864 -21.80975727
#  -20.32440591 -18.83905454 -17.35370318 -15.86835182 -14.38300045]
print(M_err_list)
# returns
# [0.74267568 0.74267568 0.74267568 0.74267568 0.74267568 
#  0.74267568 0.74267568 0.74267568 0.74267568 0.74267568]
print(phi_list)
# returns 
# [5.12016808e-10 0.00000000e+00 6.87358202e-08 3.55674570e-06 1.18791217e-05 
#  2.44735150e-05 5.43431411e-05 1.30067824e-04 1.04554476e-04 1.74886746e-03]

# OR a rudimentarily example:
lf.get_binned_phi(
    np.array([-23, -21, -19, -22, -23, -23, -22, -23, -22, -22, -19, -21]),
    np.array([
        8e+08, 2e+08, 2e+07, 3e+08, 6e+08, 6e+08, 4e+08, 7e+08, 5e+08, 6e+08,
        7e+06, 1e+08
    ]), 4)
# returns 
# (array([-22.5, -21.5, -20.5, -19.5]),
#  array([0.5, 0.5, 0.5, 0.5]),
#  array([1.06411667e-08, 1.02900000e-08, 0.00000000e+00, 1.32300000e-07]))

get_patch_centers( ): To get spatial variances of the phi phi values, first divide uniformly and randomly simulated data points over the survey area into equally distributed and equally sized patches

Return patch centers as (RA, Dec) from the RA, Dec and number of patches.

n_patches = 10
centers_array = lf.get_patch_centers(RA_list,
                                     Dec_list,
                                     n_patches,
                                     survey='kids',
                                     max_iterations=int(100),
                                     tolerance=1.0e-1)
print(centers_array)
# returns
# [[ 1.38832190e+02 -1.00733144e+00]
#  [ 2.17105380e+02  1.08365630e+00]
#  [ 1.80666296e+02 -2.73070692e-01]
#  [ 1.34335764e+02  1.31532218e-01]
#  [ 1.38831715e+02  2.15292944e+00]
#  [ 1.29005160e+02  1.01211250e+00]
#  [ 2.13883209e+02 -1.52070351e-02]
#  [ 1.32326750e+02  2.01815821e+00]
#  [ 2.21141020e+02  4.73369162e-01]
#  [ 1.38831187e+02  5.23810834e-01]]

get_patch_labels( ): Then use the patch centers to label the survey data points by equally distributed and equally sized patches:

Return patch labels for each data point from RA, Dec, number of patches and patch center guesses.

labels = lf.get_patch_labels(RA_list,
                             Dec_list,
                             n_patches,
                             centers_array,
                             survey='kids',
                             numba_installed=True,
                             plot_savename='test_patches.png')
# displays plot

get_patches

get_binned_phi_error( ): Using the patch labels, lastly compute the spatial variances of phi

Return error on phi from rest-frame magnitude, maximum observed volume, labels, number of patches and number of bins.

phi_err_list = lf.get_binned_phi_error(r_rest_mag_list, V_list, labels, 10, 10)
print(phi_err_list)
# returns
# [3.03839559e-06 7.40731159e-06 9.37491641e-06 1.52090965e-05
#  3.56343615e-05 5.44297508e-05 4.18036097e-05 1.39310857e-04
#  2.08627224e-04 3.58080092e-03]

get_plot( ): Instead, perform get_binned_phi() , get_patches_centers() , get_patches() and get_binned_phi_error() functions using only one function and visualise the luminsoity function

Plot the 1/Vmax weighted luminosity function, binned by magnitude.

M_list, M_err_list, phi_list, phi_err_list = lf.get_plot(
    r_rest_mag_list,
    V_list,
    10,
    RA_list,
    Dec_list,
    10,
    centers_array,
    survey='kids',
    numba_installed=True,
    plot_savename='test_LF.png')

# displays plot

plot_LF

filter_plot_by_colour( )

Plots the 1/Vmax weighted luminosity function from data, binned by magnitude and filtered by galaxy colours. The galaxy colours are filtered by red and blue with the help of the input colour dichotomy line parameters. The colour dichotomy line parameters can be inferred from a CMD plot.

SchechterMagModel( )

Single Schechter luminosity function in terms of magnitude from 3 free parameters of the model.

DoubleSchechterMagModel( )

Double Schechter luminosity function in terms of magnitude from 5 free parameters of the model.

get_gof( )

Returns reduced chi squared estimate of goodness of fit.

get_schechter_phi( )

Least square fits single Schechter function model on data. Returns best fit phi, reduced chi squared estimate and the 3 Schechter parameters with their errors.

get_double_schechter_phi( )

Least square fits double Schechter function model on data. Returns best fit phi, reduced chi squared estimate and the 5 Schechter parameters with their errors.

Dependencies

PyPI PyPI PyPI PyPI

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lumfunc-0.2.6.tar.gz (2.4 MB view details)

Uploaded Source

Built Distribution

lumfunc-0.2.6-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file lumfunc-0.2.6.tar.gz.

File metadata

  • Download URL: lumfunc-0.2.6.tar.gz
  • Upload date:
  • Size: 2.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for lumfunc-0.2.6.tar.gz
Algorithm Hash digest
SHA256 c1161a488884d3b5050902a1b4529293759b5cce9158275fb8a5f72cbf2f258c
MD5 4207bcaa1aaf4e3b69a6bf1dcdad350d
BLAKE2b-256 87f024ad83abdb936b0f216e1c78f30b854f567d0b011c9efa27938a469c0b5b

See more details on using hashes here.

File details

Details for the file lumfunc-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: lumfunc-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for lumfunc-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c84e5c278b0884e3644a84e3af04f026831249f364dd60d0abccdd5892a298c1
MD5 44d6274eea72748fbdec88da48ec37c2
BLAKE2b-256 c74f7d7b24771276cff7d5eeed58affed2eeea9c03b6d60d040d01570e593f9f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page