Skip to content

Commit

Permalink
added fortran format #14
Browse files Browse the repository at this point in the history
  • Loading branch information
leonfoks committed Feb 9, 2024
1 parent f86f0d5 commit caa0c4d
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions gspy/src/classes/data/Tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,28 +226,30 @@ def open_netcdf(cls, filename, group='tabular', **kwargs):
"""
return super(Tabular, cls).open_netcdf(filename, group, **kwargs)

# def subset(self, key, value):
# """Subset xarray where xarray[key] == value
def get_fortran_format(self, key, default_f32='f10.3', default_f64='g16.6'):

# Parameters
# ----------
# key : str
# Key in xarray Dataset
# value : scalar
# Subset where entry equals value
values = self._obj.data_vars[key]

# Returns
# -------
# out : gspy.Tabular
if 'format' in values.attrs:
return values.attrs['format']

# """
# out = type(self)()
dtype = values.dtype
if dtype == np.int32:

# out._xarray = self.where(self[key] == value)
# out._spatial_ref = self.spatial_ref
# out._key_mapping = self.key_mapping
# Get the max required spaces
large = np.max(np.abs(values))
p1 = values.min() < 0.0

# return out
out = "i{}".format(large%10 + p1)
if dtype == np.float32:
out = default_f32
if dtype == np.float64:
out = default_f64

if values.ndim == 2:
out = "{}".format(values.shape[1]) + out

return out

def write_netcdf(self, filename, group='tabular'):
"""Write to netcdf file
Expand Down

0 comments on commit caa0c4d

Please sign in to comment.