Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
Add zero padding file naming.
Browse files Browse the repository at this point in the history
With this up to 99999 job result output files can be loaded automatically
with xr.open_mfdataset(paths="./results/out_*.nc",concat_dim="time",combine="nested")

Signed-off-by: sherrmann <sophie.herrmann@eodc.eu>
  • Loading branch information
sophieherrmann committed Aug 24, 2021
1 parent db3bd0b commit 49155a8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/openeo_processes/cubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ def refactor_data(data: xr.DataArray) -> List[xr.Dataset]:
def create_output_filepath(output_filepath: str, idx: int = 0, ext: str = "nc") -> str:
"""Create the output filepath."""
root, _ = splitext(output_filepath)
return f'{root}_{idx}.{ext}'
return f'{root}_{str(idx).zfill(5)}.{ext}'

# start workaround
# https://github.com/opendatacube/datacube-core/issues/972
Expand Down
12 changes: 6 additions & 6 deletions tests/test_cubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def test_save_result(self):
# TODO improve file check
# xarray tests
out_filename = "out.tif"
out_filename_0 = "out_0.tif"
out_filename_1 = "out_1.tif"
out_filename_0 = "out_00000.tif"
out_filename_1 = "out_00001.tif"
out_product = "product.yml"
oeop.save_result(self.test_data.xr_odc_data_3d, out_filename)
assert os.path.exists(out_filename_0)
Expand All @@ -74,8 +74,8 @@ def test_save_result(self):
os.remove(out_product)

out_filename = "out.nc"
out_filename_0 = "out_0.nc"
out_filename_1 = "out_1.nc"
out_filename_0 = "out_00000.nc"
out_filename_1 = "out_00001.nc"

oeop.save_result(self.test_data.xr_data_extra_dim, out_filename, format='netCDF', write_prod=False)
assert os.path.exists(out_filename_0)
Expand Down Expand Up @@ -107,14 +107,14 @@ def test_save_result_from_file(self):
ref_ds_0 = ref_ds.loc[dict(time="2016-01-13T12:00:00.000000000")]
data_array = ref_ds.to_array(dim="bands")
oeop.save_result(data_array, format='netCDF')
actual_ds_0 = xr.load_dataset("out_0.nc")
actual_ds_0 = xr.load_dataset("out_00000.nc")
assert ref_ds_0.dims == actual_ds_0.dims
assert ref_ds_0.coords == actual_ds_0.coords
assert ref_ds_0.variables == actual_ds_0.variables
assert ref_ds_0.geobox == actual_ds_0.geobox
assert ref_ds_0.extent == actual_ds_0.extent
for i in range(10):
os.remove(f"out_{i}.nc")
os.remove(f"out_{str(i).zfill(5)}.nc")
os.remove("product.yml")

def test_fit_curve(self):
Expand Down

0 comments on commit 49155a8

Please sign in to comment.