Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using gleam #21

Closed
rayadastidar opened this issue Jul 6, 2021 · 4 comments
Closed

Error when using gleam #21

rayadastidar opened this issue Jul 6, 2021 · 4 comments

Comments

@rayadastidar
Copy link

rayadastidar commented Jul 6, 2021

How can I enable plotting in gleam?

@multiwavelength
Copy link
Owner

Hi Raya,
I noticed you edited the issue you opened. Have you resolved the problem with the error you were getting with units?

If not, given the error you were getting, I suspect there might be an issue with units not being consistently defined across all input files. Could you make sure that the input spectra, the gleam config file and the line list all have wavelength units defined? I hope this helps and let me know if the issue was resolved!

@rayadastidar
Copy link
Author

rayadastidar commented Jul 7, 2021

Thank you for replying.
Yes, actually that was the problem. I was able to resolve that. But when I am using the --plot functionality (in the example folder itself), I am getting the following error after the code fits the Halpha profile:

gleam --plot --inspect --verbose
WARNING: AstropyDeprecationWarning: The truth value of a Quantity is ambiguous. In the future this will raise a ValueError. [astropy.units.quantity]
/home/raya/anaconda3/envs/py38/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"] = [
Now working in ./A773 on A773 in WHT_R316R + Q1_EXT1 on source 8 at z=0.263.
Warning: non-constant dispersion
[[Model]]
    (Model(constant) + Model(gaussian, prefix='g0_'))
[[Fit Statistics]]
    # fitting method   = leastsq
    # function evals   = 74
    # data points      = 106
    # variables        = 4
    chi-square         = 197.367185
    reduced chi-square = 1.93497240
    Akaike info crit   = 73.8924391
    Bayesian info crit = 84.5461954
[[Variables]]
    c:             6.38627289 +/- 6.67347265 (104.50%) (init = 13.30506)
    g0_amplitude:  1906.81291 +/- 424.721541 (22.27%) (init = 1740.675)
    g0_center:     3728.26217 +/- 1.27562158 (0.03%) (init = 3728.483)
    g0_sigma:      5.71795514 +/- 1.38722213 (24.26%) (init = 2.723824)
    g0_fwhm:       13.4647551 +/- 3.26665842 (24.26%) == '2.3548200*g0_sigma'
    g0_height:     133.038527 +/- 25.9548254 (19.51%) == '0.3989423*g0_amplitude/max(1e-15, g0_sigma)'
[[Correlations]] (unreported correlations are < 0.100)
    C(g0_amplitude, g0_sigma) =  0.651
    C(c, g0_amplitude)        = -0.474
    C(c, g0_sigma)            = -0.287
Warning: non-constant dispersion
[[Model]]
    (Model(constant) + Model(gaussian, prefix='g0_'))
[[Fit Statistics]]
    # fitting method   = leastsq
    # function evals   = 41
    # data points      = 104
    # variables        = 4
    chi-square         = 164.170446
    reduced chi-square = 1.64170446
    Akaike info crit   = 55.4774865
    Bayesian info crit = 66.0550501
[[Variables]]
    c:             84.9542072 +/- 5.47802263 (6.45%) (init = 95.70401)
    g0_amplitude:  1929.75011 +/- 271.778006 (14.08%) (init = 1807.738)
    g0_center:     4862.52025 +/- 0.47465264 (0.01%) (init = 4862.68)
    g0_sigma:      3.09444539 +/- 0.48297542 (15.61%) (init = 2.723824)
    g0_fwhm:       7.28686190 +/- 1.13732019 (15.61%) == '2.3548200*g0_sigma'
    g0_height:     248.787376 +/- 34.8595382 (14.01%) == '0.3989423*g0_amplitude/max(1e-15, g0_sigma)'
[[Correlations]] (unreported correlations are < 0.100)
    C(g0_amplitude, g0_sigma) =  0.559
    C(c, g0_amplitude)        = -0.333
    C(c, g0_sigma)            = -0.207
Warning: non-constant dispersion
[[Model]]
    (Model(constant) + Model(gaussian, prefix='g0_'))
[[Fit Statistics]]
    # fitting method   = leastsq
    # function evals   = 34
    # data points      = 89
    # variables        = 4
    chi-square         = 218.789688
    reduced chi-square = 2.57399633
    Akaike info crit   = 88.0532368
    Bayesian info crit = 98.0077823
[[Variables]]
    c:             76.4141711 +/- 7.26746782 (9.51%) (init = 85.70117)
    g0_amplitude:  771.165916 +/- 347.515597 (45.06%) (init = 1288.239)
    g0_center:     4958.57653 +/- 1.78685688 (0.04%) (init = 4960.295)
    g0_sigma:      3.79788461 +/- 1.87859739 (49.46%) (init = 2.723824)
    g0_fwhm:       8.94333464 +/- 4.42375871 (49.46%) == '2.3548200*g0_sigma'
    g0_height:     81.0058060 +/- 34.7304157 (42.87%) == '0.3989423*g0_amplitude/max(1e-15, g0_sigma)'
[[Correlations]] (unreported correlations are < 0.100)
    C(g0_amplitude, g0_sigma) =  0.592
    C(c, g0_amplitude)        = -0.416
    C(c, g0_sigma)            = -0.251
Warning: non-constant dispersion
[[Model]]
    (Model(constant) + Model(gaussian, prefix='g0_'))
[[Fit Statistics]]
    # fitting method   = leastsq
    # function evals   = 26
    # data points      = 90
    # variables        = 4
    chi-square         = 230.872352
    reduced chi-square = 2.68456224
    Akaike info crit   = 92.7849770
    Bayesian info crit = 102.784216
[[Variables]]
    c:             53.5977163 +/- 5.08298964 (9.48%) (init = 62.82764)
    g0_amplitude:  1452.56530 +/- 184.055229 (12.67%) (init = 1792.931)
    g0_center:     5007.95090 +/- 0.30556317 (0.01%) (init = 5008.24)
    g0_sigma:      2.19214192 +/- 0.30178592 (13.77%) (init = 2.723824)
    g0_fwhm:       5.16209963 +/- 0.71065152 (13.77%) == '2.3548200*g0_sigma'
    g0_height:     264.348643 +/- 33.1719408 (12.55%) == '0.3989423*g0_amplitude/max(1e-15, g0_sigma)'
[[Correlations]] (unreported correlations are < 0.100)
    C(g0_amplitude, g0_sigma)  =  0.552
    C(c, g0_amplitude)         = -0.325
    C(c, g0_sigma)             = -0.205
    C(g0_amplitude, g0_center) =  0.123
Warning: non-constant dispersion
[[Model]]
    (((Model(constant) + Model(gaussian, prefix='g0_')) + Model(gaussian, prefix='g1_')) + Model(gaussian, prefix='g2_'))
[[Fit Statistics]]
    # fitting method   = leastsq
    # function evals   = 122
    # data points      = 130
    # variables        = 10
    chi-square         = 225.575409
    reduced chi-square = 1.87979507
    Akaike info crit   = 91.6456077
    Bayesian info crit = 120.320952
[[Variables]]
    c:             23.7551315 +/- 2.25480022 (9.49%) (init = 31.16013)
    g0_amplitude:  386.396005 +/- 109.339539 (28.30%) (init = 2761.308)
    g0_center:     6548.43093 +/- 1.06058983 (0.02%) (init = 6549.86)
    g0_sigma:      3.52622359 +/- 1.11820288 (31.71%) (init = 2.723824)
    g1_amplitude:  2825.39951 +/- 172.230533 (6.10%) (init = 2761.308)
    g1_center:     6565.16765 +/- 0.20539719 (0.00%) (init = 6564.614)
    g1_sigma:      2.97191098 +/- 0.20583051 (6.93%) (init = 2.723824)
    g2_amplitude:  665.838176 +/- 138.167397 (20.75%) (init = 2761.308)
    g2_center:     6585.66353 +/- 0.90726119 (0.01%) (init = 6585.27)
    g2_sigma:      4.09877574 +/- 0.94242145 (22.99%) (init = 2.723824)
    g0_fwhm:       8.30362184 +/- 2.63316652 (31.71%) == '2.3548200*g0_sigma'
    g0_height:     43.7152401 +/- 11.2832950 (25.81%) == '0.3989423*g0_amplitude/max(1e-15, g0_sigma)'
    g1_fwhm:       6.99831541 +/- 0.48469381 (6.93%) == '2.3548200*g1_sigma'
    g1_height:     379.274947 +/- 21.0264894 (5.54%) == '0.3989423*g1_amplitude/max(1e-15, g1_sigma)'
    g2_fwhm:       9.65187909 +/- 2.21923288 (22.99%) == '2.3548200*g2_sigma'
    g2_height:     64.8074035 +/- 12.4670332 (19.24%) == '0.3989423*g2_amplitude/max(1e-15, g2_sigma)'
[[Correlations]] (unreported correlations are < 0.100)
    C(g1_amplitude, g1_sigma)     =  0.644
    C(g0_amplitude, g0_sigma)     =  0.635
    C(g2_amplitude, g2_sigma)     =  0.617
    C(c, g0_amplitude)            = -0.368
    C(c, g2_amplitude)            = -0.350
    C(g2_amplitude, g2_center)    = -0.266
    C(g0_amplitude, g0_center)    =  0.241
    C(g0_center, g0_sigma)        =  0.225
    C(c, g2_sigma)                = -0.209
    C(c, g0_sigma)                = -0.205
    C(c, g1_amplitude)            = -0.196
    C(g2_center, g2_sigma)        = -0.168
    C(g0_amplitude, g2_amplitude) =  0.129
    C(c, g1_sigma)                = -0.104
multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/site-packages/astropy/units/quantity.py", line 740, in to_value
    scale = self.unit._to(unit)
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/site-packages/astropy/units/core.py", line 950, in _to
    raise UnitConversionError(
astropy.units.core.UnitConversionError: 'Unit("Angstrom")' is not a scaled version of 'Unit(dimensionless)'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/site-packages/astropy/units/quantity.py", line 1086, in __float__
    return float(self.to_value(dimensionless_unscaled))
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/site-packages/astropy/units/quantity.py", line 743, in to_value
    value = self._to_value(unit, equivalencies)
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/site-packages/astropy/units/quantity.py", line 662, in _to_value
    return self.unit.to(unit, self.view(np.ndarray),
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/site-packages/astropy/units/core.py", line 987, in to
    return self._get_converter(other, equivalencies=equivalencies)(value)
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/site-packages/astropy/units/core.py", line 918, in _get_converter
    raise exc
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/site-packages/astropy/units/core.py", line 903, in _get_converter
    return self._apply_equivalencies(
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/site-packages/astropy/units/core.py", line 886, in _apply_equivalencies
    raise UnitConversionError(
astropy.units.core.UnitConversionError: 'Angstrom' (length) and '' (dimensionless) are not convertible

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/multiprocessing/pool.py", line 51, in starmapstar
    return list(itertools.starmap(args[0], args[1]))
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/site-packages/gleam/main.py", line 128, in run_main
    plot_line(
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/site-packages/gleam/plot_gaussian.py", line 370, in plot_line
    adjust_labels(texts, fig, axins, zoom)
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/site-packages/gleam/plot_gaussian.py", line 467, in adjust_labels
    [
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/site-packages/gleam/plot_gaussian.py", line 468, in <listcomp>
    text.set_position(list(np.add(text.get_position(), offset)))
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/site-packages/astropy/units/quantity.py", line 1088, in __float__
    raise TypeError('only dimensionless scalar quantities can be '
TypeError: only dimensionless scalar quantities can be converted to Python scalars
"""

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

Traceback (most recent call last):
  File "/home/raya/anaconda3/envs/py38/bin/gleam", line 8, in <module>
    sys.exit(pipeline())
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/site-packages/gleam/__init__.py", line 136, in pipeline
    p.starmap(gleam.main.run_main, unique_sources)
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/multiprocessing/pool.py", line 372, in starmap
    return self._map_async(func, iterable, starmapstar, chunksize).get()
  File "/home/raya/anaconda3/envs/py38/lib/python3.8/multiprocessing/pool.py", line 771, in get
    raise self._value
TypeError: only dimensionless scalar quantities can be converted to Python scalars

This seems again like some units issue, but this time in the example folder.
I have not touched the linelist and config files in the example folder. Still to check if the units are properly defined, I converted the fits tables to ascii.
The linelist file (when converted to ascii):

#  Table Main_optical_lines.fits[1]  Wed 02:36:00 29-Apr-2020

# row line                 wavelength latex
#                            Angstrom 

    1 OII                    3728.483 [O{\sc ii}]
    2 Hb                      4862.68 H$\boldsymbol{\beta}$
    3 OIII4                  4960.295 [O{\sc iii}]
    4 OIII5         5008.239999999999 [O{\sc iii}]
    5 Ha            6564.613999999998 H$\boldsymbol{\alpha}$
    6 NII1          6585.269999999999 [N{\sc ii}]
    7 NII2          6549.859999999999 [N{\sc ii}]
    8 SII2                    6732.67 [S{\sc ii}]
    9 SII1          6718.289999999998 [S{\sc ii}]

The gleam config file:

# This is an example of a configuration file for gleam. The format used is YAML,
# a human-readable language. Note, that in YAML indentation is important, so I 
# recommend using 2 space as indentation between levels!

# Global configurations
# We will let many of the fitting parameters to the internal defaults
globals:
  # Note if instrument resolution is not listed here, if must appear under setups of sources. 
  # path to file containing the lines to be fit
  line_table: line_lists/Main_optical_lines.fits
  # Select a subset of lines to fit
  lines:
    - OII
    - Hb 
    - OIII4
    - OIII5  
    - Ha
    - NII1
    - SII1
    - SII2
  # Path to file containing the sky lines
  sky: line_lists/Sky_bands.fits 
  # Whether or not the sky bands in the "sky" parameter should be masked
  mask_sky: True 
  # Let's constrain the center and set the continuum width to 40 Anstrom, but 
  # let the other fitting parameters to the internal defaults.
  fitting:
    cont_width: 40 Angstrom
    center: constrained


# Telescope/instrument specific setups
setups:
  # VIMOS is not among our source, but why not have it here anyway?
  VIMOS:
    # VIMOS does not have a great resolution
    resolution: 12.5 Angstrom
    # Here we override the internal default of gleam with 60 Angstrom
    fitting:
      cont_width: 60 Angstrom
  # A particular setup for the AF2 instrument on WHT
  WHT_R316R:
    resolution: 8.1 Angstrom
    # This is definitely too small, but we will override again in our source ;)
    fitting:
      cont_width: 20 Angstrom


# Some source-specific overrides
sources:
  # Name of the source to override. Note naming convetion.
  A773.WHT_R316R.Q1_EXT1.008:
    # For this source we want to fit all the lines in the input line_table. We
    # need to specify 'all' here!
    lines: all
    # Override the continuum with to 70 Angstrom
    fitting:
      # Much more reasonable value here!
      cont_width: 70 Angstrom

# The cosmological parameters, which are fixed for the entire project. You can 
# set them from here to your preferred value.
#cosmology:
#   H0: 75 km / (Mpc s)
#   Om0: 0.3
#   Tcmb0: 2.725 K

@rayadastidar rayadastidar reopened this Jul 7, 2021
@multiwavelength
Copy link
Owner

multiwavelength commented Feb 14, 2022

Hi Raya,
I am so sorry this issue fell off my radar. The issue you described was fixed by a recent update we made to the code and GLEAM should now run fine for you.
You can update your GLEAM installation to the most recent version by typing into the terminal:

python3 -m pip install --upgrade astro-gleam

Let me know if you get the chance to run GLEAM again and if the it works for you.

@multiwavelength
Copy link
Owner

I will close the issue and reopen if Raya reports any further issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants