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

Commit

Permalink
Ensure crs attr is always available in saved files.
Browse files Browse the repository at this point in the history
Signed-off-by: sherrmann <sophie.herrmann@eodc.eu>
  • Loading branch information
sophieherrmann committed Aug 26, 2021
1 parent 90c0977 commit 15a672d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/openeo_processes/cubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,9 @@ def extract_single_timestamp(data_without_time: xr.DataArray, timestamp: datetim
# This is a hack! ODC always(!) expectes to have a time dimension
# set datetime to now if no other information is available
tmp.attrs["datetime_from_dim"] = str(timestamp) if timestamp else str(datetime.now())
if "crs" not in tmp.attrs:
first_data_var = tmp.data_vars[list(tmp.data_vars.keys())[0]]
tmp.attrs["crs"] = first_data_var.geobox.crs.to_wkt()
return tmp

def refactor_data(data: xr.DataArray) -> List[xr.Dataset]:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_cubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def test_save_result_from_file(self):
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
assert "crs" in actual_ds_0.attrs and actual_ds_0.attrs["crs"] == 'PROJCRS["Azimuthal_Equidistant",BASEGEOGCRS["WGS 84",DATUM["World Geodetic System 1984",ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]],ID["EPSG",6326]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]]],CONVERSION["unnamed",METHOD["Modified Azimuthal Equidistant",ID["EPSG",9832]],PARAMETER["Latitude of natural origin",53,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8801]],PARAMETER["Longitude of natural origin",24,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8802]],PARAMETER["False easting",5837287.81977,LENGTHUNIT["metre",1],ID["EPSG",8806]],PARAMETER["False northing",2121415.69617,LENGTHUNIT["metre",1],ID["EPSG",8807]]],CS[Cartesian,2],AXIS["easting",east,ORDER[1],LENGTHUNIT["metre",1,ID["EPSG",9001]]],AXIS["northing",north,ORDER[2],LENGTHUNIT["metre",1,ID["EPSG",9001]]]]'
assert "datetime_from_dim" in actual_ds_0.attrs
for i in range(10):
os.remove(f"out_{str(i).zfill(5)}.nc")
os.remove("product.yml")
Expand Down

0 comments on commit 15a672d

Please sign in to comment.