Skip to content

Commit

Permalink
Merge pull request #47 from p-slash/0.5.0-dev
Browse files Browse the repository at this point in the history
0.5.0 merge:
+ Error method for varlss is configurable. default is regJack.
+ Adjustable smoothing scale for noise.
+ Variance fitting auto calculates needed wavelength bins based on 120 A average spacing.
+ Mean Gaussian sigma is calculated and added to delta headers
+ Auto calculate quasar redshifts using wavelength ranges
  • Loading branch information
p-slash authored Mar 28, 2023
2 parents 9f54561 + 4cdc2a0 commit 82933eb
Show file tree
Hide file tree
Showing 25 changed files with 375 additions and 124 deletions.
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
'sphinx.ext.intersphinx',
'sphinx.ext.viewcode',
'sphinx.ext.napoleon',
'sphinxarg.ext'
'sphinxarg.ext',
"sphinxcontrib.jquery" # based on https://github.com/readthedocs/readthedocs.org/issues/10159#issuecomment-1478717074
# 'nbsphinx',
# 'autoapi.extension'
]
Expand All @@ -56,7 +57,7 @@
'numpy': ('https://numpy.org/doc/stable', None),
'scipy': ('https://docs.scipy.org/doc/scipy/', None)
}
intersphinx_disabled_domains = ['std']
# intersphinx_disabled_domains = ['std']
# intersphinx_disabled_reftypes = ["*"]

templates_path = ['_templates']
Expand All @@ -65,7 +66,6 @@

html_theme = 'sphinx_rtd_theme'
html_logo = "_static/qsonic-logo.png"
html_show_sourcelink = False

# -- Options for EPUB output
epub_show_urls = 'footnote'
Expand Down
2 changes: 1 addition & 1 deletion docs/source/example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Examples
Running qsonic-fit
-------------------------

See :ref:`qsonic-fit arguments <qsonic_fit_arguments_label>` for all options.
See :ref:`qsonic-fit arguments <qsonic fit arguments>` for all options.

.. code-block:: shell
:caption: For an imaginary Y5 DESI quickquasars mock
Expand Down
2 changes: 1 addition & 1 deletion docs/source/generated/catalog.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
qsonic.catalog module
qsonic.catalog
=======================

.. automodule:: qsonic.catalog
Expand Down
2 changes: 1 addition & 1 deletion docs/source/generated/io.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
qsonic.io module
qsonic.io
==================

.. automodule:: qsonic.io
Expand Down
2 changes: 1 addition & 1 deletion docs/source/generated/masks.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
qsonic.masks module
qsonic.masks
=====================

.. automodule:: qsonic.masks
Expand Down
2 changes: 1 addition & 1 deletion docs/source/generated/mathtools.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
qsonic.mathtools module
qsonic.mathtools
=========================

.. automodule:: qsonic.mathtools
Expand Down
1 change: 1 addition & 0 deletions docs/source/generated/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ Scripts
:maxdepth: 4

scripts.qsonic_fit
scripts.qsonic_calib
3 changes: 2 additions & 1 deletion docs/source/generated/mpi_utils.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
qsonic.mpi\_utils module
qsonic.mpi\_utils
==========================

.. automodule:: qsonic.mpi_utils
:members:
:undoc-members:
:show-inheritance:
:exclude-members: _INVALID_VALUE
2 changes: 1 addition & 1 deletion docs/source/generated/picca_continuum.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
qsonic.picca\_continuum module
qsonic.picca\_continuum
================================

.. automodule:: qsonic.picca_continuum
Expand Down
21 changes: 21 additions & 0 deletions docs/source/generated/scripts.qsonic_calib.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
qsonic.scripts.qsonic_calib
=========================================


.. automodule:: qsonic.scripts.qsonic_calib
:members:
:undoc-members:
:show-inheritance:
:exclude-members: get_parser

.. _qsonic calib arguments:

Arguments
---------

.. autofunction:: qsonic.scripts.qsonic_calib.get_parser

.. argparse::
:ref: qsonic.scripts.qsonic_calib.get_parser
:prog: qsonic-calib

4 changes: 2 additions & 2 deletions docs/source/generated/scripts.qsonic_fit.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
qsonic.scripts.qsonic_fit script module
qsonic.scripts.qsonic_fit
=======================================


Expand All @@ -8,7 +8,7 @@ qsonic.scripts.qsonic_fit script module
:show-inheritance:
:exclude-members: get_parser

.. _qsonic_fit_arguments_label:
.. _qsonic fit arguments:

Arguments
---------
Expand Down
2 changes: 1 addition & 1 deletion docs/source/generated/spectrum.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
qsonic.spectrum module
qsonic.spectrum
========================

.. automodule:: qsonic.spectrum
Expand Down
3 changes: 2 additions & 1 deletion docs/source/readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

Programs
--------
+ ``qsonic-fit`` performs picca-like continuum fitting. See :ref:`here <qsonic_fit_arguments_label>` or execute ``srun -n 1 qsonic-fit.py --help`` for help.
+ ``qsonic-fit`` performs picca-like continuum fitting. See :ref:`here <qsonic fit arguments>` or execute ``srun -n 1 qsonic-fit --help`` for help.
+ ``qsonic-calib`` calculates stacked flux and performs variance fitting with noise calibration (eta) enabled. See :ref:`here <qsonic calib arguments>` ``srun -n 1 qsonic-calib --help`` for help.

Source
------
Expand Down
2 changes: 1 addition & 1 deletion py/qsonic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__author__ = 'Naim Goksel Karacayli'
__email__ = '[email protected]'
__version__ = '0.4.4'
__version__ = '0.5.0'


class QsonicException(Exception):
Expand Down
45 changes: 21 additions & 24 deletions py/qsonic/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import numpy as np
from numpy.lib.recfunctions import rename_fields, append_fields

from qsonic import QsonicException
from qsonic.mpi_utils import logging_mpi, balance_load
from qsonic.mpi_utils import logging_mpi, balance_load, mpi_fnc_bcast

_accepted_extnames = set(['QSO_CAT', 'ZCATALOG', 'METADATA'])
"""set: Accepted extentions for quasar catalog."""
Expand Down Expand Up @@ -53,9 +52,9 @@ def read_quasar_catalog(
If the catalog is for mocks.
keep_surveys: None or list(str), default: None
List of surveys to subselect. None keeps all.
zmin: float, default: 2.1
zmin: float, default: 0
Minimum quasar redshift
zmax: float, default: 6.0
zmax: float, default: 100
Maximum quasar redshift
Returns
Expand All @@ -72,49 +71,47 @@ def read_quasar_catalog(


def mpi_read_quasar_catalog(
filename, comm, mpi_rank, is_mock,
keep_surveys=None, zmin=2.1, zmax=6.0
filename, comm=None, mpi_rank=0, is_mock=False,
keep_surveys=None, zmin=0, zmax=100
):
""" Returns the same quasar catalog object on all MPI ranks.
It is sorted in the following order: HPXPIXEL, SURVEY (if applicable),
TARGETID. BAL info included if available. It is required for BAL masking.
Can be used without MPI by passing ``comm=None`` and ``mpi_rank=0``.
Arguments
----------
filename: str
Filename to catalog.
comm: MPI comm object
comm: MPI comm object or None, default: None
MPI comm object for bcast
mpi_rank: int
mpi_rank: int, default: 0
Rank of the MPI process
is_mock: bool
is_mock: bool, default: False
If the catalog is for mocks.
keep_surveys: None or list(str), default: None
List of surveys to subselect. None keeps all.
zmin: float, default: 2.1
zmin: float, default: 0
Minimum quasar redshift
zmax: float, default: 6.0
zmax: float, default: 100
Maximum quasar redshift
Returns
----------
catalog: :external+numpy:py:class:`ndarray <numpy.ndarray>`
Sorted catalog on all MPI ranks.
Raises
------
QsonicException
If error occurs while reading the catalog.
"""
catalog = None

if mpi_rank == 0:
try:
catalog = read_quasar_catalog(
filename, is_mock, keep_surveys, zmin, zmax)
except Exception as e:
logging_mpi(e, 0, "error")
catalog = None

catalog = comm.bcast(catalog, root=0)
if catalog is None:
raise QsonicException("Error while reading catalog.")
catalog = mpi_fnc_bcast(
read_quasar_catalog,
comm, mpi_rank, "Error while reading catalog.",
filename, is_mock, keep_surveys, zmin, zmax)

return catalog

Expand Down
2 changes: 1 addition & 1 deletion py/qsonic/masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, fname):

self.mask_rest_frame = mask[mask['frame'] == 'RF']
self.mask_obs_frame = mask[mask['frame'] == 'OBS']
except QsonicException as e:
except Exception as e:
raise QsonicException(
f"Error loading SkyMask from mask file {fname}.") from e

Expand Down
17 changes: 7 additions & 10 deletions py/qsonic/mathtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,16 @@ def mypoly1d(coef, x):
return results


def fft_gaussian_smooth(x, sigma_pix=20, pad_size=25, mode='edge'):
def fft_gaussian_smooth(x, sigma_pix=20, mode='edge'):
""" My Gaussian smoother using FFTs. Input array is padded with edge
values at the boundary by default.
values at the boundary by default. Pad size is ``3*sigma_pix``.
Arguments
---------
x: :external+numpy:py:class:`ndarray <numpy.ndarray>`
1D array to smooth.
sigma_pix: float, default: 20
Smoothing Gaussian sigma
pad_size: int, default: 25
Number of pixels to pad the array x at the boundary.
Smoothing Gaussian sigma in terms of number of pixels.
mode: str
Padding method. See :external+numpy:func:`numpy.pad` for options.
Expand All @@ -60,6 +58,7 @@ def fft_gaussian_smooth(x, sigma_pix=20, pad_size=25, mode='edge'):
"""
# Pad the input array to get rid of annoying edge effects
# Pad values are set to the edge value
pad_size = max(1, int(3 * sigma_pix))
arrsize = x.size + 2 * pad_size
padded_arr = np.pad(x, pad_size, mode=mode)

Expand All @@ -71,7 +70,7 @@ def fft_gaussian_smooth(x, sigma_pix=20, pad_size=25, mode='edge'):
return y


def get_smooth_ivar(ivar, sigma_pix=20, pad_size=25, esigma=3.5):
def get_smooth_ivar(ivar, sigma_pix=20, esigma=3.5):
""" Smoothing ``ivar`` values to reduce signal-noise coupling.
Smoothing is done on ``error=1/sqrt(ivar)``, while replacing ``ivar=0`` and
Expand All @@ -83,9 +82,7 @@ def get_smooth_ivar(ivar, sigma_pix=20, pad_size=25, esigma=3.5):
ivar: :external+numpy:py:class:`ndarray <numpy.ndarray>`
Inverse variance array.
sigma_pix: float, default: 20
Smoothing Gaussian sigma.
pad_size: int, default: 25
Number of pixels to pad the array at the boundary.
Smoothing Gaussian sigma in terms of number of pixels.
esigma: float, default: 3.5
Sigma to identify outliers via MAD.
Expand All @@ -107,7 +104,7 @@ def get_smooth_ivar(ivar, sigma_pix=20, pad_size=25, esigma=3.5):

# Replace them with the median
error[w2] = median_err
error = fft_gaussian_smooth(error, sigma_pix, pad_size)
error = fft_gaussian_smooth(error, sigma_pix)

# Restore values of bad pixels
error[w2] = err_org
Expand Down
Loading

0 comments on commit 82933eb

Please sign in to comment.