Skip to content

Commit

Permalink
Inline comment describing enocding attribute removal when reading a n…
Browse files Browse the repository at this point in the history
…etcdf
  • Loading branch information
BaptisteVandecrux committed Jun 19, 2024
1 parent 7756f30 commit 48817e6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/pypromice/process/get_l2tol3.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ def get_l2tol3():
# Define Level 2 dataset from file
with xr.open_dataset(args.inpath) as l2:
l2.load()

# Remove encoding attributes from NetCDF
for varname in l2.variables:
if 'encoding' in l2[varname].attrs:
del l2[varname].attrs['encoding']
del l2[varname].attrs['encoding']

if 'bedrock' in l2.attrs.keys():
l2.attrs['bedrock'] = l2.attrs['bedrock'] == 'True'
if 'number_of_booms' in l2.attrs.keys():
Expand Down
1 change: 1 addition & 0 deletions src/pypromice/process/join_l2.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def loadArr(infile):
elif infile.split('.')[-1].lower() == 'nc':
with xr.open_dataset(infile) as ds:
ds.load()
# Remove encoding attributes from NetCDF
for varname in ds.variables:
if 'encoding' in ds[varname].attrs:
del ds[varname].attrs['encoding']
Expand Down
1 change: 1 addition & 0 deletions src/pypromice/process/join_l3.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def loadArr(infile):
f.close()
elif infile.split('.')[-1].lower() in 'nc':
ds = xr.open_dataset(infile)
# Remove encoding attributes from NetCDF
for varname in ds.variables:
if 'encoding' in ds[varname].attrs:
del ds[varname].attrs['encoding']
Expand Down
3 changes: 1 addition & 2 deletions src/pypromice/process/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ def writeNC(outfile, Lx, col_names=None):
names = [c for c in col_names if c in list(Lx.keys())]
else:
names = list(Lx.keys())
for var in names:
Lx[var].encoding = {}

Lx[names].to_netcdf(outfile, mode='w', format='NETCDF4', compute=True)

def getColNames(vars_df, ds, remove_nan_fields=False):
Expand Down

0 comments on commit 48817e6

Please sign in to comment.