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
6 changes: 4 additions & 2 deletions hydromt/data_adapter/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,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 @@ -158,7 +160,7 @@ 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
Expand All @@ -171,7 +173,7 @@ def to_file(
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 @@ -162,7 +162,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 @@ -186,7 +186,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 @@ -178,7 +178,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 @@ -214,7 +214,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 @@ -175,6 +175,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 @@ -186,7 +188,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 @@ -224,7 +226,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 @@ -585,7 +585,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