Skip to content

Commit

Permalink
Update to save in datetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbieker committed Nov 16, 2021
1 parent 24c16c2 commit 3a99d5b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion satip/intermediate.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def create_or_update_zarr_with_native_files(
directory: str,
zarr_path: str,
hrv_zarr_path: str,
temp_directory: Path,
temp_directory: Path,
region: str,
spatial_chunk_size: int = 256,
temporal_chunk_size: int = 1,
Expand Down
9 changes: 4 additions & 5 deletions satip/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ def convert_scene_to_dataarray(scene: Scene, band: str, area: str) -> xr.DataArr
lon, lat = scene[band].attrs["area"].get_lonlats()
osgb_x, osgb_y = lat_lon_to_osgb(lat, lon)
dataset: xr.Dataset = scene.to_xarray_dataset()
# Add coordinate arrays, since x and y changes for each pixel, cannot replace dataset x,y coords with these directly
osgb_y = osgb_y[:,0]
osgb_x = osgb_x[0,:]
dataset = dataset.assign_coords(x=osgb_x,y=osgb_y)
Expand All @@ -185,9 +184,8 @@ def convert_scene_to_dataarray(scene: Scene, band: str, area: str) -> xr.DataArr

get_time_as_unix = (
lambda da: pd.Series(
(pd.to_datetime(da.time.values) - pd.Timestamp("1970-01-01")).total_seconds()
pd.to_datetime(da.time.values)
)
.astype(int)
.values
)

Expand All @@ -199,7 +197,7 @@ def save_dataset_to_zarr(
timesteps_per_chunk: int = 1,
y_size_per_chunk: int = 256,
x_size_per_chunk: int = 256,
channel_chunk_size: int = 12
channel_chunk_size: int = 12
) -> None:
"""
Save an Xarray DataArray into a Zarr file
Expand Down Expand Up @@ -247,7 +245,8 @@ def save_dataset_to_zarr(
"stacked_eumetsat_data": {
"compressor": zarr.Blosc(cname="zstd", clevel=5),
"chunks": chunks,
}
},
"time": {"units": "nanoseconds since 1970-01-01"},
}
},
}
Expand Down

0 comments on commit 3a99d5b

Please sign in to comment.