11 from dtocean
import dtocean
12 from dbocean
import dbocean
20 print (
"Reading sensor data: " + self.
ifile)
22 self.
rfl = np.append(xr.load_dataset(l1b_filepath,group=
'/reflectance')[
'toa_reflectance'][2:7,:,:],
23 xr.load_dataset(l1b_filepath,group=
'/reflectance')[
'toa_reflectance'][8:,:,:],axis=0)
24 self.
sza = xr.load_dataset(l1b_filepath,group=
'/geolocation')[
'solar_zenith'].values
25 self.
vza = xr.load_dataset(l1b_filepath,group=
'/geolocation')[
'sensor_zenith'].values
26 self.
raa = xr.load_dataset(l1b_filepath,group=
'/geolocation')[
'relative_azimuth'].values
27 self.
lat = xr.load_dataset(l1b_filepath,group=
'/navigation_data')[
'latitude'].values
28 self.
lon = xr.load_dataset(l1b_filepath,group=
'/navigation_data')[
'longitude'].values
29 self.
cld = xr.load_dataset(l1b_filepath,group=
'/ancillary')[
'cloud_mask'].values
30 self.
wnd = xr.load_dataset(l1b_filepath,group=
'/ancillary')[
'wind_speed'].values
31 self.
chl = xr.load_dataset(l1b_filepath,group=
'/ancillary')[
'chlorophyll'].values
32 self.
rfl = np.transpose(self.
rfl, (1,2,0))
34 except Exception
as inst:
37 print (
"Unable to read from file ... exiting")
47 rfl = xr.DataArray(np.zeros((NWL,ydim,xdim)),dims=(
'wl',
'y',
'x'))
48 lat = xr.DataArray(np.zeros((ydim,xdim)),dims=(
'y',
'x'))
49 lon = xr.DataArray(np.zeros((ydim,xdim)),dims=(
'y',
'x'))
50 sza = xr.DataArray(np.zeros((ydim,xdim)),dims=(
'y',
'x'))
51 vza = xr.DataArray(np.zeros((ydim,xdim)),dims=(
'y',
'x'))
52 raa = xr.DataArray(np.zeros((ydim,xdim)),dims=(
'y',
'x'))
53 wnd = xr.DataArray(np.zeros((ydim,xdim)),dims=(
'y',
'x'))
54 chl = xr.DataArray(np.zeros((ydim,xdim)),dims=(
'y',
'x'))
55 aot = xr.DataArray(np.zeros((ydim,xdim)),dims=(
'y',
'x'))
56 fmf = xr.DataArray(np.zeros((ydim,xdim)),dims=(
'y',
'x'))
57 sse = xr.DataArray(np.zeros((ydim,xdim)),dims=(
'y',
'x'))
58 self.
ds = xr.Dataset({
'rfl': rfl,
'lat': lat,
'lon': lon,
59 'sza': sza,
'vza': vza,
'raa': raa,
60 'wnd': wnd,
'chl': chl,
'aot': aot,
61 'fmf': fmf,
'sse': sse, })
62 except Exception
as inst:
65 print (
"Unable to initialize output file ... exiting")
69 print (
"Writing to file: " + self.
ofile)
74 parser = argparse.ArgumentParser()
75 parser.add_argument(
"-af",
"--alg",
76 help=
"algorithm name", required=
True)
77 parser.add_argument(
"-if",
"--ifile", type=argparse.FileType(
'r'),
78 help=
"input file", required=
True)
79 parser.add_argument(
"-of",
"--ofile", type=argparse.FileType(
'w'),
80 help=
"output file", required=
False)
81 parser.add_argument(
"-lf",
"--lut", type=argparse.FileType(
'r'),
82 help=
"lookup table file", required=
True)
83 parser.add_argument(
"-pf",
"--plot", type=bool, default=
False,
84 help=
"plot pixel data", required=
False)
85 parser.add_argument(
"-mf",
"--mode", type=int, default=0,
86 help=
"mode option", required=
False)
87 parser.add_argument(
"y", type=int, help=
"start line")
88 parser.add_argument(
"x", type=int, help=
"start pixel")
89 parser.add_argument(
"z", type=int, help=
"square side ")
91 args = parser.parse_args()
92 vin =
input(args.ifile.name)
99 vout =
output(args.ofile.name, dimy, dimx)
101 if (args.alg ==
"deepblue"):
102 dtdb =
dbocean(args.lut.name, args.mode)
103 elif (args.alg ==
"darktarget"):
104 dtdb =
dtocean(args.lut.name, args.mode)
106 print (
"invalid algorithm")
109 print (
"Processing mode {0}".format(args.mode))
110 for iy
in range(args.y, args.y+dimy):
111 tic = time.perf_counter()
113 for ix
in range(args.x, args.x+dimx):
115 if(vin.cld[iy,ix]
or vin.chl[iy,ix]<-999):
116 fmf,aot,chl,wnd,sse = -999.9, -999.9, -999.9, -999.9, -999.9
119 fmf,aot,chl,wnd,sse = dtdb.process(vin.rfl[iy,ix],vin.sza[iy,ix],
120 vin.vza[iy,ix],vin.raa[iy,ix],
121 vin.wnd[iy,ix],vin.chl[iy,ix])
122 except Exception
as inst:
125 print (
"processing error at pixel", iy, ix)
130 vout.ds.rfl[:,iy-args.y,ix-args.x] = vin.rfl[iy,ix]
131 vout.ds.lat[iy-args.y,ix-args.x] = vin.lat[iy,ix]
132 vout.ds.lon[iy-args.y,ix-args.x] = vin.lon[iy,ix]
133 vout.ds.sza[iy-args.y,ix-args.x] = vin.sza[iy,ix]
134 vout.ds.vza[iy-args.y,ix-args.x] = vin.vza[iy,ix]
135 vout.ds.raa[iy-args.y,ix-args.x] = vin.raa[iy,ix]
136 vout.ds.wnd[iy-args.y,ix-args.x] = wnd
137 vout.ds.chl[iy-args.y,ix-args.x] = chl
138 vout.ds.aot[iy-args.y,ix-args.x] = aot
139 vout.ds.fmf[iy-args.y,ix-args.x] = fmf
140 vout.ds.sse[iy-args.y,ix-args.x] = sse
142 toc = time.perf_counter()
145 print(iy, tpp, flush=
True)
149 if __name__ ==
"__main__":