generated from openclimatefix/ocf-template
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf5578f
commit 219c06d
Showing
2 changed files
with
19 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
"""Convert Satellite to NumpyBatch""" | ||
import xarray as xr | ||
|
||
from ocf_datapipes.batch import BatchKey, NumpyBatch | ||
|
||
class SatelliteBatchKey: | ||
|
||
def convert_satellite_to_numpy_batch(da: xr.DataArray, t0_idx: int | None = None) -> NumpyBatch: | ||
satellite_actual = 'satellite_actual' | ||
satellite_time_utc = 'satellite_time_utc' | ||
satellite_x_geostationary = 'satellite_x_geostationary' | ||
satellite_y_geostationary = 'satellite_y_geostationary' | ||
satellite_t0_idx = 'satellite_t0_idx' | ||
|
||
|
||
def convert_satellite_to_numpy_batch(da: xr.DataArray, t0_idx: int | None = None) -> dict: | ||
"""Convert from Xarray to NumpyBatch""" | ||
example: NumpyBatch = { | ||
BatchKey.satellite_actual: da.values, | ||
BatchKey.satellite_time_utc: da.time_utc.values.astype(float), | ||
example = { | ||
SatelliteBatchKey.satellite_actual: da.values, | ||
SatelliteBatchKey.satellite_time_utc: da.time_utc.values.astype(float), | ||
} | ||
|
||
for batch_key, dataset_key in ( | ||
(BatchKey.satellite_x_geostationary, "x_geostationary"), | ||
(BatchKey.satellite_y_geostationary, "y_geostationary"), | ||
(SatelliteBatchKey.satellite_x_geostationary, "x_geostationary"), | ||
(SatelliteBatchKey.satellite_y_geostationary, "y_geostationary"), | ||
): | ||
example[batch_key] = da[dataset_key].values | ||
|
||
if t0_idx is not None: | ||
example[BatchKey.satellite_t0_idx] = t0_idx | ||
example[SatelliteBatchKey.satellite_t0_idx] = t0_idx | ||
|
||
return example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters