Skip to content
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

fix: only attempt to squeeze from final dimension in harmonics objects #108

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions gravity_toolkit/harmonics.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
Updated 03/2023: customizable file-level attributes to netCDF4 and HDF5
add attributes fetching to the from_dict and to_dict functions
retrieve all root attributes from HDF5 and netCDF4 datasets
only attempt to squeeze from final dimension in harmonics objects
Updated 02/2023: fix expand case where data is a single degree
fixed case where maximum spherical harmonic degree is 0
use monospaced text for harmonics objects in docstrings
Expand Down Expand Up @@ -365,8 +366,9 @@ def from_netCDF4(self, filename, **kwargs):
self.attributes['ROOT'][att_name] = fileID.getncattr(att_name)
# Closing the NetCDF file
fileID.close()
# remove singleton dimensions and
# assign shape and ndim attributes
self.update_dimensions()
self.squeeze(update_dimensions=True)
return self

def from_HDF5(self, filename, **kwargs):
Expand Down Expand Up @@ -466,8 +468,9 @@ def from_HDF5(self, filename, **kwargs):
self.attributes['ROOT'][att_name] = att_val
# Closing the HDF5 file
fileID.close()
# remove singleton dimensions and
# assign shape and ndim attributes
self.update_dimensions()
self.squeeze(update_dimensions=True)
return self

def from_gfc(self, filename, **kwargs):
Expand Down Expand Up @@ -1386,10 +1389,13 @@ def squeeze(self, update_dimensions=True):
Update the degree and order dimensions
"""
# squeeze singleton dimensions
self.time = np.squeeze(self.time)
self.month = np.squeeze(self.month)
self.clm = np.squeeze(self.clm)
self.slm = np.squeeze(self.slm)
try:
self.clm = np.squeeze(self.clm, axis=-1)
self.slm = np.squeeze(self.slm, axis=-1)
self.time = np.squeeze(self.time)
self.month = np.squeeze(self.month)
except ValueError as exc:
pass
# reassign ndim and shape attributes
if update_dimensions:
self.update_dimensions()
Expand Down