abby-baskind / seniorthesis

0 stars 2 forks source link

importing Bushinsky observations #20

Closed abby-baskind closed 2 years ago

abby-baskind commented 2 years ago

I was hoping I could import the Bushinsky observations using xarray: xr.open_dataset('MPI-SOM_FFN_SOCCOMv2018weighted_minus_4uatm_offset.nc'). I get this error:

---------------------------------------------------------------------------
MissingDimensionsError                    Traceback (most recent call last)
<ipython-input-3-0b3b379402e8> in <module>
----> 1 NOAA = xr.open_dataset('MPI-SOM_FFN_SOCCOMv2018weighted_minus_4uatm_offset.nc')

/srv/conda/envs/notebook/lib/python3.8/site-packages/xarray/backends/api.py in open_dataset(filename_or_obj, group, decode_cf, mask_and_scale, decode_times, concat_characters, decode_coords, engine, chunks, lock, cache, drop_variables, backend_kwargs, use_cftime, decode_timedelta)
    555 
    556     with close_on_error(store):
--> 557         ds = maybe_decode_store(store, chunks)
    558 
    559     # Ensure source filename always stored in dataset object (GH issue #2550)

/srv/conda/envs/notebook/lib/python3.8/site-packages/xarray/backends/api.py in maybe_decode_store(store, chunks)
    451 
    452     def maybe_decode_store(store, chunks):
--> 453         ds = conventions.decode_cf(
    454             store,
    455             mask_and_scale=mask_and_scale,

/srv/conda/envs/notebook/lib/python3.8/site-packages/xarray/conventions.py in decode_cf(obj, concat_characters, mask_and_scale, decode_times, decode_coords, drop_variables, use_cftime, decode_timedelta)
    655         decode_timedelta=decode_timedelta,
    656     )
--> 657     ds = Dataset(vars, attrs=attrs)
    658     ds = ds.set_coords(coord_names.union(extra_coords).intersection(vars))
    659     ds.set_close(close)

/srv/conda/envs/notebook/lib/python3.8/site-packages/xarray/core/dataset.py in __init__(self, data_vars, coords, attrs)
    685             coords = coords.variables
    686 
--> 687         variables, coord_names, dims, indexes, _ = merge_data_and_coords(
    688             data_vars, coords, compat="broadcast_equals"
    689         )

/srv/conda/envs/notebook/lib/python3.8/site-packages/xarray/core/merge.py in merge_data_and_coords(data, coords, compat, join)
    465     explicit_coords = coords.keys()
    466     indexes = dict(_extract_indexes_from_coords(coords))
--> 467     return merge_core(
    468         objects, compat, join, explicit_coords=explicit_coords, indexes=indexes
    469     )

/srv/conda/envs/notebook/lib/python3.8/site-packages/xarray/core/merge.py in merge_core(objects, compat, join, combine_attrs, priority_arg, explicit_coords, indexes, fill_value)
    611         coerced, join=join, copy=False, indexes=indexes, fill_value=fill_value
    612     )
--> 613     collected = collect_variables_and_indexes(aligned)
    614 
    615     prioritized = _get_priority_vars_and_indexes(aligned, priority_arg, compat=compat)

/srv/conda/envs/notebook/lib/python3.8/site-packages/xarray/core/merge.py in collect_variables_and_indexes(list_of_mappings)
    276                 append_all(coords, indexes)
    277 
--> 278             variable = as_variable(variable, name=name)
    279             if variable.dims == (name,):
    280                 variable = variable.to_index_variable()

/srv/conda/envs/notebook/lib/python3.8/site-packages/xarray/core/variable.py in as_variable(obj, name)
    164         # convert the Variable into an Index
    165         if obj.ndim != 1:
--> 166             raise MissingDimensionsError(
    167                 "%r has more than 1-dimension and the same name as one of its "
    168                 "dimensions %r. xarray disallows such variables because they "

MissingDimensionsError: 'date' has more than 1-dimension and the same name as one of its dimensions ('time', 'date'). xarray disallows such variables because they conflict with the coordinates used to label dimensions.

Is there another/better way to open this dataset?

gmacgilchrist commented 2 years ago

Ah yeah I think I cam across this issue too. See the first three cells here for an alternative loading procedure: https://github.com/gmacgilchrist/so_decadal_variability/blob/master/notebooks/dev_carbonflux.ipynb