Commit b177132a authored by Clément Haëck's avatar Clément Haëck
Browse files

Fix histogram computation

fix mix-up in masks

add some print statements

specify default proba mask threshold
parent bc874ca7
......@@ -42,7 +42,7 @@ VAR_RANGE = dict(
)
VARS = ['CHL', 'sst']
MASKS = ['low', 'mid', 'hi']
MASKS = ['frt', 'bkg']
MASKS_VAR = ['mask_' + m for m in MASKS]
INFILE_PARAMS = ['threshold', 'scale', 'number', 'coef']
......@@ -68,9 +68,8 @@ def main(args):
m_next("Computing HI masks")
# Masks
ds['mask_low'] = ds.HI < args['thr_lo']
ds['mask_mid'] = ds.HI > args['thr_lo'] * ds.HI < args['thr_hi']
ds['mask_hi'] = ds.HI > args['thr_hi']
ds['mask_frt'] = ds.HI > args['threshold']
ds['mask_bkg'] = ds.HI < args['threshold']
ds = ds.drop_vars(['HI'])
m_next("Computing zones datasets")
......@@ -87,7 +86,7 @@ def main(args):
up[mask] = up[mask] * op(ds.sst, ds.threshold)
zones['GS3_'+zone] = up
m_next("Setting up histogram computations")
print("Setting up histogram computations", end='', flush=True)
hists_var = []
for var in VARS:
hists = []
......@@ -95,6 +94,7 @@ def main(args):
bins_name = 'bins_' + var
for zone, zone_ds in zones.items():
for m, mask in zip(MASKS, MASKS_VAR):
print('.', end='', flush=True)
h = zone_ds[var].where(zone_ds[mask]).groupby('time').map(
hist_grp, shortcut=True, args=[bins, bins_name]
)
......@@ -151,7 +151,10 @@ def get_data(args):
args['grid'] = lib.data.ostia.grid
data.append(lib.zones.get_data(args).total)
data.append(lib.zones.get_land(args).land_large)
data.append(lib.data.p_frt_mask.get_data(args).rename(mask='p_frt'))
data.append(lib.data.p_frt_mask.get_data(
args, fixes=dict(
threshold=lib.data.p_frt.mask.default_threshold
)).rename(mask='p_frt'))
ds = xr.merge(data, join='inner')
......@@ -186,8 +189,7 @@ def get_bins(variable):
if __name__ == '__main__':
def add_args(parser):
parser.add_argument('-thr_lo', type=float, default=5.)
parser.add_argument('-thr_hi', type=float, default=10.)
parser.add_argument('-threshold', type=float, default=10.)
# Zone·s to compute
parser.add_argument('-zones', type=str, default='INS')
......
......@@ -45,7 +45,7 @@ VARS = ['CHL', 'sst']
MASKS = ['low', 'mid', 'hi']
MASKS_VAR = ['mask_' + m for m in MASKS]
INFILE_PARAMS = ['threshold', 'scale', 'number', 'coef']
INFILE_PARAMS = ['thr_lo', 'thr_hi', 'scale', 'number', 'coef']
def main(args):
......@@ -69,7 +69,7 @@ def main(args):
m_next("Computing HI masks")
# Masks
ds['mask_low'] = ds.HI < args['thr_lo']
ds['mask_mid'] = ds.HI > args['thr_lo'] * ds.HI < args['thr_hi']
ds['mask_mid'] = (ds.HI > args['thr_lo']) * (ds.HI < args['thr_hi'])
ds['mask_hi'] = ds.HI > args['thr_hi']
ds = ds.drop_vars(['HI'])
......@@ -87,7 +87,7 @@ def main(args):
up[mask] = up[mask] * op(ds.sst, ds.threshold)
zones['GS3_'+zone] = up
m_next("Setting up histogram computations")
print("Setting up histogram computations", end='', flush=True)
hists_var = []
for var in VARS:
hists = []
......@@ -95,6 +95,7 @@ def main(args):
bins_name = 'bins_' + var
for zone, zone_ds in zones.items():
for m, mask in zip(MASKS, MASKS_VAR):
print('.', end='', flush=True)
h = zone_ds[var].where(zone_ds[mask]).groupby('time').map(
hist_grp, shortcut=True, args=[bins, bins_name]
)
......@@ -153,7 +154,10 @@ def get_data(args):
args['grid'] = lib.data.ostia.grid
data.append(lib.zones.get_data(args).total)
data.append(lib.zones.get_land(args).land_large)
data.append(lib.data.p_frt_mask.get_data(args).rename(mask='p_frt'))
data.append(lib.data.p_frt_mask.get_data(
args, fixes=dict(
threshold=lib.data.p_frt_mask.default_threshold
)).rename(mask='p_frt'))
ds = xr.merge(data, join='inner')
......@@ -189,7 +193,8 @@ if __name__ == '__main__':
def add_args(parser):
# Frt/Bkg HI threshold
parser.add_argument('-threshold', type=float, default=5.)
parser.add_argument('-thr_lo', type=float, default=5.)
parser.add_argument('-thr_hi', type=float, default=10.)
# Zone·s to compute
parser.add_argument('-zones', type=str, default='INS')
......
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