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
Use grid_var_names everywhere
UXARRY uses grid_var_names to map mesh topology variable names, but it is not used for all variables currently. For example, Mesh2_edge_nodes is not referred to through grid_var_names. Not using mapped names becomes an issue when a dataset uses a different topology information variable name from default Mesh2.
Describe the solution you'd like
Use grid_var_names for all topology variables.
I'll look into this! We've been thinking of a refactor to how we internally use grid_var_names, since there are quite a few inconsistencies throughout our usages.
Can you explain the issue that you encountered a bit more in detail? Specifically, were you using our access attributes (uxds.uxgrid.Mesh2_edge_nodes) or directly accessing the internal dataset (uxds.uxgrid._ds).
@philipc2 A main issue with this in my case is slicing (or sel with xarray). Since there could be two different names for same topology variables and dimensions, slicing becomes a headache.
For the case of a UGRID dataset (which I believe you are referring to), If the inputted dataset has variable names that aren't the ones that we use (i.e. Instead of Mesh2_edge_nodes it may simply be mesh_edge_nodes), there would be inconsitensties between the variable names (especially if we construct a new one internally)
This could cause some headaches when working with UxDataArray or UxDataset for the case where where the variable names are not matched.
I'll give this a look through and get a fix out soon! Thank you for bringing this to light!
@philipc2 Thanks for taking care of it. That is exactly the case. You described it much better than I did. 👍
This issue breaks my use cases, and I do not see a simple way to correct it on my side.
@philipc2 Thanks for taking care of it. That is exactly the case. You described it much better than I did. 👍 This issue breaks my use cases, and I do not see a simple way to correct it on my side.
We should get all grid_var_names in our dictionary.
@kjnam It'd be good if you shared a mesh with mesh_edge_nodes etc. for var name.
Retire grid_var_names for Indexing, Standardize Variable/Dimension Names across Grid, UxDataset, and UxDataArray
The grid_var_names dictionary only serves a purpose for UGRID datasets, mapping our internal names (which follows the naming in the UGRID examples under the documentation) to the original names in the inputted dataset.
To avoid any inconstancies with naming, at the data loading step (open_grid or open_dataset), the variable and dimension names will be standardized to the convention that we have already been employing as seen below:
Having standardized names in our Grid means that we should also parse over the data file in our UxDataset to adjust the names to match our conventions.
@philipc2 Thanks for your suggestion. It is what I just did for my use case as a temporary measure, and I agree it is a reasonable option. Converting (or standardizing) names would certainly make the matter simple inside of uxarray, though it means that we are losing a bit of the original UGRID information.
Keeping the original information in post-processed outputs may matter in some cases. (I certainly need to keep it, at least for now.) Uxarray does not (or does not need to) have writing IO functions implemented yet, as far as I know, and it is probably not a concern for now.
Maybe uxarray can store the original name of a UGRID so that it can be recovered when the grid data is written (or accessed) to comply with the UGRID convention in outputs. This is like the current approach without mapping names internally.
@philipc2 Thanks for your suggestion. It is what I just did for my use case as a temporary measure, and I agree it is a reasonable option. Converting (or standardizing) names would certainly make the matter simple inside of uxarray, though it means that we are losing a bit of the original UGRID information. Keeping the original information in post-processed outputs may matter in some cases. (I certainly need to keep it, at least for now.)
I agree with this. In case user just reads in and then writes out an UGRID file with custom variable names, preserving those nomes in the output would be favorable. So, instead of retiring grid_var_names, we can consider making it internal API and use only for UGRID case internally.
Uxarray does not (or does not need to) have writing IO functions implemented yet, as far as I know, and it is probably not a concern for now. Maybe uxarray can store the original name of a UGRID so that it can be recovered when the grid data is written (or accessed) to comply with the UGRID convention in outputs. This is like the current approach without mapping names internally.
We have encode_as where the user can generate a Xarray dataset in the desired grid type out of their UXarray dataset.
We thought encoding instead of writing out to file would work better as Xarray has already functions like to_netcdf that supports writing to file. Thoughts?
Activity
philipc2 commentedon Jun 29, 2023
Hi @kjnam
I'll look into this! We've been thinking of a refactor to how we internally use
grid_var_names, since there are quite a few inconsistencies throughout our usages.Can you explain the issue that you encountered a bit more in detail? Specifically, were you using our access attributes (
uxds.uxgrid.Mesh2_edge_nodes) or directly accessing the internal dataset (uxds.uxgrid._ds).kjnam commentedon Jun 29, 2023
@philipc2 A main issue with this in my case is slicing (or
selwithxarray). Since there could be two different names for same topology variables and dimensions, slicing becomes a headache.philipc2 commentedon Jun 29, 2023
@kjnam
I can see where that would cause issues.
For the case of a UGRID dataset (which I believe you are referring to), If the inputted dataset has variable names that aren't the ones that we use (i.e. Instead of
Mesh2_edge_nodesit may simply bemesh_edge_nodes), there would be inconsitensties between the variable names (especially if we construct a new one internally)This could cause some headaches when working with
UxDataArrayorUxDatasetfor the case where where the variable names are not matched.I'll give this a look through and get a fix out soon! Thank you for bringing this to light!
kjnam commentedon Jun 29, 2023
@philipc2 Thanks for taking care of it. That is exactly the case. You described it much better than I did. 👍
This issue breaks my use cases, and I do not see a simple way to correct it on my side.
rajeeja commentedon Jun 29, 2023
We should get all
grid_var_namesin our dictionary.@kjnam It'd be good if you shared a mesh with
mesh_edge_nodesetc. for var name.kjnam commentedon Jun 29, 2023
@rljacob I will concoct and upload a small example file.
For now, I am renaming items in my dataset to go around the issue.
philipc2 commentedon Jun 30, 2023
Here's my proposed solution:
Retire
grid_var_namesfor Indexing, Standardize Variable/Dimension Names acrossGrid,UxDataset, andUxDataArrayThe
grid_var_namesdictionary only serves a purpose for UGRID datasets, mapping our internal names (which follows the naming in the UGRID examples under the documentation) to the original names in the inputted dataset.To avoid any inconstancies with naming, at the data loading step (
open_gridoropen_dataset), the variable and dimension names will be standardized to the convention that we have already been employing as seen below:Having standardized names in our
Gridmeans that we should also parse over the data file in ourUxDatasetto adjust the names to match our conventions.kjnam commentedon Jun 30, 2023
@philipc2 Thanks for your suggestion. It is what I just did for my use case as a temporary measure, and I agree it is a reasonable option. Converting (or standardizing) names would certainly make the matter simple inside of uxarray, though it means that we are losing a bit of the original UGRID information.
Keeping the original information in post-processed outputs may matter in some cases. (I certainly need to keep it, at least for now.) Uxarray does not (or does not need to) have writing IO functions implemented yet, as far as I know, and it is probably not a concern for now.
Maybe uxarray can store the original name of a UGRID so that it can be recovered when the grid data is written (or accessed) to comply with the UGRID convention in outputs. This is like the current approach without mapping names internally.
erogluorhan commentedon Jul 11, 2023
I agree with this. In case user just reads in and then writes out an UGRID file with custom variable names, preserving those nomes in the output would be favorable. So, instead of retiring
grid_var_names, we can consider making it internal API and use only for UGRID case internally.We have
encode_aswhere the user can generate a Xarray dataset in the desired grid type out of their UXarray dataset.We thought encoding instead of writing out to file would work better as Xarray has already functions like
to_netcdfthat supports writing to file. Thoughts?kjnam commentedon Jul 11, 2023
@erogluorhan Sounds good to me.