Commit faaa5d5a authored by RKGarcia's avatar RKGarcia
Browse files

environment and region parameter optionals on hcast2scmi

parent 0c3cb167
......@@ -411,7 +411,8 @@ def scmi_filename(
tile=None, # 001..### upper left to lower right
satellite='H8', # 16, 17, ... H8
scene_time=None, # datetime object
creation_time=None): # now, datetime object
creation_time=None, # now, datetime object
**kwargs):
scene_time = scene_time.strftime('%Y%j%H%M%S')
if creation_time is None:
creation_time = datetime.utcnow()
......@@ -480,18 +481,20 @@ class AttributeHelper(object):
"""
helper object which wraps around a HimawariScene to provide SCMI attributes
"""
additional_naming_info = {}
tile_count = (0,0) # ny, nx
hsd = None
offset = (0,0) # ty, tx tile number
tile_shape = (0,0) # wy, wx height and width of tile in pixels
scene_shape = (0,0) # sy, sx height and width of scene in pixels
def __init__(self, hsd, offset, tile_count, scene_shape):
def __init__(self, hsd, offset, tile_count, scene_shape, **naming_info):
self.hsd = hsd
self.offset = offset
self.tile_count = tile_count
self.scene_shape = scene_shape
self.tile_shape = (int(scene_shape[0] / tile_count[0]), int(scene_shape[1] / tile_count[1]))
self.additional_naming_info = naming_info
if (scene_shape[0] % tile_count[0] != 0) or (scene_shape[1] % tile_count[1] != 0):
raise ValueError('tile shape %r does not fit evenly into scene shape %r' % (self.tile_shape, scene_shape))
......@@ -536,10 +539,10 @@ class AttributeHelper(object):
return self.offset[0] * self.tile_count[1] + self.offset[1] + 1
def _filename(self):
return scmi_filename(channel=self.hsd.metadata.band, scene_time=self._scene_time(), tile=self._tile_number())
return scmi_filename(channel=self.hsd.metadata.band, scene_time=self._scene_time(), tile=self._tile_number(), **self.additional_naming_info)
def _product_name(self):
return scmi_product(channel=self.hsd.metadata.band, scene_time=self._scene_time())
return scmi_product(channel=self.hsd.metadata.band, scene_time=self._scene_time(), **self.additional_naming_info)
def _global_product_tile_height(self): # = None, # 1100,
return self.tile_shape[0]
......@@ -903,7 +906,8 @@ def hsd2scmi(scene, filename=None, include_rad=False,
include_geo=False, include_fgf=True,
downsample_factor=0, downsample_to_band=0,
stride=0, nav_scene=None,
offset=None, shape=None, tile_count=(1,1)):
offset=None, shape=None, tile_count=(1,1),
**naming_info):
"""convey content of scene to writer object
"""
if isinstance(scene, str):
......@@ -954,7 +958,7 @@ def hsd2scmi(scene, filename=None, include_rad=False,
for tx in range(tile_count[1]):
LOG.info('building tile ({},{})'.format(ty,tx))
tile_offset = (ty, tx)
helper = AttributeHelper(scene, tile_offset, tile_count, shape)
helper = AttributeHelper(scene, tile_offset, tile_count, shape, **naming_info)
tile_shape = helper.tile_shape
filename = filename if (filename and tile_count==1) else helper._filename()
nc = SCMI_writer(filename, resolution, offset, tile_shape, scene.kind, scene.band,
......@@ -1120,6 +1124,9 @@ def main():
help='factor to stride by, typically 1, 2 or 4')
parser.add_argument('-t', '--tiles', dest='tiles', default='1',
help='number of tiles to create in each dimension, or y,x tile count pair')
parser.add_argument('-R', '--region', help='region tag to use in filename, e.g. HFD', default='HFD')
parser.add_argument('-E', '--environment', default='DT',
help='environment and data type to use in filename, e.g. DT or OR')
parser.add_argument('--debug', dest='debug', action='store_true',
help="enable interactive PDB debugger on exception")
# FUTURE: include a resolution tag for 2km/1km/0p5km
......@@ -1141,10 +1148,17 @@ def main():
# unittest.main()
# return 0
try:
environment, data_type = args.environment
except ValueError:
LOG.error('environment parameter requires two characters')
return 1
if args.pos_args:
fns = list(hsd2scmi(*args.pos_args, downsample_factor=args.factor, stride=args.stride,
include_geo=args.geolocation, include_fgf=True, include_rad=False,
tile_count=_parse_tile_count(args.tiles), nav_scene=attach_nav(args.nav_donor)))
tile_count=_parse_tile_count(args.tiles), nav_scene=attach_nav(args.nav_donor),
environment=environment, data_type=data_type, region=args.region))
for fn in fns:
print("> " + fn)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment