Coder Social home page Coder Social logo

multiwavelength / gleam Goto Github PK

View Code? Open in Web Editor NEW
24.0 24.0 6.0 8.45 MB

Galaxy Line Emission & Absorption Modeling

Home Page: https://github.com/multiwavelength/gleam

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%
1d-spectra absorption-lines agn astronomy astronomy-library astronomy-software emission-lines extragalactic galaxies spectral-lines spectroscopy

gleam's People

Contributors

multiwavelength avatar victor-savu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gleam's Issues

Rename metadata file

Change the way that metadata files are searched on disk, ie using the name 'meta.' instead of master.

Number of zoom in plots does not match number of connected line components

The zoom-in plots are sometimes too narrow and lots of space is left on the right side. This is because the number of zoom-in plots is calculated as a function of the number of connected line components. However, some of these spectral lines might not be covered by the spectrum (i.e. too low or too high wavelength), so a fit is never attempted for them. The number of plots should thus take into account only the components that are covered by the spectrum.

Explicitly define groups in the configuration file

While the tolerance parameter offers a very succinct way to uniquely define the groups of lines to be fitted jointly, it requires some validation on the part of the user to make sure there are no surprising groupings.

Here are two things we could consider to avoid any confusion:

  1. A sub-command (gleam list groups) to list the groups (for each override scenario) so the user can easily inspect them.
  2. Explicitly define the groups in the config file, using line names:
    groups:
      - 
        - Halpha
        - NII1
        - NII2
      -
        - SII1
        - SII2
    All other lines would be fit individually.

Add broad line support

At the moment, gleam works really well for narrow emission lines (such as those associated with narrow-line regions in AGN and star-forming regions). This is because the starting solution for the Gaussian fits is set to the resolution of the instruments. This starting solution also works for broad lines (>500 km/s), as long as the line is well separated from other lines and the fit is simple. However, the fits do not converge to the correct solution when one has both broad and narrow components of the same emission line. To fix this, we should give users the option to label lines in the spectral lines list as broad and provide a different starting solution for the Gaussian fits, in line with expectations for broad lines (i.e. a FWHM starting solution equivalent to 500-1000 km/s)

example meta file

In the example (A773), the meta file does not start with "meta." so that user will get the following message:

Error! Cannot find any metadata files.

Renameing the file to "meta.A773.WHT_R316R.Q1_EXT1.dat" solves the issue.

Add option to specify output folder

At the moment, gleam outputs the fit results and plots next to the corresponding input spectra.

It would be great to have the options to output the results to a different folder. This can help:

  • speed up the execution when the input data is hosted on a slower drive (like a network drive).
  • back up the results without having to pick them out from among the data.
  • produce comparable & archivable snapshots of different runs with different input configurations. Maybe the input configuration could be copied or somehow linked to the output folder in order to help with keeping track of the results.

Flux density scaling when restframing

GLEAM did not scale the flux density (lambda) when restframing the spectrum. This resulted in fluxes, luminosities and Gaussian amplitudes that were a factor of (1+z) too small. Equivalent widths are not affected. The effect is small at small redshifts, but very important for high redshifts.

Negative EW error for absorption line

Mariusz Tarnopolski noticed the following issue in GLEAM:

"When an absorption line is fitted, the corresponding amplitude is negative, which results in a negative EW_rest (which can be positive or negative depending on convention), but then - as per line 80 of gaussian_fitting.py - this negative value it carried on to the error, which should always be positive. So I just changed v to abs(v) in that line of the code."

This should be an easy fix as Mariusz suggests.

Error when processing multi files

Error when processing multi files, but process single file works

(py38_gleam) zijianzhang@fushuqis-iMac formated_Data % gleam --path gleam_Data --spectra .//spec1d.MMT.Hectlow.a.24.fits --config gleamconfig.yaml --plot
WARNING: AstropyDeprecationWarning: The truth value of a Quantity is ambiguous. In the future this will raise a ValueError. [astropy.units.quantity]
Usage: gleam [OPTIONS]
Try 'gleam --help' for help.

Error: Got unexpected extra argument (./gleam_Data/spec1d.MMT.Hectlow.a.243.fits)
(py38_gleam) zijianzhang@fushuqis-iMac formated_Data % gleam --path gleam_Data --spectra ./**/spec1d.MMT.Hectlow.a.243.fits --config gleamconfig.yaml --plot
WARNING: AstropyDeprecationWarning: The truth value of a Quantity is ambiguous. In the future this will raise a ValueError. [astropy.units.quantity]
WARNING: AstropyDeprecationWarning: The truth value of a Quantity is ambiguous. In the future this will raise a ValueError. [astropy.units.quantity]
WARNING: AstropyDeprecationWarning: The truth value of a Quantity is ambiguous. In the future this will raise a ValueError. [astropy.units.quantity]
WARNING: AstropyDeprecationWarning: The truth value of a Quantity is ambiguous. In the future this will raise a ValueError. [astropy.units.quantity]
WARNING: AstropyDeprecationWarning: The truth value of a Quantity is ambiguous. In the future this will raise a ValueError. [astropy.units.quantity]
WARNING: AstropyDeprecationWarning: The truth value of a Quantity is ambiguous. In the future this will raise a ValueError. [astropy.units.quantity]
WARNING: AstropyDeprecationWarning: The truth value of a Quantity is ambiguous. In the future this will raise a ValueError. [astropy.units.quantity]
WARNING: AstropyDeprecationWarning: The truth value of a Quantity is ambiguous. In the future this will raise a ValueError. [astropy.units.quantity]
WARNING: AstropyDeprecationWarning: The truth value of a Quantity is ambiguous. In the future this will raise a ValueError. [astropy.units.quantity]
Now working in ./gleam_Data on MMT in Hectlow + a on source 243 at z=0.322.

Unexpected behavior in empty cells in output fits file

With different installations of GLEAM, I am getting different behaviors on the empty cell in the output FITS file that contains the emission and absorption line fits.

If I run GLEAM from a local GLEAM sandbox (clone of git repository), the cell is empty, as intended.
If I run GLEAM from my PyPI installation, the cell is filled with 1.0E20, not as intended.

Both GLEAM installations use Astropy 4.2.

This could be an issue solved by using more recent versions of dependencies. At the moment we cannot upgrade dependencies until we figure out how to deal with #26.

Add flag to output defaults

The defaults for the fitting parameters are hidden in the code. It would be helpful if we had an option to print them for the user to see.

Warnings when importing gleam

I am getting two warnings when importing gleam:

>>> import gleam
WARNING: AstropyDeprecationWarning: The truth value of a Quantity is ambiguous. In the future this will raise a ValueError. [astropy.units.quantity]
/home/victor/Code/GitHub/gleamenv/lib/python3.8/site-packages/gleam/matplotlibparams.py:12: MatplotlibDeprecationWarning: Support for setting the 'text.latex.preamble' or 'pgf.preamble' rcParam to a list of strings is deprecated since 3.3 and will be removed two minor releases later; set it to a single string instead.
  plt.rcParams["text.latex.preamble"] = [

Issue with matplotlib locks when using multiprocessing

multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 51, in starmapstar
    return list(itertools.starmap(args[0], args[1]))
  File "/home/andra/.local/lib/python3.8/site-packages/gleam/main.py", line 108, in run_main
    pg.plot_spectrum(
  File "/home/andra/.local/lib/python3.8/site-packages/gleam/plot_gaussian.py", line 240, in plot_spectrum
    fig.savefig(f"{basename}.png", format="png", bbox_inches="tight")
  File "/home/andra/.local/lib/python3.8/site-packages/matplotlib/figure.py", line 2311, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/home/andra/.local/lib/python3.8/site-packages/matplotlib/backend_bases.py", line 2193, in print_figure
    self.figure.draw(renderer)
  File "/home/andra/.local/lib/python3.8/site-packages/matplotlib/artist.py", line 41, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/home/andra/.local/lib/python3.8/site-packages/matplotlib/figure.py", line 1863, in draw
    mimage._draw_list_compositing_images(
  File "/home/andra/.local/lib/python3.8/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
    a.draw(renderer)
  File "/home/andra/.local/lib/python3.8/site-packages/matplotlib/artist.py", line 41, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/home/andra/.local/lib/python3.8/site-packages/matplotlib/cbook/deprecation.py", line 411, in wrapper
    return func(*inner_args, **inner_kwargs)
  File "/home/andra/.local/lib/python3.8/site-packages/matplotlib/axes/_base.py", line 2747, in draw
    mimage._draw_list_compositing_images(renderer, self, artists)
  File "/home/andra/.local/lib/python3.8/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
    a.draw(renderer)
  File "/home/andra/.local/lib/python3.8/site-packages/matplotlib/artist.py", line 41, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/home/andra/.local/lib/python3.8/site-packages/matplotlib/axis.py", line 1165, in draw
    ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
  File "/home/andra/.local/lib/python3.8/site-packages/matplotlib/axis.py", line 1091, in _get_tick_bboxes
    return ([tick.label1.get_window_extent(renderer)
  File "/home/andra/.local/lib/python3.8/site-packages/matplotlib/axis.py", line 1091, in <listcomp>
    return ([tick.label1.get_window_extent(renderer)
  File "/home/andra/.local/lib/python3.8/site-packages/matplotlib/text.py", line 902, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "/home/andra/.local/lib/python3.8/site-packages/matplotlib/text.py", line 295, in _get_layout
    w, h, d = renderer.get_text_width_height_descent(
  File "/home/andra/.local/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py", line 227, in get_text_width_height_descent
    w, h, d = texmanager.get_text_width_height_descent(
  File "/home/andra/.local/lib/python3.8/site-packages/matplotlib/texmanager.py", line 423, in get_text_width_height_descent
    dvifile = self.make_dvi(tex, fontsize)
  File "/home/andra/.local/lib/python3.8/site-packages/matplotlib/texmanager.py", line 309, in make_dvi
    self._run_checked_subprocess(
  File "/usr/lib/python3.8/contextlib.py", line 120, in __exit__
    next(self.gen)
  File "/home/andra/.local/lib/python3.8/site-packages/matplotlib/cbook/__init__.py", line 1814, in _lock_path
    lock_path.unlink()
  File "/usr/lib/python3.8/pathlib.py", line 1321, in unlink
    self._accessor.unlink(self)
FileNotFoundError: [Errno 2] No such file or directory: '/home/andra/.cache/matplotlib/tex.cache/7b049115a0b65bb660d58d081a8c2c63.tex.matplotlib-lock'
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/andra/.local/bin/gleam", line 8, in <module>
    sys.exit(pipeline())
  File "/home/andra/.local/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/andra/.local/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/andra/.local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/andra/.local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/andra/.local/lib/python3.8/site-packages/gleam/__init__.py", line 136, in pipeline
    p.starmap(gleam.main.run_main, unique_sources)
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 372, in starmap
    return self._map_async(func, iterable, starmapstar, chunksize).get()
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 771, in get
    raise self._value
FileNotFoundError: [Errno 2] No such file or directory: '/home/andra/.cache/matplotlib/tex.cache/7b049115a0b65bb660d58d081a8c2c63.tex.matplotlib-lock'
Command exited with non-zero status 1

Warnings regarding truth value of Quantities

When importing/running GLEAM this issue arises:

WARNING: AstropyDeprecationWarning: The truth value of a Quantity is ambiguous. In the future this will raise a ValueError. [astropy.units.quantity]

This was noticed by @Victor-Savu in #9.
Preliminary investigations indicate the issue is caused by how Pydantic dataclasses interact with Astropy Quantities.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.