Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions xdas/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import warnings
from functools import partial
import os

import h5netcdf
import h5py
Expand Down Expand Up @@ -904,6 +905,9 @@ def to_netcdf(self, fname, mode="w", group=None, virtual=None, encoding=None):
attrs = {} if self.attrs is None else self.attrs
attrs |= {"coordinate_interpolation": mapping} if mapping else attrs
name = "__values__" if self.name is None else self.name
if os.path.dirname(fname) is not "" and not os.path.exists(os.path.dirname(fname)):
os.makedirs(os.path.dirname(fname), exist_ok=True)

with h5netcdf.File(fname, mode=mode) as file:
if group is not None and group not in file:
file.create_group(group)
Expand Down
2 changes: 2 additions & 0 deletions xdas/core/datacollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ def to_netcdf(self, fname, mode="w", group=None, virtual=None, encoding=None):
location = "/".join([name, str(key)])
if group is not None:
location = "/".join([group, location])
if os.path.dirname(fname) is not "" and not os.path.exists(os.path.dirname(fname)):
os.makedirs(os.path.dirname(fname), exist_ok=True)
self[key].to_netcdf(
fname,
mode="a",
Expand Down