@@ -191,7 +191,7 @@ def save_hdf5_file(hdf5_obj, output_hdf5_file, clip_max,
191191 del hdf5_obj [h5_ds ]
192192 pol_list_s2 = np .array (pol_list , dtype = 'S2' )
193193 dset = hdf5_obj .create_dataset (h5_ds , data = pol_list_s2 )
194- dset .attrs ['description' ] = np .string_ (
194+ dset .attrs ['description' ] = np .bytes_ (
195195 'List of processed polarization layers' )
196196
197197 # save geogrid coordinates
@@ -294,21 +294,21 @@ def create_hdf5_file(product_id, output_hdf5_file, orbit, burst, cfg,
294294 '''
295295
296296 hdf5_obj = h5py .File (output_hdf5_file , 'w' )
297- hdf5_obj .attrs ['Conventions' ] = np .string_ ("CF-1.8" )
298- hdf5_obj .
attrs [
"contact" ]
= np .
string_ (
"[email protected] " )
299- hdf5_obj .attrs ["institution" ] = np .string_ ("NASA JPL" )
300- hdf5_obj .attrs ["project" ] = np .string_ ("OPERA" )
301- hdf5_obj .attrs ["reference_document" ] = np .string_ (
297+ hdf5_obj .attrs ['Conventions' ] = np .bytes_ ("CF-1.8" )
298+ hdf5_obj .
attrs [
"contact" ]
= np .
bytes_ (
"[email protected] " )
299+ hdf5_obj .attrs ["institution" ] = np .bytes_ ("NASA JPL" )
300+ hdf5_obj .attrs ["project" ] = np .bytes_ ("OPERA" )
301+ hdf5_obj .attrs ["reference_document" ] = np .bytes_ (
302302 "Product Specification Document for the OPERA Radiometric"
303303 " Terrain-Corrected SAR Backscatter from Sentinel-1,"
304304 " JPL D-108758, Rev. Working Version 1, Aug 31, 2023" )
305305
306306 # product type
307307 product_type = cfg .groups .primary_executable .product_type
308308 if product_type == STATIC_LAYERS_PRODUCT_TYPE :
309- hdf5_obj .attrs ["title" ] = np .string_ ("OPERA RTC-S1-STATIC Product" )
309+ hdf5_obj .attrs ["title" ] = np .bytes_ ("OPERA RTC-S1-STATIC Product" )
310310 else :
311- hdf5_obj .attrs ["title" ] = np .string_ ("OPERA RTC-S1 Product" )
311+ hdf5_obj .attrs ["title" ] = np .bytes_ ("OPERA RTC-S1 Product" )
312312
313313 populate_metadata_group (product_id , hdf5_obj , burst , cfg ,
314314 processing_datetime , is_mosaic )
@@ -320,23 +320,44 @@ def create_hdf5_file(product_id, output_hdf5_file, orbit, burst, cfg,
320320
321321
322322def save_orbit (orbit , orbit_group , orbit_file_path ):
323+
324+ # ensure that the orbit reference epoch has not fractional part
325+ # otherwise, trancate it to seconds precision
326+ orbit_reference_epoch = orbit .reference_epoch
327+ if orbit_reference_epoch .frac != 0 :
328+ logger .warning ('the orbit reference epoch is not an'
329+ ' integer number. Truncating it'
330+ ' to seconds precision and'
331+ ' updating the orbit ephemeris'
332+ ' accordingly.' )
333+
334+ epoch = isce3 .core .DateTime (orbit_reference_epoch .year ,
335+ orbit_reference_epoch .month ,
336+ orbit_reference_epoch .day ,
337+ orbit_reference_epoch .hour ,
338+ orbit_reference_epoch .minute ,
339+ orbit_reference_epoch .second )
340+
341+ orbit .update_reference_epoch (epoch )
342+
323343 orbit .save_to_h5 (orbit_group )
344+
324345 # Add description attributes.
325- orbit_group ["time" ].attrs ["description" ] = np .string_ (
346+ orbit_group ["time" ].attrs ["description" ] = np .bytes_ (
326347 "Time vector record. This"
327348 " record contains the time corresponding to position, velocity,"
328349 " acceleration records" )
329- orbit_group ["position" ].attrs ["description" ] = np .string_ (
350+ orbit_group ["position" ].attrs ["description" ] = np .bytes_ (
330351 "Position vector"
331352 " record. This record contains the platform position data with"
332353 " respect to WGS84 G1762 reference frame" )
333- orbit_group ["velocity" ].attrs ["description" ] = np .string_ (
354+ orbit_group ["velocity" ].attrs ["description" ] = np .bytes_ (
334355 "Velocity vector"
335356 " record. This record contains the platform velocity data with"
336357 " respect to WGS84 G1762 reference frame" )
337358 orbit_group .create_dataset (
338359 'referenceEpoch' ,
339- data = np .string_ (orbit .reference_epoch .isoformat ()))
360+ data = np .bytes_ (orbit .reference_epoch .isoformat ()))
340361
341362 # Orbit source/type
342363 orbit_type = 'Undefined'
@@ -359,9 +380,12 @@ def save_orbit(orbit, orbit_group, orbit_file_path):
359380 orbit_type_list .append (orbit_type_individual )
360381 orbit_type = '; ' .join (orbit_type_list )
361382
362- d = orbit_group .require_dataset ("orbitType" , (), "S64" ,
363- data = np .string_ (orbit_type ))
364- d .attrs ["description" ] = np .string_ (
383+ if 'orbitType' in orbit_group :
384+ del orbit_group ['orbitType' ]
385+ d = orbit_group .create_dataset ("orbitType" ,
386+ data = np .bytes_ (orbit_type ))
387+
388+ d .attrs ["description" ] = np .bytes_ (
365389 "Type of orbit file used in processing" )
366390
367391
@@ -1296,11 +1320,11 @@ def populate_metadata_group(product_id: str,
12961320 continue
12971321 if isinstance (data , str ):
12981322 dset = h5py_obj .create_dataset (
1299- path_dataset_in_h5 , data = np .string_ (data ))
1323+ path_dataset_in_h5 , data = np .bytes_ (data ))
13001324 else :
13011325 dset = h5py_obj .create_dataset (path_dataset_in_h5 , data = data )
13021326
1303- dset .attrs ['description' ] = np .string_ (description )
1327+ dset .attrs ['description' ] = np .bytes_ (description )
13041328
13051329
13061330def save_hdf5_dataset (ds_filename , h5py_obj , root_path ,
@@ -1341,7 +1365,11 @@ def save_hdf5_dataset(ds_filename, h5py_obj, root_path,
13411365 logger .warning (f'WARNING Cannot open raster file: { ds_filename } ' )
13421366 return
13431367
1344- ds_name = layer_hdf5_dict [layer_name ]
1368+ if isinstance (layer_name , str ):
1369+ ds_name = layer_hdf5_dict [layer_name ]
1370+ else :
1371+ ds_name = [layer_hdf5_dict [l ] for l in layer_name ]
1372+
13451373 if long_name is not None :
13461374 description = long_name
13471375 else :
@@ -1377,25 +1405,27 @@ def save_hdf5_dataset(ds_filename, h5py_obj, root_path,
13771405 dset = h5py_obj .create_dataset (h5_ds , data = data )
13781406 dset .dims [0 ].attach_scale (yds )
13791407 dset .dims [1 ].attach_scale (xds )
1380- dset .attrs ['grid_mapping' ] = np .string_ ("projection" )
1408+ dset .attrs ['grid_mapping' ] = np .bytes_ ("projection" )
13811409
13821410 if standard_name is not None :
1383- dset .attrs ['standard_name' ] = np .string_ (standard_name )
1411+ dset .attrs ['standard_name' ] = np .bytes_ (standard_name )
13841412
13851413 if long_name is not None :
1386- dset .attrs ['long_name' ] = np .string_ (long_name )
1414+ dset .attrs ['long_name' ] = np .bytes_ (long_name )
13871415
1388- dset .attrs ['description' ] = np .string_ (description )
1416+ dset .attrs ['description' ] = np .bytes_ (description )
13891417
13901418 if units is not None :
1391- dset .attrs ['units' ] = np .string_ (units )
1419+ dset .attrs ['units' ] = np .bytes_ (units )
13921420
13931421 if fill_value is not None :
13941422 dset .attrs .create ('_FillValue' , data = fill_value )
13951423 elif 'cfloat' in gdal .GetDataTypeName (raster .datatype ()).lower ():
13961424 dset .attrs .create ('_FillValue' , data = np .nan + 1j * np .nan )
13971425 elif 'float' in gdal .GetDataTypeName (raster .datatype ()).lower ():
13981426 dset .attrs .create ('_FillValue' , data = np .nan )
1427+ elif 'byte' in gdal .GetDataTypeName (raster .datatype ()).lower ():
1428+ dset .attrs .create ('_FillValue' , data = 255 )
13991429
14001430 if stats_vector is not None :
14011431 stats_obj = stats_vector [band ]
0 commit comments