<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def from_netcdf(filename):
 """Initialize object from a netcdf file. Expects that the file will have groups, each of which can be loaded by xarray. Parameters filename : str location of netcdf file Returns ------- InferenceData object """

        groups = {}
        with nc.Dataset(filename, mode="r") as data:
            data_groups = list(data.groups)

        for group in data_groups:
            with xr.open_dataset(filename, group=group) as data:
                groups[group] = data
        return InferenceData(**groups)