Пример #1
0
def func_data_consistency(ds_single):
    #    print(ds_single)
    #    mdo = CARDAMOMlib.load_mdo_greg(ds_single)
    #    abs_err, rel_err = mdo.check_data_consistency()

    abs_err, rel_err = CARDAMOMlib.check_data_consistency(
        ds_single, params["time_step_in_days"])
    data_vars = dict()
    data_vars['abs_err'] = xr.DataArray(
        data=abs_err.data.filled(fill_value=np.nan),
        attrs={'units': abs_err.unit}  # ignored by map_blocks
    )
    data_vars['rel_err'] = xr.DataArray(
        data=rel_err.data.filled(fill_value=np.nan),
        attrs={'units': rel_err.unit}  # ignored by map_blocks
    )

    ds_res = xr.Dataset(data_vars=data_vars)
    ds_single.close()

    return ds_res
        yearly_flux_variable = variable.isel(
            time=slice(delay_in_months, None, 1)
        ).shift(time=-1).coarsen(  # first u is useless in CARDAMOM and ELM
            time=nr_months,
            boundary="pad",
            coord_func="min",
            keep_attrs=True).mean().shift(
                time=1)  # unit is gC/m2/d, create useless first u again
        yearly_flux_variable.coords["time"] = yearly_coords_time
        data_vars[variable_name] = yearly_flux_variable

yearly_ds = xr.Dataset(data_vars=data_vars,
                       attrs={"delay_in_months": delay_in_months})
yearly_ds

# +
# %%time

print(target_path)
yearly_ds.to_netcdf(target_path, compute=True)
# -

check_ds = xr.open_dataset(target_path)
check_ds

#sub_ds = check_ds.isel(lat=9, lon=26, prob=0).compute()
sub_ds = check_ds.isel(lat=5, lon=23, prob=0).compute()  # bad reconstruction
sub_ds

CARDAMOMlib.check_data_consistency(sub_ds.compute(), time_step_in_days=31 * 12)