Skip to content

Cosmology read & write method for AAS MRT - #14883

Closed
Mubin17 wants to merge 13 commits into
astropy:mainfrom
Mubin17:Mubin17/Issue#14871
Closed

Mubin17 wants to merge 13 commits into
astropy:mainfrom
Mubin17:Mubin17/Issue#14871

Conversation

@Mubin17

@Mubin17 Mubin17 commented May 31, 2023

Copy link
Copy Markdown
Contributor

Description

This pull request is to address #14871

Fixes #14871

Registered the read_mrt() and write_mrt() methods with the Cosmology class, enabling the import and export of cosmological data to and from MRT files.

Writing Example:

from astropy.cosmology import Planck18
Planck18.write("example_cosmology.mrt", overwrite=True, format="mrt")

Output:

Title:
Authors:
Table:
================================================================================
Byte-by-byte Description of file: table.dat
--------------------------------------------------------------------------------
 Bytes Format Units  Label     Explanations
--------------------------------------------------------------------------------
 1-13  A13          ---    cosmology Description of cosmology
15-22  A8           ---    name      Description of name
24-28  F5.2   km.Mpc-1.s-1 H0        [67.66/67.66] Hubble constant as an
                              `~astropy.units.Quantity` at z=0.
30-36  F7.5         ---    Om0       [0.3/0.31] Omega matter; matter
                              density/critical density at z=0.
38-43  F6.4         K      Tcmb0     [2.72/2.73] Temperature of the CMB as
                              `~astropy.units.Quantity` at z=0.
45-49  F5.3         ---    Neff      [3.04/3.05] Number of effective neutrino
                              species.
51-53  F3.1         eV     mnu0      Description of mnu0
55-57  F3.1         eV     mnu1      Description of mnu1
59-62  F4.2         eV     mnu2      [0.06/0.06] Description of mnu2
64-70  F7.5         ---    Ob0       [0.04/0.05] Omega baryon; baryonic matter
                              density/critical density at z=0.
--------------------------------------------------------------------------------
Notes:
--------------------------------------------------------------------------------
FlatLambdaCDM Planck18 67.66 0.30966 2.7255 3.046 0.0 0.0 0.06 0.04897

Reading Example

from astropy.cosmology import Cosmology
Cosmology.read('example_cosmology.mrt', format='mrt')

Output:

FlatLambdaCDM(name="Planck18", H0=67.66 km / (Mpc s), Om0=0.30966, Tcmb0=2.7255 K, Neff=3.046, m_nu=[0.   0.   0.06] eV, Ob0=0.04897)

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see "When to rebase and squash commits".
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • Is a milestone set? Milestone must be set but we cannot check for it on Actions; do not let the green checkmark fool you.
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Thank you for your draft pull request! Do you know that you can use [ci skip] or [skip ci] in your commit messages to skip running continuous integration tests until you are ready?

@pllim pllim added this to the v6.0 milestone May 31, 2023
@Mubin17 Mubin17 changed the title Added mrt.py Cosmology read & write method for AAS MRT May 31, 2023
@Mubin17
Mubin17 marked this pull request as ready for review May 31, 2023 19:08
@Mubin17
Mubin17 requested a review from a team as a code owner May 31, 2023 19:08
@Mubin17
Mubin17 requested a review from nstarman May 31, 2023 19:08

@nstarman nstarman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Mubin17 for the PR. Most things look good. I have just 2 corrections"

  1. the format should be "ascii.mrt", in line with how it's registered with Table
  2. with represent_mixins_as_columns do we still need to make separate neutrino columns?

Comment thread astropy/cosmology/io/mrt.py Resolved
Comment thread astropy/cosmology/io/mrt.py Resolved
Comment thread astropy/cosmology/io/mrt.py Resolved
Comment thread astropy/cosmology/io/mrt.py Resolved
Comment thread astropy/cosmology/io/mrt.py Resolved
Comment thread astropy/cosmology/io/mrt.py Outdated
Comment on lines +102 to +107
m_nu = table_main["m_nu"]
table.remove_column("m_nu")
for i in range(len(m_nu[0])):
column_name = f"mnu{i}"
column_data = m_nu[0][i]
table.add_column(column_data, name=column_name, index=-2)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With represent_mixins_as_columns(table_main), does this serialize without breaking apart the neutrino mass?

@Mubin17 Mubin17 Jun 2, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be completely wrong in my understanding of how serializing is supposed to work in this context. But I believe represent_mixins_as_columns(table_main), does not serialize the table without breaking apart the neutrino mass, and here is why:

from astropy.cosmology import Planck18
from astropy.table.serialize import represent_mixins_as_columns
table_main = Planck18.to_format("astropy.table")
table = represent_mixins_as_columns(table_main)

m_nu_table_main = table_main['m_nu'] # Get the m_nu column from table_main
m_nu_table = table['m_nu']  # Get the m_nu column from table

N = len(m_nu_table[0])  # Get the number of elements in m_nu

for i in range(N):
    column_data_table = m_nu_table[0][i]
    print(column_data_table, type(column_data_table))
    
for i in range(N):
    column_data_table_main = m_nu_table_main[0][i]
    print(column_data_table_main, type(column_data_table_main))

Output:

0.0 <class 'numpy.float64'>
0.0 <class 'numpy.float64'>
0.06 <class 'numpy.float64'>
0.0 eV <class 'astropy.units.quantity.Quantity'>
0.0 eV <class 'astropy.units.quantity.Quantity'>
0.06 eV <class 'astropy.units.quantity.Quantity'>

The way I see it is that, for serialization to work correctly the outputs must be the same. And this is the primary reason why I have two separate variables table_main and table

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that represent_mixins_as_columns doesn't help here. I'll open an issue to see if we can extend represent_mixins_as_columns to make structured arrays into a series of columns.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @taldcroft

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #14913 for this change.

Comment thread astropy/cosmology/io/mrt.py Resolved
Comment thread astropy/cosmology/io/mrt.py Resolved
Comment thread astropy/cosmology/io/mrt.py Resolved
Comment thread astropy/cosmology/io/mrt.py Resolved
@Mubin17
Mubin17 requested a review from nstarman June 2, 2023 21:03
@nstarman

nstarman commented Jun 4, 2023

Copy link
Copy Markdown
Member

@Mubin17, the tests are failing. It looks like many are related to this PR. If you need help, feel free to ping me for questions.

@Mubin17

Mubin17 commented Jun 4, 2023 •

Copy link
Copy Markdown
Contributor Author

@nstarman do have any insight on what is triggering this error, m_nu[0] is iterable and it is not a scalar so I don't understand why the error?

self = <astropy.cosmology.tests.test_core.TestCosmology object at 0x1186f38b0>, read = <astropy.cosmology.connect.CosmologyRead object at 0x118e04c40>
write = <astropy.cosmology.connect.CosmologyWrite object at 0x118e06140>
tmp_path = PosixPath('/private/var/folders/t3/4lbhlq652z16wh1ldqsfr04m0000gn/T/pytest-of-mubinmanasia/pytest-8/test_to_mrt_bad_index0')

    def test_to_mrt_bad_index(self, read, write, tmp_path):
        """Test if argument ``index`` is incorrect"""
        fp = tmp_path / "test_to_mrt_bad_index.mrt"
    
>       write(fp, format="ascii.mrt")

cosmology/io/tests/test_mrt.py:25: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
cosmology/connect.py:126: in __call__
    self.registry.write(self._instance, *args, **kwargs)
io/registry/core.py:383: in write
    return writer(data, *args, **kwargs)
cosmology/io/mrt.py:127: in write_mrt
    cols, names = tuple(zip(*((m, f"m_nu[{i}]") for i, m in enumerate(m_nu[0]))))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Quantity 0.6 eV>

    def __iter__(self):
        if self.isscalar:
>           raise TypeError(
                f"'{self.__class__.__name__}' object with a scalar value is not"
                " iterable"
            )
E           TypeError: 'Quantity' object with a scalar value is not iterable

units/quantity.py:1275: TypeError

The same error is triggered whenever the write_mrt() method is called in tests

FAILED cosmology/tests/test_core.py::TestCosmology::test_to_mrt_bad_index - TypeError: 'Quantity' object with a scalar value is not iterable
FAILED cosmology/tests/test_core.py::TestCosmology::test_to_mrt_cls[QTable] - TypeError: 'Quantity' object with a scalar value is not iterable
FAILED cosmology/tests/test_core.py::TestCosmology::test_to_mrt_cls[Table] - TypeError: 'numpy.float64' object is not iterable
FAILED cosmology/tests/test_core.py::TestCosmology::test_readwrite_mrt_instance - TypeError: 'Quantity' object with a scalar value is not iterable
FAILED cosmology/tests/test_core.py::TestCosmology::test_readwrite_mrt_subclass_partial_info - TypeError: 'Quantity' object with a scalar value is not iterable
FAILED cosmology/tests/test_core.py::TestCosmology::test_readwrite_complete_info[ascii.mrt-False-True] - TypeError: 'Quantity' object with a scalar value is not iterable
FAILED cosmology/tests/test_core.py::TestCosmology::test_readwrite_from_subclass_complete_info[ascii.mrt-False-True] - TypeError: 'Quantity' object with a scalar value is not iterable

@nstarman

nstarman commented Jun 6, 2023

Copy link
Copy Markdown
Member

So this is my fault. If you look at astropy.cosmology.tests.test_core.TestCosmology

        self._cls_args = dict(
            H0=70 * (u.km / u.s / u.Mpc), Tcmb0=2.7 * u.K, m_nu=0.6 * u.eV
        )

m_nu can be a scalar, which doesn't work with the code I pushed. m_nu needs to be listified first.

@Mubin17

Mubin17 commented Jun 7, 2023 •

Copy link
Copy Markdown
Contributor Author

Thanks for the insight @nstarman I've listified the m_nu parameter in the astropy.cosmology.tests.test_core.TestCosmology class and this seem to fix some of the failing tests. However, I’m not sure if this is what you meant by the phrase "m_nu needs to be listified first". I have also updated the index values from (-2, -2, -2) to (-4, -3, -2) to make sure m_un[0], m_un[1], and m_un[2] are written in the correct order.

There is one last set of failing tests that needed to be fixed:

self = <astropy.cosmology.flrw.tests.test_wpwazpcdm.TestwpwaCDM object at 0x12b6f0ac0>, cosmo_cls = <class 'astropy.cosmology.flrw.wpwazpcdm.wpwaCDM'>
cosmo = wpwaCDM(name="ABCMeta", H0=70.0 km / (Mpc s), Om0=0.27, Ode0=0.73, wp=-0.9, wa=0.2, zp=0.5 redshift, Tcmb0=3.0 K, Neff=3.04, m_nu=[0. 0. 0.] eV, Ob0=0.03)
read = <astropy.cosmology.connect.CosmologyRead object at 0x1693be8c0>, write = <astropy.cosmology.connect.CosmologyWrite object at 0x1693bfa00>
tmp_path = PosixPath('/private/var/folders/t3/4lbhlq652z16wh1ldqsfr04m0000gn/T/pytest-of-mubinmanasia/pytest-28/test_readwrite_mrt_instance9')

    def test_readwrite_mrt_instance(
        self, cosmo_cls, cosmo, read, write, tmp_path
    ):
        """Test cosmology -> ascii.mrt -> cosmology."""
        fp = tmp_path / "test_readwrite_mrt_instance.mrt"
    
        # ------------
        # To Table
    
        write(fp, format="ascii.mrt")
    
        # some checks on the saved file
        tbl = Table.read(fp, format="ascii.mrt")
        assert tbl["name"] == cosmo.name
    
        # ------------
        # From Table
    
        tbl["mismatching"] = "will error"
        tbl.write(fp, format="ascii.mrt", overwrite=True)
    
        # tests are different if the last argument is a **kwarg
        if tuple(cosmo._init_signature.parameters.values())[-1].kind == 4:
            got = read(fp, format="ascii.mrt")
    
            assert got.__class__ is cosmo_cls
            assert got.name == cosmo.name
            assert "mismatching" not in got.meta
    
            return  # don't continue testing
    
        # read with mismatching parameters errors
        with pytest.raises(TypeError, match="there are unused parameters"):
            read(fp, format="ascii.mrt")
    
        # unless mismatched are moved to meta
>       got = read(fp, format="ascii.mrt", move_to_meta=True)

cosmology/io/tests/test_mrt.py:89: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
cosmology/connect.py:86: in __call__
    cosmo = self.registry.read(self._cls, *args, **kwargs)
io/registry/core.py:218: in read
    data = reader(*args, **kwargs)
cosmology/io/mrt.py:77: in read_mrt
    return from_table(
cosmology/io/table.py:138: in from_table
    return from_row(row, move_to_meta=move_to_meta, cosmology=cosmology)
cosmology/io/row.py:80: in from_row
    return from_mapping(mapping, move_to_meta=move_to_meta, cosmology=cosmology)
cosmology/io/mapping.py:114: in from_mapping
    return cosmology(*ba.args, **ba.kwargs)
cosmology/flrw/wpwazpcdm.py:141: in __init__
    self.zp = zp
cosmology/parameter.py:138: in __set__
    value = self.validate(cosmology, copy.deepcopy(value))
cosmology/parameter.py:186: in validate
    return self.fvalidate(cosmology, self, value)
cosmology/parameter.py:348: in _validate_with_unit
    value = u.Quantity(value, param.unit)
units/quantity.py:445: in __new__
    value = value.to(unit)
units/quantity.py:935: in to
    value = self._to_value(unit, equivalencies)
units/quantity.py:888: in _to_value
    return self.unit.to(
units/core.py:1195: in to
    return self._get_converter(Unit(other), equivalencies)(value)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = UnrecognizedUnit(redshift), other = Unit("redshift"), equivalencies = []

    def _get_converter(self, other, equivalencies=None):
        self._normalize_equivalencies(equivalencies)
>       raise ValueError(
            f"The unit {self.name!r} is unrecognized.  It can not be converted "
            "to other units."
        )
E       ValueError: The unit 'redshift' is unrecognized.  It can not be converted to other units.

units/core.py:2015: ValueError
------------------------------------------------------------------------------------------- Captured stdout call -------------------------------------------------------------------------------------------
cosmology   name       H0      Om0  Ode0 ... Neff m_nu[0] m_nu[1] m_nu[2] Ob0 
                  km / (Mpc s)           ...         eV      eV      eV       
--------- ------- ------------ ---- ---- ... ---- ------- ------- ------- ----
  wpwaCDM ABCMeta         70.0 0.27 0.73 ... 3.04     0.0     0.0     0.0 0.03
FAILED cosmology/flrw/tests/test_wpwazpcdm.py::TestwpwaCDM::test_readwrite_mrt_instance - ValueError: The unit 'redshift' is unrecognized.  It can not be converted to other units.
FAILED cosmology/flrw/tests/test_wpwazpcdm.py::TestwpwaCDM::test_readwrite_mrt_subclass_partial_info - ValueError: The unit 'redshift' is unrecognized.  It can not be converted to other units.
FAILED cosmology/flrw/tests/test_wpwazpcdm.py::TestwpwaCDM::test_readwrite_complete_info[ascii.mrt-False-True] - ValueError: The unit 'redshift' is unrecognized.  It can not be converted to other units.
FAILED cosmology/flrw/tests/test_wpwazpcdm.py::TestwpwaCDM::test_readwrite_from_subclass_complete_info[ascii.mrt-False-True] - ValueError: The unit 'redshift' is unrecognized.  It can not be converted to other units.
FAILED cosmology/flrw/tests/test_wpwazpcdm.py::TestFlatwpwaCDM::test_readwrite_mrt_instance - ValueError: The unit 'redshift' is unrecognized.  It can not be converted to other units.
FAILED cosmology/flrw/tests/test_wpwazpcdm.py::TestFlatwpwaCDM::test_readwrite_mrt_subclass_partial_info - ValueError: The unit 'redshift' is unrecognized.  It can not be converted to other units.
FAILED cosmology/flrw/tests/test_wpwazpcdm.py::TestFlatwpwaCDM::test_readwrite_complete_info[ascii.mrt-False-True] - ValueError: The unit 'redshift' is unrecognized.  It can not be converted to other units.
FAILED cosmology/flrw/tests/test_wpwazpcdm.py::TestFlatwpwaCDM::test_readwrite_from_subclass_complete_info[ascii.mrt-False-True] - ValueError: The unit 'redshift' is unrecognized.  It can not be converted to other units.

@nstarman

nstarman commented Jun 7, 2023

Copy link
Copy Markdown
Member

Thanks for the insight @nstarman I've listified the m_nu parameter in the astropy.cosmology.tests.test_core.TestCosmology class.

Sorry of the confusion. m_nu shouldn't be listified in the test, it should be fixed in write_mrt. Astropy currently supports scalar m_nu, which is being tested.

@Mubin17

Mubin17 commented Jun 10, 2023

Copy link
Copy Markdown
Contributor Author

@nstarman Thanks for the clarification. I was able listify the m_nu parameter by making the following changes to the existing write_mrt method:

    # Replace the m_nu column with three columns with names 'm_nu_[i]'
    if "m_nu" in table.colnames:
        m_nu = table_main["m_nu"]
        table.remove_column("m_nu")
        m_nu = np.atleast_1d(m_nu) # Ensure m_nu is an array
        if m_nu.shape == (1,):
            table.add_column(m_nu[0], name="m_nu[0]", index=-2) # Add a single column 
        else:
            # Create multiple columns with appropriate names
            cols, names = tuple(zip(*((m, f"m_nu[{i}]") for i, m in enumerate(m_nu[0]))))
            table.add_columns(cols, names=names, indexes=(-4, -3, -2))

I ran tests on my local machine and they passed successfully.
Question: Do you know if I am allowed to use numpy here?

@nstarman

nstarman commented Jun 10, 2023 •

Copy link
Copy Markdown
Member

I ran tests on my local machine and they passed successfully.

Great!

Question: Do you know if I am allowed to use numpy here?

Always! Numpy is a runtime dependency for Astropy

table.add_columns(cols, names=names, indexes=(-4, -3, -2))

m_nu can have more than 3 elements, so this should be indexes = tuple(range(...)) or something like that.

@Mubin17

Mubin17 commented Jun 13, 2023

Copy link
Copy Markdown
Contributor Author

Thanks for the insight @nstarman I've listified the m_nu parameter in the astropy.cosmology.tests.test_core.TestCosmology class and this seem to fix some of the failing tests. However, I’m not sure if this is what you meant by the phrase "m_nu needs to be listified first". I have also updated the index values from (-2, -2, -2) to (-4, -3, -2) to make sure m_un[0], m_un[1], and m_un[2] are written in the correct order.

There is one last set of failing tests that needed to be fixed:

self = <astropy.cosmology.flrw.tests.test_wpwazpcdm.TestwpwaCDM object at 0x12b6f0ac0>, cosmo_cls = <class 'astropy.cosmology.flrw.wpwazpcdm.wpwaCDM'>
cosmo = wpwaCDM(name="ABCMeta", H0=70.0 km / (Mpc s), Om0=0.27, Ode0=0.73, wp=-0.9, wa=0.2, zp=0.5 redshift, Tcmb0=3.0 K, Neff=3.04, m_nu=[0. 0. 0.] eV, Ob0=0.03)
read = <astropy.cosmology.connect.CosmologyRead object at 0x1693be8c0>, write = <astropy.cosmology.connect.CosmologyWrite object at 0x1693bfa00>
tmp_path = PosixPath('/private/var/folders/t3/4lbhlq652z16wh1ldqsfr04m0000gn/T/pytest-of-mubinmanasia/pytest-28/test_readwrite_mrt_instance9')

    def test_readwrite_mrt_instance(
        self, cosmo_cls, cosmo, read, write, tmp_path
    ):
        """Test cosmology -> ascii.mrt -> cosmology."""
        fp = tmp_path / "test_readwrite_mrt_instance.mrt"
    
        # ------------
        # To Table
    
        write(fp, format="ascii.mrt")
    
        # some checks on the saved file
        tbl = Table.read(fp, format="ascii.mrt")
        assert tbl["name"] == cosmo.name
    
        # ------------
        # From Table
    
        tbl["mismatching"] = "will error"
        tbl.write(fp, format="ascii.mrt", overwrite=True)
    
        # tests are different if the last argument is a **kwarg
        if tuple(cosmo._init_signature.parameters.values())[-1].kind == 4:
            got = read(fp, format="ascii.mrt")
    
            assert got.__class__ is cosmo_cls
            assert got.name == cosmo.name
            assert "mismatching" not in got.meta
    
            return  # don't continue testing
    
        # read with mismatching parameters errors
        with pytest.raises(TypeError, match="there are unused parameters"):
            read(fp, format="ascii.mrt")
    
        # unless mismatched are moved to meta
>       got = read(fp, format="ascii.mrt", move_to_meta=True)

cosmology/io/tests/test_mrt.py:89: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
cosmology/connect.py:86: in __call__
    cosmo = self.registry.read(self._cls, *args, **kwargs)
io/registry/core.py:218: in read
    data = reader(*args, **kwargs)
cosmology/io/mrt.py:77: in read_mrt
    return from_table(
cosmology/io/table.py:138: in from_table
    return from_row(row, move_to_meta=move_to_meta, cosmology=cosmology)
cosmology/io/row.py:80: in from_row
    return from_mapping(mapping, move_to_meta=move_to_meta, cosmology=cosmology)
cosmology/io/mapping.py:114: in from_mapping
    return cosmology(*ba.args, **ba.kwargs)
cosmology/flrw/wpwazpcdm.py:141: in __init__
    self.zp = zp
cosmology/parameter.py:138: in __set__
    value = self.validate(cosmology, copy.deepcopy(value))
cosmology/parameter.py:186: in validate
    return self.fvalidate(cosmology, self, value)
cosmology/parameter.py:348: in _validate_with_unit
    value = u.Quantity(value, param.unit)
units/quantity.py:445: in __new__
    value = value.to(unit)
units/quantity.py:935: in to
    value = self._to_value(unit, equivalencies)
units/quantity.py:888: in _to_value
    return self.unit.to(
units/core.py:1195: in to
    return self._get_converter(Unit(other), equivalencies)(value)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = UnrecognizedUnit(redshift), other = Unit("redshift"), equivalencies = []

    def _get_converter(self, other, equivalencies=None):
        self._normalize_equivalencies(equivalencies)
>       raise ValueError(
            f"The unit {self.name!r} is unrecognized.  It can not be converted "
            "to other units."
        )
E       ValueError: The unit 'redshift' is unrecognized.  It can not be converted to other units.

units/core.py:2015: ValueError
------------------------------------------------------------------------------------------- Captured stdout call -------------------------------------------------------------------------------------------
cosmology   name       H0      Om0  Ode0 ... Neff m_nu[0] m_nu[1] m_nu[2] Ob0 
                  km / (Mpc s)           ...         eV      eV      eV       
--------- ------- ------------ ---- ---- ... ---- ------- ------- ------- ----
  wpwaCDM ABCMeta         70.0 0.27 0.73 ... 3.04     0.0     0.0     0.0 0.03
FAILED cosmology/flrw/tests/test_wpwazpcdm.py::TestwpwaCDM::test_readwrite_mrt_instance - ValueError: The unit 'redshift' is unrecognized.  It can not be converted to other units.
FAILED cosmology/flrw/tests/test_wpwazpcdm.py::TestwpwaCDM::test_readwrite_mrt_subclass_partial_info - ValueError: The unit 'redshift' is unrecognized.  It can not be converted to other units.
FAILED cosmology/flrw/tests/test_wpwazpcdm.py::TestwpwaCDM::test_readwrite_complete_info[ascii.mrt-False-True] - ValueError: The unit 'redshift' is unrecognized.  It can not be converted to other units.
FAILED cosmology/flrw/tests/test_wpwazpcdm.py::TestwpwaCDM::test_readwrite_from_subclass_complete_info[ascii.mrt-False-True] - ValueError: The unit 'redshift' is unrecognized.  It can not be converted to other units.
FAILED cosmology/flrw/tests/test_wpwazpcdm.py::TestFlatwpwaCDM::test_readwrite_mrt_instance - ValueError: The unit 'redshift' is unrecognized.  It can not be converted to other units.
FAILED cosmology/flrw/tests/test_wpwazpcdm.py::TestFlatwpwaCDM::test_readwrite_mrt_subclass_partial_info - ValueError: The unit 'redshift' is unrecognized.  It can not be converted to other units.
FAILED cosmology/flrw/tests/test_wpwazpcdm.py::TestFlatwpwaCDM::test_readwrite_complete_info[ascii.mrt-False-True] - ValueError: The unit 'redshift' is unrecognized.  It can not be converted to other units.
FAILED cosmology/flrw/tests/test_wpwazpcdm.py::TestFlatwpwaCDM::test_readwrite_from_subclass_complete_info[ascii.mrt-False-True] - ValueError: The unit 'redshift' is unrecognized.  It can not be converted to other units.

@nstarman Do have an idea on how can I tackle this ValueError: The unit 'redshift' is unrecognized. It can not be converted to other units. It come from this line from_table(table, index=index, move_to_meta=move_to_meta, cosmology=cosmology). I tried usingu.add_enabled_units(cu) but it doesn’t help.

Mubin17 and others added 9 commits June 15, 2023 21:18
@Mubin17
Mubin17 force-pushed the Mubin17/Issue#14871 branch from 52dea54 to aa5cfba Compare June 16, 2023 03:22
nstarman added 3 commits June 16, 2023 10:25
Signed-off-by: Nathaniel Starkman <[email protected]>
Signed-off-by: Nathaniel Starkman <[email protected]>
Signed-off-by: Nathaniel Starkman <[email protected]>
@nstarman

Copy link
Copy Markdown
Member

Ok. I found a workaround while diagnosing the issue!

@saimn saimn modified the milestones: v6.0, v6.1 Oct 28, 2023
@github-actions github-actions Bot added the Close? Tell stale bot that this issue/PR is stale label Nov 14, 2023
@github-actions

Copy link
Copy Markdown
Contributor

Hi humans 👋 - this pull request hasn't had any new commits for approximately 4 months. I plan to close this in 30 days if the pull request doesn't have any new commits by then.

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

If you believe I commented on this pull request incorrectly, please report this here.

@github-actions github-actions Bot added the closed-by-bot Closed by stale bot label Dec 15, 2023
@github-actions

Copy link
Copy Markdown
Contributor

I'm going to close this pull request as per my previous message. If you think what is being added/fixed here is still important, please remember to open an issue to keep track of it. Thanks!

If this is the first time I am commenting on this issue, or if you believe I closed this issue incorrectly, please report this here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Close? Tell stale bot that this issue/PR is stale closed-by-bot Closed by stale bot cosmology whatsnew-needed

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Cosmology read & write method for AAS MRT

4 participants