You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Register format html to Cosmology.write with nice mathjax #12356
I'm thinking the write_html(...) method would call cosmology.io.table.to_table(), format the table to nice MathJax or something and then call the QTable.write(..., format='html').
Edit: also, the mathjax representation of each parameter can be stored on the corresponding Parameter object, like how units have the format argument in def_unit.
@JefftheCloudDog, correct! Looks like a great plan for implementation.
In #12983 we are working on the backend which should make the column naming easier, so each Parameter can hold its mathjax representation.
In the meantime it might be easiest to just have a dict of parameter name -> mathjax name.
Ah, I see. The format input is just a dict that has mathjax (or some other type) representation as values which should be an optional parameter.
I'm looking through the example of def_unit, and looks like a new type of unit is defined with the format dict.
Should write_table() function the same way? Are we creating a new Cosmology or QTable object for formatting?
I suppose we are essentially using Table.write() since a QTable object is mostly identical to a Table object.
However, #12983 is not yet merged, so the whole mathjax format can just be one central dictionary:
mathjax_formats=dict(H0=..., Ode0=...)
Making it
tbl=to_table(cosmo, ...)
fornameincosmo.__parameters__:
new_name=mathjax_formats.get(name, name) # fallback if not in formatstbl.rename_column(name, new_name)
Anyway, that's just what I was suggesting as a workaround until #12983 is in.
Ok, I see. Since this deals with i/o, the new code should go to astropy\cosmology\table.py?
I see that there is already a line for convert_registry.register_writer("astropy.table", Cosmology, to_table), so I was not sure if there should be a different file to register the new method.
I see that there is already a line for convert_registry.register_writer("astropy.table", Cosmology, to_table), so I was not sure if there should be a different file to register the new method.
Yes, this should probably have a new file astropy/cosmology/io/html.py.
I am writing tests now and it looks like writing fails with the following errors. I am not quite sure why these errors are appearing. I have been trying to understand why the error is occurring, since ascii.html is a built-in HTML table writer, but I am struggling a little. Can someone provide some support?
I based the first test on cosmology\io\tests\test_ecsv.py. Seems like the test is just failing on write.
@JefftheCloudDog Thanks for dropping in the test output. The best way for me to help will be to see the code. To do that, it would be great if you opened a Pull Request with your code. Don't worry that the PR is not in it's final state, you can open it as Draft. Thanks!
Thanks for the response! I created a draft pull request for this issue. I did try to adhere to the instructions, but since this is my first contribution, there might be some mistakes. Please let me know if there are any issues.
Activity
JefftheCloudDog commentedon Mar 22, 2022
Hi. I am a new contributor and was wondering if this was still open for contribution? I would like to look into this if possible.
pllim commentedon Mar 22, 2022
Hello! The issue is still open, so feel free. 😸
nstarman commentedon Mar 22, 2022
@JefftheCloudDog that would be great! No one else is currently working on this feature request. If you need any help or have any questions I am happy to help. You can post here, or in the Astropy Slack cosmology channel. We also have documentation to assist in contributing at https://www.astropy.org/contribute.html#contribute-code-or-docs.
JefftheCloudDog commentedon Apr 2, 2022
From my understanding of the request description, the high-level steps should look as such:
cosmology.io.table.to_table()function, which returns a QTableQTable.write()to writereadwrite_registry.register_writer("ascii.html", Cosmology, write_table)From the steps and observing some examples from Cosmology/io, this
write_table()should look very similar towrite_ecsv()from Cosmology/io/ecsv.pyAm I correct in understanding so far?
nstarman commentedon Apr 2, 2022
@JefftheCloudDog, correct! Looks like a great plan for implementation.
In #12983 we are working on the backend which should make the column naming easier, so each Parameter can hold its mathjax representation.
In the meantime it might be easiest to just have a
dictof parameter name -> mathjax name.JefftheCloudDog commentedon Apr 3, 2022
Ah, I see. The format input is just a dict that has mathjax (or some other type) representation as values which should be an optional parameter.
I'm looking through the example of def_unit, and looks like a new type of unit is defined with the format dict.
Should
write_table()function the same way? Are we creating a new Cosmology or QTable object for formatting?I suppose we are essentially using
Table.write()since a QTable object is mostly identical to a Table object.nstarman commentedon Apr 3, 2022
When #12983 is merged then each parameter will hold its mathjax representation.
e.g. for latex.
So then the columns of the
FLRW->QTablecan be renamed like (note this is a quick and dirty implementation)However, #12983 is not yet merged, so the whole mathjax format can just be one central dictionary:
Making it
Anyway, that's just what I was suggesting as a workaround until #12983 is in.
JefftheCloudDog commentedon Apr 3, 2022
Ok, I see. Since this deals with i/o, the new code should go to astropy\cosmology\table.py?
I see that there is already a line for
convert_registry.register_writer("astropy.table", Cosmology, to_table), so I was not sure if there should be a different file to register the new method.nstarman commentedon Apr 3, 2022
Yes, this should probably have a new file
astropy/cosmology/io/html.py.JefftheCloudDog commentedon Apr 6, 2022
I am writing tests now and it looks like writing fails with the following errors. I am not quite sure why these errors are appearing. I have been trying to understand why the error is occurring, since ascii.html is a built-in HTML table writer, but I am struggling a little. Can someone provide some support?
I based the first test on cosmology\io\tests\test_ecsv.py. Seems like the test is just failing on write.
error:
nstarman commentedon Apr 6, 2022
@JefftheCloudDog Thanks for dropping in the test output. The best way for me to help will be to see the code. To do that, it would be great if you opened a Pull Request with your code. Don't worry that the PR is not in it's final state, you can open it as Draft. Thanks!
See https://docs.astropy.org/en/latest/development/workflow/development_workflow.html if you are unsure how to make a Pull Request.
JefftheCloudDog commentedon Apr 6, 2022
Thanks for the response! I created a draft pull request for this issue. I did try to adhere to the instructions, but since this is my first contribution, there might be some mistakes. Please let me know if there are any issues.