Skip to content

Commit

Permalink
Try to handle image_time and actual_image_time if they are available …
Browse files Browse the repository at this point in the history
…so that

they can be used in filenames
  • Loading branch information
joleenf committed Aug 10, 2023
1 parent 9ab454c commit f432480
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions satpy/readers/geocat.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import logging
import warnings
from datetime import datetime as datetime

import numpy as np
from pyproj import Proj
Expand Down Expand Up @@ -168,6 +169,10 @@ def _get_proj(self, platform, ref_lon):
ref_lon = -75.
return GEO_PROJS[platform].format(lon_0=ref_lon)

def _parse_time(self, datestr):
"""Parse a time string."""
return datetime.strptime(datestr, "%H%M%S")

@property
def sensor_names(self):
"""Get sensor names."""
Expand All @@ -183,6 +188,26 @@ def end_time(self):
"""Get end time."""
return self.filename_info.get('end_time', self.start_time)

@property
def image_time(self):
"""Get image time from global attributes if possible."""
image_time = self.get("/attr/Image_Time", None)
if image_time is not None:
image_time = self._parse_time(str(image_time))
else:
warnings.warn("WARNING: Image_Time not in global attributes", stacklevel=2)
return image_time

@property
def actual_image_time(self):
"""Get image time from global attributes if possible."""
actual_image_time = self.get("/attr/Actual_Image_Time", None)
if actual_image_time is not None:
actual_image_time = self._parse_time(str(actual_image_time))
else:
warnings.warn("WARNING: Actual_Image_Time not in global attributes", stacklevel=2)
return actual_image_time

@property
def is_geo(self):
"""Check platform."""
Expand Down Expand Up @@ -380,6 +405,11 @@ def get_metadata(self, dataset_id, ds_info):
elif var_name in ['pixel_latitude', 'pixel_latitude_tc']:
info['standard_name'] = 'latitude'

if self.image_time:
info["image_time"] = self.image_time
if self.actual_image_time:
info["actual_image_time"] = self.actual_image_time

return info

def _available_aliases(self, sensor, ds_info, current_var):
Expand Down

0 comments on commit f432480

Please sign in to comment.