Add physical module to units index, and include list of types#11618
Conversation
|
Hmm, not quite consistent with other unit listings (if you scroll up and down): https://astropy--11618.org.readthedocs.build/en/11618/units/index.html#module-astropy.units.physical |
|
Ah, was about to post the link! Note that this table is really for the physical types, so it is not supposed to be the same as the other unit listings. One question is whether it would make more sense to do the mapping by physical type (rather than the unit). Or perhaps have both, though I feel that is a bit superfluous. |
For xref in #11595 I feel quite strongly that the mapping should be by physical type. I think this also makes a lot more sense physically, where different unit systems have a different base unit corresponding to each physical type. In #11595 I had columns : "physical type" and "example unit" for the above 2 reasons. |
|
But the Latex representation is great! so much better than what was in #11595. |
|
OK, perhaps I should switch it around. It feels like it would be best to sort the physical type then, which is a bit tricky given that some units are associated with multiple types. I guess then maybe we should have 3 columns: phys-type-name, unit, other names in same physical type. |
|
Thank you for doing this! I think this table is going to be really helpful. One thing that the above screenshot of the table reminded me of... Right now using >>> print(u.m.physical_type) # single physical type name
length
>>> print(u.Pa.physical_type)
{'energy density', 'pressure', 'stress'} # multiple physical type namesShould we change this so that >>> print(u.Pa.physical_type)
energy density, pressure, stressThe reason why is that if someone uses |
|
@namurphy. I think that is a good suggestion for |
I originally had some hesitations about changing
I suppose the first thing isn't really that big of a factor, and the second could be resolved by either using the SI decomposition, or whatever units were used when originally instantiating each PhysicalType(m, 'length')
PhysicalType(Unit('m'), 'length')
PhysicalType(m * s, {'absement', 'sustained displacement'})
PhysicalType(Unit('m s'), {'absement', 'sustained displacement'})Changing |
It's definitely not an urgent need. Many objects in astropy were chosen to not have round-tripable reps. But it's always nice when it can be done and is a small change. I like and also prefer the idea of decomposing to SI.
Agreed. |
|
Note that in the current version of this PR, I do not use But FWIW, I can see the case for changing |
Oh, good point, I didn't notice that. Yes, let's continue this conversation in #11625. |
|
Wondering what to do with the PR: are people happy with how the docs look now? - https://astropy--11618.org.readthedocs.build/en/11618/units/index.html#module-astropy.units.physical My own sense would be to get this in and change it later as the need arises. |
|
|
||
| .. list-table:: Defined Physical Types | ||
| :header-rows: 1 | ||
| :widths: 30 10 50 |
There was a problem hiding this comment.
I think the "Other physical type(s) with same unit" column is a little too wide, but I agree! let's get this in and fiddle with some settings when we add x-ref link targets.
adrn
left a comment
There was a problem hiding this comment.
Approving because my only comment is about style, and it's subjective, and I am not particularly advocating for my suggestion. So, feel free to ignore and merge as is, or accept the change (but then you should also change the style of L537–546)
| docstring.write(f""" | ||
| * - {ptype_name} | ||
| - :math:`{physical_type._unit.to_string('latex')[1:-1]}` | ||
| - {', '.join([name for name in physical_type if name != ptype_name])} | ||
| """) |
There was a problem hiding this comment.
Bikeshedding warning 😉
Which is less ugly here? For some reason the """) at the start of the line is jarring to me, but have to admit that my suggestion might be equally abhorrent 😅. If you go with mine here, change the block above to be similar?
| docstring.write(f""" | |
| * - {ptype_name} | |
| - :math:`{physical_type._unit.to_string('latex')[1:-1]}` | |
| - {', '.join([name for name in physical_type if name != ptype_name])} | |
| """) | |
| docstring.write("\n".join([ | |
| f" * - {ptype_name}", | |
| f" - :math:`{physical_type._unit.to_string('latex')[1:-1]}`", | |
| f" - {', '.join([name for name in physical_type if name != ptype_name])}" | |
| ]) |
|
This PR looks great to me too. Thank you again for doing this! |
2290e04 to
05c44b5
Compare

This is an alternative to part of #11595, to typeset the known physical types in the documentation, following how units lists are created. It should be easy to extend this to allow links, but that's for follow-up.
Note that this also makes the
physicalmodule visible in the units documentation - that was an oversight in #11118.