diff --git a/satpy/readers/avhrr_l1b_gaclac.py b/satpy/readers/avhrr_l1b_gaclac.py index 47f0d97283..34945ddb80 100644 --- a/satpy/readers/avhrr_l1b_gaclac.py +++ b/satpy/readers/avhrr_l1b_gaclac.py @@ -43,7 +43,7 @@ from pygac.lac_pod import LACPODReader from satpy.readers.file_handlers import BaseFileHandler -from satpy.utils import get_legacy_chunk_size +from satpy.utils import datetime64_to_pydatetime, get_legacy_chunk_size logger = logging.getLogger(__name__) @@ -185,8 +185,8 @@ def get_dataset(self, key, info): # Update start/end time using the actual scanline timestamps times = self.reader.get_times() - self._start_time = times[0].astype(dt.datetime) - self._end_time = times[-1].astype(dt.datetime) + self._start_time = datetime64_to_pydatetime(times[0]) + self._end_time = datetime64_to_pydatetime(times[-1]) # Select user-defined scanlines and/or strip invalid coordinates if (self.start_line is not None or self.end_line is not None @@ -224,8 +224,8 @@ def slice(self, data, times): # noqa: A003 """ sliced = self._slice(data) times = self._slice(times) - self._start_time = times[0].astype(dt.datetime) - self._end_time = times[-1].astype(dt.datetime) + self._start_time = datetime64_to_pydatetime(times[0]) + self._end_time = datetime64_to_pydatetime(times[-1]) return sliced, times def _slice(self, data): diff --git a/satpy/readers/gms/gms5_vissr_l1b.py b/satpy/readers/gms/gms5_vissr_l1b.py index 51f33d657a..7fb75c062b 100644 --- a/satpy/readers/gms/gms5_vissr_l1b.py +++ b/satpy/readers/gms/gms5_vissr_l1b.py @@ -164,7 +164,7 @@ from satpy.readers.file_handlers import BaseFileHandler from satpy.readers.hrit_jma import mjd2datetime64 from satpy.readers.utils import generic_open -from satpy.utils import get_legacy_chunk_size +from satpy.utils import datetime64_to_pydatetime, get_legacy_chunk_size CHUNK_SIZE = get_legacy_chunk_size() @@ -307,8 +307,7 @@ def _get_orbital_parameters(self): } def _get_time_parameters(self): - start_time = mjd2datetime64(self._mode_block["observation_time_mjd"]).astype("datetime64[us]") - start_time = start_time.astype(dt.datetime).replace(second=0, microsecond=0) + start_time = self._get_start_time() end_time = start_time + dt.timedelta( minutes=25 ) # Source: GMS User Guide, section 3.3.1 @@ -317,6 +316,11 @@ def _get_time_parameters(self): "nominal_end_time": end_time, } + def _get_start_time(self): + start_time = mjd2datetime64(self._mode_block["observation_time_mjd"]) + start_time = datetime64_to_pydatetime(start_time) + return start_time.replace(second=0, microsecond=0) + def get_dataset(self, dataset_id, ds_info): """Get dataset from file.""" image_data = self._get_image_data() diff --git a/satpy/readers/viirs_vgac_l1c_nc.py b/satpy/readers/viirs_vgac_l1c_nc.py index 2f43ffd2a2..116bd0e5c9 100644 --- a/satpy/readers/viirs_vgac_l1c_nc.py +++ b/satpy/readers/viirs_vgac_l1c_nc.py @@ -22,7 +22,7 @@ import xarray as xr from satpy.readers.file_handlers import BaseFileHandler -from satpy.utils import get_legacy_chunk_size +from satpy.utils import datetime64_to_pydatetime, get_legacy_chunk_size CHUNK_SIZE = get_legacy_chunk_size() logger = logging.getLogger(__name__) @@ -75,9 +75,7 @@ def set_time_attrs(self, data): def dt64_to_datetime(self, dt64): """Conversion of numpy.datetime64 to datetime objects.""" - if isinstance(dt64, np.datetime64): - return dt64.astype(dt.datetime) - return dt64 + return datetime64_to_pydatetime(dt64) def extract_time_data(self, data, nc): """Decode time data."""