New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add units to a Table #199
Add units to a Table #199
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this. I added a number of comments inline related to the user interface and maintainability. Most of these are minor/optional, but curiously the one I care most about is not making the user set the logger after import since it moves boilerplate responsibility to the user instead of the model; it is a different pattern than most of the rest of our code; and science users using this for a VAC may not even know what a desiutil logger is...
log.debug("t.replace_column('%s', t['%s'].to('%s'))", column, column, units[column]) | ||
t.replace_column(column, t[column].to(units[column])) | ||
except UnitConversionError: | ||
log.error("Cannot add or replace unit '%s' to column '%s'!", units[column], column) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider adding an equivalent units check to csv_units
and yml_units
to catch invalid units at the time they are loaded, before attempting to apply them to a table.
OTOH, it if the input file has invalid units for a column that isn't in the table anyway, it could be considered a feature to not complain until you actually try to use it, so I could see an argument either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but that would come into play when implementing the command-line script that adds units to FITS files, as opposed to a Table
.
However, I should emphasize here that the UnitConversionError
exception isn't checking for the validity of the unit format. That is catching the much more specific case where existing units are being converted to other units requested by the user, for example, nm
--> Angstrom
or deg
--> arcsec
.
Still, I agree that there should be a check on the validity of the unit format.
@sbailey, I suggest moving forward with merging this and splitting off the task of verifying unit format into a separate issue. There is already unit format verification code in desidatamodel, and I additionally propose moving that code to desiutil so that desiutil doesn't have to depend on desidatamodel. |
This PR addresses parts of #191, focussed on adding units to a
astropy.table.Table
.Here's a simple test snippet:
TO DO: