Commit 3625f479 authored by Niklas Bohn's avatar Niklas Bohn
Browse files

Soft coded fill values and data ranges

parent 1ce160bf
Pipeline #2657 passed with stages
in 15 minutes and 7 seconds
......@@ -613,7 +613,8 @@ def json_to_netcdf(out_mode, api_result, outpath, out_prefix, geo_ll, geo_ur, st
band_group.createDimension('x', band_arr.shape[2])
band_group.createDimension('y', band_arr.shape[1])
band_group.createDimension('t', band_arr.shape[0])
data = band_group.createVariable('Data', 'i4', ('x', 'y', 't'), fill_value=255)
fill = api_result[key][tile][band]['fill_value']
data = band_group.createVariable('Data', 'i4', ('x', 'y', 't'), fill_value=fill)
data.units = "None"
if level == "L1C":
data.long_name = "Top of Atmosphere Reflectance"
......@@ -621,13 +622,12 @@ def json_to_netcdf(out_mode, api_result, outpath, out_prefix, geo_ll, geo_ur, st
else:
data.long_name = "Surface Reflectance"
data.standard_name = "boa_reflectance"
data.valid_range = np.array((-2000.0, 16000.0))
data.actual_range = np.array((np.min(band_arr), np.max(band_arr)))
masked_fill = np.ma.masked_equal(band_arr, fill)
data.data_range = np.array((np.min(masked_fill), np.max(masked_fill)))
data[:, :, :] = band_arr
band_group.Band = band.split("_")[0].split("B")[-1]
band_group.Resolution = band.split("_")[-1]
band_group.Central_Wavelength = wl[str(band.split("_")[0])]
if key == 'Metadata':
key_group = f.createGroup(key)
for tile in api_result[key].keys():
......@@ -664,15 +664,16 @@ def json_to_netcdf(out_mode, api_result, outpath, out_prefix, geo_ll, geo_ur, st
mask_group.createDimension('x', mask_arr.shape[2])
mask_group.createDimension('y', mask_arr.shape[1])
mask_group.createDimension('t', mask_arr.shape[0])
data = mask_group.createVariable('Data', 'i4', ('x', 'y', 't'), fill_value=255)
fill = api_result[key][tile][msk]['fill_value']
data = mask_group.createVariable('Data', 'i4', ('x', 'y', 't'), fill_value=fill)
data.units = "None"
data.long_name = "Mask classes"
data.standard_name = "classes"
data.valid_range = np.array((10.0, 60.0))
data.actual_range = np.array((np.min(mask_arr), np.max(mask_arr)))
masked_fill = np.ma.masked_equal(mask_arr, fill)
data.data_range = np.array((np.min(masked_fill), np.max(masked_fill)))
data[:, :, :] = mask_arr
f.close()
except:
except Exception:
raise Exception("Something went wrong while saving as netcdf. " + traceback.format_exc())
......
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