Skip to content

Commit

Permalink
Merge pull request #109 from sdss/synth
Browse files Browse the repository at this point in the history
Script to create synthetic MaNGA datacubes
  • Loading branch information
kbwestfall authored Jul 11, 2023
2 parents d3e9d83 + 4f42e77 commit 81f18ab
Show file tree
Hide file tree
Showing 42 changed files with 1,678 additions and 670 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python: [3.8, 3.9]
python: ['3.9', '3.10', '3.11']
toxenv: [test-cov, test-astropydev]
steps:
- name: Check out repository
Expand All @@ -36,11 +36,11 @@ jobs:
tox -e ${{ matrix.toxenv }}
- name: Upload coverage to codecov
if: "contains(matrix.toxenv, '-cov')"
uses: codecov/codecov-action@v1
# with:
# token: ${{ secrets.CODECOV }}
# file: ./coverage.xml
# fail_ci_if_error: false
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV }}
file: ./coverage.xml
fail_ci_if_error: true

os-tests:
name: Python ${{ matrix.python }} on ${{ matrix.os }}
Expand All @@ -51,13 +51,13 @@ jobs:
matrix:
# os: [windows-latest, macos-latest]
os: [macos-latest]
python: [3.8, 3.9]
python: ['3.9', '3.10', '3.11']
toxenv: [test]
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install base dependencies
Expand All @@ -70,11 +70,11 @@ jobs:
codestyle:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Python codestyle check
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: '3.11'
- name: Install base dependencies
run: |
python -m pip install --upgrade pip
Expand Down
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@

4.1.0dev
--------

- Adds script for creating synthetic MaNGA datacubes for testing.
- Change syntax for emission-line modeling files to enable additional tying
strategies that make it easier to implement multi-component fitting.

4.0.4 (23 Jun 2022)
-------------------

Expand Down
6 changes: 3 additions & 3 deletions docs/corrections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ The corrected gas velocity dispersion is:
\sigma_{\rm gas}^2 = \sigma_{\rm gas,obs}^2 - \sigma_{\rm inst}^2
where :math:`\sigma_{\rm gas}` and :math:`\sigma_{\rm inst}` are
where :math:`\sigma_{\rm gas,obs}` and :math:`\sigma_{\rm inst}` are
provided in, respectively, the ``EMLINE_GSIGMA`` and
``EMLINE_INSTSIGMA`` extensions of the :ref:`datamodel-maps`.

The corrected stellar velocity dispersion is:

.. math::
\sigma_\ast^2 = \sigma_{\rm obs}^2 - \delta\sigma_{\rm inst}^2
\sigma_\ast^2 = \sigma_{\ast,{\rm obs}}^2 - \delta\sigma_{\rm inst}^2
where :math:`\sigma_{\rm obs}` and :math:`\delta\sigma_{\rm inst}` are
where :math:`\sigma_{\ast,{\rm obs}}` and :math:`\delta\sigma_{\rm inst}` are
provided in, respectively, the ``STELLAR_SIGMA`` and
``STELLAR_SIGMACORR`` extensions of the :ref:`datamodel-maps`.

Expand Down
102 changes: 74 additions & 28 deletions docs/emissionlines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -374,23 +374,31 @@ The columns of the parameter file are:
| ``action`` | str | A single character setting how the line should be treated. See |
| | | :ref:`emission-line-modeling-action`. |
+-------------------+-----------+-----------------------------------------------------------------------+
| ``tie`` | str[4] | A sequence of 4 strings that indicate how the line should be tied to |
| | | other lines. The first element specifies the line to which to tie |
| | | the line specified in this row, indicated by its line ``index``. The |
| | | next three entries indicate how to tie each of the 3 Gaussian |
| | | parameters: flux, velocity, and velocity dispersion. To leave the |
| | | parameter untied, this should be ``None``. To force the parameter to |
| | | be identical to the parameter for the tied line, use ``=``. For the |
| | | flux, the flux can be specified to be a specific factor of the tied |
| | | line; e.g., ``=0.30`` forces the flux of this line to be 0.3 times |
| | | the flux of the tied line. For the velocity and velocity dispersion, |
| | | a single value can be used to set a the tied parameter to be within |
| | | the specified fraction of the tied parameter. I.e., a value of |
| | | ``1.4`` for the velocity dispersion parameter means the velocity |
| | | dispersion of this line should be within |
| | | :math:`\sigma_t/1.4 < \sigma < 1.4 \sigma_t`, where :math:`\sigma_t` |
| | | is the velocity dispersion of the tied line. When imposing these |
| | | parameter inequalities, `ppxf`_ will require the `cvxopt`_ package. |
| ``tie_f`` | str[2] | A sequence of 2 10-character strings that indicate how the flux of |
| | | the line should be tied to another line. The first element gives the |
| | | index of the line to tie (see ``index`` above). The second element |
| | | provides the constraint. Currently fluxes can only be tied by |
| | | fixing the line flux ratio, and lines with tied fluxes must also have |
| | | their velocity and velocity dispersions tied by equality. For |
| | | example, to fix the ratio of the OIII 4959 line to the OIII 5007 |
| | | line, the entry for the OIII 4959 line should be ``{ 14 =0.34 }``, |
| | | where 14 is the index number of the OIII 5007 in the file and the |
| | | flux in the OIII 4959 line is always 0.34 times the flux in the |
| | | OIII 5007 line. |
+-------------------+-----------+-----------------------------------------------------------------------+
| ``tie_v`` | str[2] | A sequence of 2 10-character strings that indicate how the velocity |
| | | of the line should be tied to another line. The first element gives |
| | | the index of the line to tie (see ``index`` above). The second |
| | | element provides the constraint. Velocities can be tied by equality |
| | | (using ``=``) or tied by inequality (see below); however, tying by |
| | | inequality is not well tested. |
+-------------------+-----------+-----------------------------------------------------------------------+
| ``tie_s`` | str[2] | A sequence of 2 10-character strings that indicate how the velocity |
| | | dispersion of the line should be tied to another line. The first |
| | | element gives the index of the line to tie (see ``index`` above). |
| | | The second element provides the constraint. Velocity dispersions can |
| | | can be tied by equality (using ``=``) or tied by inequality (see |
| | | below). |
+-------------------+-----------+-----------------------------------------------------------------------+
| ``blueside`` | float[2] | A two-element vector with the starting and ending wavelength for a |
| | | passband to the blue of the primary band. |
Expand All @@ -409,17 +417,19 @@ and an example file might look like this:
double restwave;
char waveref[3];
char action;
char tie[4][10];
char tie_f[2][10];
char tie_v[2][10];
char tie_s[2][10];
double blueside[2];
double redside[2];
} DAPEML;
DAPEML 2 OII 3727.092 vac f { 34 None = None } { 3706.3 3716.3 } { 3738.6 3748.6 }
DAPEML 3 OII 3729.875 vac f { 2 None = = } { 3706.3 3716.3 } { 3738.6 3748.6 }
DAPEML 23 Hb 4862.6830 vac f { 34 None = 1.4 } { 4798.9 4838.9 } { 4885.6 4925.6 }
DAPEML 33 NII 6549.86 vac f { 35 =0.34 = = } { 6483.0 6513.0 } { 6623.0 6653.0 }
DAPEML 34 Ha 6564.608 vac f { None None None None } { 6483.0 6513.0 } { 6623.0 6653.0 }
DAPEML 35 NII 6585.27 vac f { 34 None = None } { 6483.0 6513.0 } { 6623.0 6653.0 }
DAPEML 2 OII 3727.092 vac f { None None } { 34 = } { None None } { 3706.3 3716.3 } { 3738.6 3748.6 }
DAPEML 3 OII 3729.875 vac f { None None } { 2 = } { 2 = } { 3706.3 3716.3 } { 3738.6 3748.6 }
DAPEML 23 Hb 4862.6830 vac f { None None } { 34 = } { 34 1.4 } { 4798.9 4838.9 } { 4885.6 4925.6 }
DAPEML 33 NII 6549.86 vac f { 35 =0.34 } { 35 = } { 35 = } { 6483.0 6513.0 } { 6623.0 6653.0 }
DAPEML 34 Ha 6564.608 vac f { None None } { None None } { None None } { 6483.0 6513.0 } { 6623.0 6653.0 }
DAPEML 35 NII 6585.27 vac f { None None } { 34 = } { None None } { 6483.0 6513.0 } { 6623.0 6653.0 }
.. note::

Expand All @@ -429,9 +439,12 @@ and an example file might look like this:
up to the person that writes the two parameter files to make sure
that is true.

* The format of this file has changed in version 3.1.0 in a way that removes
many of the parameters used by the :class:`~mangadap.proc.elric.Elric`
fitter. That class is now deprecated.
* Format changes:
- version 3.1.0: Many parameters removed that were used by the
deprecated :class:`~mangadap.proc.elric.Elric` fitter.
- version 4.1.0: Added ability to tie the three parameters to different
lines; i.e., velocity can be tied to one line while dispersion is tied
to a different one.

.. _emission-line-modeling-action:

Expand All @@ -442,6 +455,40 @@ Emission-Line "Actions"

.. _emission-line-modeling-mode:

Emission-Line Tying
+++++++++++++++++++

Line tying in the DAP uses the functionality in `ppxf`_ in a limited and
abstracted way.

**Tying fluxes** effectively means that the lines are put in the same
emission-line template. This is why, currently, any lines with tied fluxes must
also tie their velocity and velocity dispersion. Also, the DAP currently does
not allow tying fluxes using inequalities.

**Tying kinematics** can be done with equality or inequality. For equality, use
the ``=`` character, as in the example file above. Unlike the fluxes, the
kinematics cannot be tied to be, e.g., a specific fraction of the value of the
tied line. (I.e., you can't tie the dispersion to be exactly half of the
dispersion of the tied line). For inequality, there are a couple of options:

#. Use ``>N`` or ``<N`` to force the value to be greater or less than the
provided fraction of the the value of the tied line. E.g., to force the
dispersion of one component to be at least 1.5 times larger than the tied
line, use ``>1.5``. Using ``>`` or ``<`` is equivalent to ``>1`` and
``<``, respectively.

#. To bound the value between both upper and lower limits, you must use a
*single* fixed fractional bound. For example, setting the tied value for
the dispersion to ``1.4`` means that the best-fitting dispersion must be
greater than 1/1.4 and less than 1.4 times the dispersion of the tied
line.

.. warning::

Although line tying has been experimented with for MaNGA data, much of the
inequality tying is not well tested.

Emission-Line "Modes"
+++++++++++++++++++++

Expand All @@ -454,7 +501,6 @@ Emission-Line "Modes"
Changing the modeling parameters
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


The moment measurements are performed by
:class:`~mangadap.proc.emissionlinemoments.EmissionLineMoments`; see
:ref:`emission-line-moments`. A set of parameter files that define a list of
Expand Down
2 changes: 1 addition & 1 deletion docs/tables/emissionlinepar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Key Type Options Default Description
``name`` str .. .. A name for the line.
``restwave`` int, float .. .. The rest wavelength of the line in angstroms *in vacuum*.
``action`` str ``i``, ``f``, ``m``, ``s`` ``f`` Describes how the line should be treated. See :ref:`emission-line-modeling-action`. Default is ``f``.
``tie_index`` int .. .. Index of the line to which parameters for this line are tied. See :ref:`emission-line-modeling-tying`.
``tie_index`` ndarray, list .. .. Indices the lines to which parameters for this line are tied; one index per (3) Gaussian parameters. See :ref:`emission-line-modeling-tying`.
``tie_par`` ndarray, list .. .. Details of how each model parameter for this line is tied to the reference line. See :ref:`emission-line-modeling-tying`.
``blueside`` ndarray, list .. .. A two-element vector with the starting and ending wavelength for a bandpass blueward of the emission line, which is used to set the continuum level near the emission line when calculating the equivalent width.
``redside`` ndarray, list .. .. A two-element vector with the starting and ending wavelength for a bandpass redward of the emission line, which is used to set the continuum level near the emission line when calculating the equivalent width.
Expand Down
2 changes: 0 additions & 2 deletions examples/fit_one_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,6 @@ def main():
f'{corrected_indices_err[0,i]:12.4f}')
print('-'*73)

embed()

print('Elapsed time: {0} seconds'.format(time.perf_counter() - t))


Expand Down
9 changes: 8 additions & 1 deletion mangadap/contrib/xjmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,11 +880,18 @@ def _fit_iteration(tpl_wave, templates, wave, flux, noise, velscale, start, mome
# emission lines
reject_pixels = list(set(pp.goodpixels)
& set(np.arange(len(resid))[pp.gas_bestfit < 1e-6]))
if len(reject_pixels) == 0:
warnings.warn('Unable to find *good* pixels in the spectrum to use for rejection.'

Check warning on line 884 in mangadap/contrib/xjmc.py

View check run for this annotation

Codecov / codecov/patch

mangadap/contrib/xjmc.py#L884

Added line #L884 was not covered by tests
' This is likely because a hardcoded threshold could not find '
'pixels that were fit but not part of a fitted emission line. '
'Please submit a GitHub Issue. Logging fault and continuing.')
fault[i] = True
continue

Check warning on line 889 in mangadap/contrib/xjmc.py

View check run for this annotation

Codecov / codecov/patch

mangadap/contrib/xjmc.py#L888-L889

Added lines #L888 - L889 were not covered by tests
# - Calculate the 1-sigma confidence interval
rms = calculate_noise(resid[reject_pixels], width=reject_boxcar)
# - Reject pixels with > 3-sigma residuals
model_mask[i,reject_pixels+ps[i]] &= (np.absolute(resid[reject_pixels]) < sigma_rej*rms)

# Reorder the output; sets any omitted components to have
# the starting values from the original input
sol, err = _reorder_solution(pp.sol, pp.error, component_map, moments, start=start[i])
Expand Down
Loading

0 comments on commit 81f18ab

Please sign in to comment.