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

return kwargs from adapter.to_file funtions #456

Merged
merged 10 commits into from
Aug 3, 2023
7 changes: 5 additions & 2 deletions hydromt/data_adapter/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ def to_file(
driver : str
Name of the driver used to read the data.
See :py:func:`~hydromt.data_catalog.DataCatalog.get_geodataset`.
kwargs: dict
The additional keyword arguments that were passed in.


"""
Expand All @@ -162,20 +164,21 @@ def to_file(
)
except IndexError as err: # out of bounds for time
logger.warning(str(err))
return None, None
return None, None, None

if driver is None or driver == "csv":
# always write as CSV
driver = "csv"
fn_out = join(data_root, f"{data_name}.csv")
obj.to_csv(fn_out, **kwargs)
kwargs["index_col"] = obj.index.name
savente93 marked this conversation as resolved.
Show resolved Hide resolved
elif driver == "excel":
fn_out = join(data_root, f"{data_name}.xlsx")
obj.to_excel(fn_out, **kwargs)
else:
raise ValueError(f"DataFrame: Driver {driver} is unknown.")

return fn_out, driver
return fn_out, driver, kwargs
savente93 marked this conversation as resolved.
Show resolved Hide resolved

def get_data(
self,
Expand Down
4 changes: 2 additions & 2 deletions hydromt/data_adapter/geodataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def to_file(
kwargs.pop("time_tuple", None)
gdf = self.get_data(bbox=bbox, variables=variables, logger=logger)
if gdf.index.size == 0:
return None, None
return None, None, None

if driver is None:
_lst = ["csv", "xls", "xlsx", "xy", "vector_table"]
Expand All @@ -190,7 +190,7 @@ def to_file(
gdf.to_file(fn_out, driver=driver, **kwargs)
driver = "vector"

return fn_out, driver
return fn_out, driver, kwargs

def get_data(
self,
Expand Down
4 changes: 2 additions & 2 deletions hydromt/data_adapter/geodataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def to_file(
single_var_as_array=variables is None,
)
if obj.vector.index.size == 0 or ("time" in obj.coords and obj.time.size == 0):
return None, None
return None, None, None

# much better for mem/storage/processing if dtypes are set correctly
for name, coord in obj.coords.items():
Expand Down Expand Up @@ -218,7 +218,7 @@ def to_file(
else:
raise ValueError(f"GeoDataset: Driver {driver} unknown.")

return fn_out, driver
return fn_out, driver, kwargs

def get_data(
self,
Expand Down
6 changes: 4 additions & 2 deletions hydromt/data_adapter/rasterdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ def to_file(
driver: str
Name of driver to read data with, see
:py:func:`~hydromt.data_catalog.DataCatalog.get_rasterdataset`
kwargs: dict
the additional kwyeord arguments that were passed to `to_netcdf`
"""
try:
obj = self.get_data(
Expand All @@ -190,7 +192,7 @@ def to_file(
)
except IndexError as err: # out of bounds
logger.warning(str(err))
return None, None
return None, None, None

if driver is None:
# by default write 2D raster data to GeoTiff and 3D raster data to netcdf
Expand Down Expand Up @@ -228,7 +230,7 @@ def to_file(
)
driver = "raster"

return fn_out, driver
return fn_out, driver, kwargs

def get_data(
self,
Expand Down
2 changes: 1 addition & 1 deletion hydromt/data_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ def export_data(
unit_add = source.unit_add
source.unit_mult = {}
source.unit_add = {}
fn_out, driver = source.to_file(
fn_out, driver, source_kwargs = source.to_file(
data_root=data_root,
data_name=key,
variables=source_vars.get(key, None),
Expand Down
2 changes: 1 addition & 1 deletion hydromt/stats/extremes.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ def get_lmom(x, nmom=4):
vector of (nmom) L-moments
"""
n = len(x)
xs = np.msort(x)
xs = np.sort(x, axis=0)
bb = np.zeros(nmom - 1)
ll = np.zeros(nmom - 1)
b0 = xs.mean(axis=0)
Expand Down
Loading