running LineRatioFit with measurements as a dict gives error

84 views
Skip to first unread message

Aaron Bryant

unread,
Jan 25, 2023, 9:24:51 AM1/25/23
to PDR Toolbox
Hi Marc,

using version 2.3.0

if I put measurements into LineRatioFit as a dictionary, with keys as line identifiers, when doing lrf.run() I get an Attribute Error. See below for comparison with measurements as a list, which works fine:

type(meas_list), type(meas_dict)
Out[35]: (list, dict)

lrf_list = LineRatioFit(ms, measurements = meas_list)

lrf_dict = LineRatioFit(ms, measurements = meas_dict)

lrf_list.run()
0%| | 0/8118 [00:00<?, ?it/s]
fitted 6949 of 8118 pixels
got 0 exceptions

lrf_dict.run()
Traceback (most recent call last):

Input In [39] in <cell line: 1>
lrf_dict.run()

File C:\ProgramData\Anaconda3\lib\site-packages\pdrtpy\tool\lineratiofit.py:387 in run
self._reset_masks()

File C:\ProgramData\Anaconda3\lib\site-packages\pdrtpy\tool\lineratiofit.py:417 in _reset_masks
self._measurements[m].mask = deepcopy(self._masks[m])

AttributeError: 'LineRatioFit' object has no attribute '_masks'

lrf_list._masks
Out[40]:
{'OI_63': array([[ True, True, True, ..., True, True, True],
[ True, True, True, ..., True, True, True],
[ True, True, True, ..., True, True, True],
...,
[False, False, False, ..., True, True, True],
[False, False, False, ..., True, True, True],
[False, False, False, ..., True, True, True]]),
'OI_145': array([[ True, True, True, ..., True, True, True],
[ True, True, True, ..., True, True, True],
[ True, True, True, ..., True, True, True],
...,
[False, False, False, ..., True, True, True],
[False, False, False, ..., True, True, True],
[False, False, False, ..., True, True, True]]),
'CII_158': array([[ True, True, True, ..., True, True, True],
[ True, True, True, ..., True, True, True],
[ True, True, True, ..., True, True, True],
...,
[False, False, False, ..., True, True, True],
[False, False, False, ..., True, True, True],
[False, False, False, ..., True, True, True]])}

lrf_dict._masks
Traceback (most recent call last):

Input In [41] in <cell line: 1>
lrf_dict._masks

AttributeError: 'LineRatioFit' object has no attribute '_masks'

I see in line 50 of lineratiofit.py, dict measurements get turned straight into self._measurements, whereas list measurements go to _init_measurements where self gets the _masks attribute. So I think this may be the source of the problem.

thanks,
Aaron

Marc W. Pound

unread,
Jan 25, 2023, 10:37:40 AM1/25/23
to Aaron Bryant, PDR Toolbox
Dear Aaron,

Thanks for finding a bug and the hint for where to look!   Can you provide a minimal running/failing example python script?  I am working on a new release for ~next week so can possibly get this bug fix in if it is simple.

Marc


--
You received this message because you are subscribed to the Google Groups "PDR Toolbox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pdrt+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pdrt/a1b43fda-4855-4cd2-81ca-e4ba80a05acan%40googlegroups.com.


--
Dr. Marc Pound
Research Scientist
Astronomy Department
University of Maryland, College Park
Message has been deleted

Aaron Bryant

unread,
Jan 25, 2023, 11:15:16 AM1/25/23
to PDR Toolbox
Hi Marc,

using the example data:



from pdrtpy.modelset import ModelSet
from pdrtpy.tool.lineratiofit import LineRatioFit
from pdrtpy.measurement import Measurement
import pdrtpy.pdrutils as utils

cii_flux = utils.get_testdata("n22_cii_flux.fits")
cii_err = utils.get_testdata("n22_cii_error.fits")
oi_flux = utils.get_testdata("n22_oi_flux.fits")
oi_err = utils.get_testdata("n22_oi_error.fits")
FIR_flux = utils.get_testdata("n22_FIR.fits")

cii_combined = "n22_cii_flux_error.fits"
oi_combined = "n22_oi_flux_error.fits"
FIR_combined = "n22_FIR_flux_error.fits"

Measurement.make_measurement(cii_flux, cii_err, cii_combined,overwrite=True)
Measurement.make_measurement(oi_flux, oi_err, oi_combined,overwrite=True)
Measurement.make_measurement(FIR_flux, error='10%', outfile=FIR_combined,overwrite=True)

cii_meas = Measurement.read(cii_combined, identifier="CII_158")
FIR_meas = Measurement.read(FIR_combined, identifier="FIR")
oi_meas = Measurement.read(oi_combined, identifier="OI_63")

ms = ModelSet("wk2020", z=1)

meas_list = (cii_meas, oi_meas, FIR_meas)
lrf_list = LineRatioFit(ms, meas_list)
lrf_list.run()

meas_dict = {cii_meas.id: cii_meas, oi_meas.id: oi_meas, FIR_meas.id: FIR_meas}
lrf_dict = LineRatioFit(ms, meas_dict)
lrf_dict.run()



lrf_dict.run() will raise an AttributeError

at least from my side I could fix it by editing lineratiofit.py like this, starting at line 49, the parts I added being in bold:

        if type(measurements) == dict or measurements is None:
            self._measurements = measurements
            self._masks = dict()
            for key in measurements:
                self._masks[key] = deepcopy(measurements[key].mask)

        else:
            self._init_measurements(measurements)



regards,
Aaron

Marc W. Pound

unread,
Feb 6, 2023, 1:57:52 PM2/6/23
to PDR Toolbox
Aaron 
This is now fixed in version 2.3.1 just released
Marc


Reply all
Reply to author
Forward
0 new messages