flaresimulations / synthesizer

Synthesizer - a code for creating synthetic astrophysical observables
https://flaresimulations.github.io/synthesizer/
GNU General Public License v3.0
17 stars 9 forks source link

OK, a real UnifiedAGN line issue #735

Closed stephenmwilkins closed 1 month ago

stephenmwilkins commented 2 months ago

OK, so the previous one was because I hadn't generated the spectra. However, this one looks more like a bona fide bug:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[9], line 5
      3 # get the spectra assuming this emission model
      4 blackhole.get_spectra(emission_model)
----> 5 lines = blackhole.get_lines(line_ids, emission_model)
      6 print(lines)

File ~/Dropbox/Research/projects/synthesizer/src/synthesizer/components/blackhole.py:933, in BlackholesComponent.get_lines(self, line_ids, emission_model, dust_curves, tau_v, covering_fraction, mask, verbose, **kwargs)
    879 """
    880 Generate stellar lines as described by the emission model.
    881 
   (...)
    930         root model.
    931 """
    932 # Get the lines
--> 933 lines, particle_lines = emission_model._get_lines(
    934     line_ids=line_ids,
    935     emitters={"blackhole": self},
    936     dust_curves=dust_curves,
    937     tau_v=tau_v,
    938     fesc=covering_fraction,
    939     mask=mask,
    940     verbose=verbose,
    941     **kwargs,
    942 )
    944 # Update the lines dictionary
    945 self.lines.update(lines)

File ~/Dropbox/Research/projects/synthesizer/src/synthesizer/emission_models/base_model.py:2663, in EmissionModel._get_lines(self, line_ids, emitters, dust_curves, tau_v, fesc, covering_fraction, mask, verbose, lines, particle_lines, _is_related, **kwargs)
   2661 # Apply any post processing functions
   2662 for func in self._post_processing:
-> 2663     lines = func(lines, emitters, self)
   2664     if len(particle_lines) > 0:
   2665         particle_lines = func(particle_lines, emitters, self)

File ~/Dropbox/Research/projects/synthesizer/src/synthesizer/emission_models/agn/unified_agn.py:89, in scale_by_incident_isotropic(emission, emitters, model)
     86 emitter = emitters[this_model.emitter]
     88 # Loop over the lines
---> 89 for line_id, line in emission[key]:
     90     # Get the continuum of the isotropic disc emission
     91     isotropic_continuum = line._continuum
     93     # Get the scaling

File ~/Dropbox/Research/projects/synthesizer/src/synthesizer/line.py:330, in LineCollection.__getitem__(self, line_id)
    322 def __getitem__(self, line_id):
    323     """
    324     Simply returns one particular line from the collection.
    325 
   (...)
    328             A synthesizer.line.Line object.
    329     """
--> 330     return self.lines[line_id]

KeyError: 'disc_transmitted_blr'
WillJRoper commented 2 months ago

That one I'll give you 😂. That's because the post-processing function isn't set up for the line collection structure (at a guess from the Traceback). What branch are you on? I can take a look at it soon.

In short, I think it's expecting emission to be a dict of spectra but instead it's a line collection. It's almost like there should be another layer to emission

stephenmwilkins commented 2 months ago

Actually, after restarting I'm now getting a different error.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[8], line 3
      1 # get the spectra assuming this emission model
      2 blackhole.get_spectra(emission_model)
----> 3 lines = blackhole.get_lines(line_ids, emission_model)
      4 print(lines)

File ~/Dropbox/Research/projects/synthesizer/src/synthesizer/components/blackhole.py:933, in BlackholesComponent.get_lines(self, line_ids, emission_model, dust_curves, tau_v, covering_fraction, mask, verbose, **kwargs)
    879 """
    880 Generate stellar lines as described by the emission model.
    881 
   (...)
    930         root model.
    931 """
    932 # Get the lines
--> 933 lines, particle_lines = emission_model._get_lines(
    934     line_ids=line_ids,
    935     emitters={"blackhole": self},
    936     dust_curves=dust_curves,
    937     tau_v=tau_v,
    938     fesc=covering_fraction,
    939     mask=mask,
    940     verbose=verbose,
    941     **kwargs,
    942 )
    944 # Update the lines dictionary
    945 self.lines.update(lines)

File ~/Dropbox/Research/projects/synthesizer/src/synthesizer/emission_models/base_model.py:2522, in EmissionModel._get_lines(self, line_ids, emitters, dust_curves, tau_v, fesc, covering_fraction, mask, verbose, lines, particle_lines, _is_related, **kwargs)
   2515     raise exceptions.InconsistentArguments(
   2516         f"{self.label} is not being saved. There's no point in "
   2517         "generating at the root if they are not saved. Maybe you "
   2518         "want to use a child model you are saving instead?"
   2519     )
   2521 # Perform all extractions
-> 2522 lines, particle_lines = self._extract_lines(
   2523     line_ids,
   2524     emission_model,
   2525     emitters,
   2526     lines,
   2527     particle_lines,
   2528     verbose,
   2529     **kwargs,
   2530 )
   2532 # With all base lines extracted we can now loop from bottom to top
   2533 # of the tree creating each lines
   2534 for label in emission_model._bottom_to_top:
   2535     # Get this model

File ~/Dropbox/Research/projects/synthesizer/src/synthesizer/emission_models/operations.py:224, in Extraction._extract_lines(self, line_ids, emission_model, emitters, lines, particle_lines, verbose, **kwargs)
    221 # Loop over the line ids
    222 for line_id in line_ids:
    223     # Get this base lines
--> 224     out_lines[line_id] = generator_func(
    225         grid=this_model.grid,
    226         line_id=line_id,
    227         line_type=this_model.extract,
    228         fesc=getattr(emitter, this_model.fesc)
    229         if isinstance(this_model.fesc, str)
    230         else this_model.fesc,
    231         mask=this_mask,
    232         verbose=verbose,
    233         **kwargs,
    234     )
    236 # Store the lines in the right place (integrating if we need to)
    237 if this_model.per_particle:

File ~/Dropbox/Research/projects/synthesizer/src/synthesizer/components/blackhole.py:482, in BlackholesComponent.generate_line(self, grid, line_id, line_type, fesc, mask, method, nthreads, verbose)
    478 lam = grid.line_lams[line_id_] * angstrom
    480 # Get the luminosity and continuum
    481 lum, cont = compute_integrated_line(
--> 482     *self._prepare_line_args(
    483         grid,
    484         line_id_,
    485         line_type,
    486         fesc,
    487         mask=mask,
    488         grid_assignment_method=method,
    489         nthreads=nthreads,
    490     )
    491 )
    493 # Append this lines values to the containers
    494 lines.append(
    495     Line(
    496         line_id=line_id_,
   (...)
    500     )
501 )

File ~/Dropbox/Research/projects/synthesizer/src/synthesizer/parametric/blackholes.py:377, in BlackHole._prepare_line_args(self, grid, line_id, line_type, fesc, mask, grid_assignment_method, nthreads)
    375 # Handle the case where mask is None
    376 if mask is None:
--> 377     mask = np.ones(self.nbh, dtype=bool)
    379 # Set up the inputs to the C function.
    380 grid_props = [
    381     np.ascontiguousarray(getattr(grid, axis), dtype=np.float64)
    382     for axis in grid.axes
    383 ]

AttributeError: 'BlackHole' object has no attribute 'nbh'
stephenmwilkins commented 2 months ago

unifiedagn_fixes branch

WillJRoper commented 2 months ago

Oh fun... nbh needs to be set to 1 on a Parametric BlackHole I guess. That must have not been caught before because it was all masked? I guess anyway since the docs have run without issue 😂