Skip to content

parse_cf() DimensionalityError on GOES data #1887

@lsterzinger

Description

@lsterzinger

I'm trying to use parse_cf() on GOES-16 SST data so I can use cartopy to plot coastlines etc. I'm pulling my GOES-16 data from the AWS S3 bucket and running the code on the Pangeo cloud.

import s3fs
import xarray as xr
import matplotlib.pyplot as plt
import metpy

fs = s3fs.S3FileSystem(anon=True)
f = fs.open("s3://noaa-goes16/ABI-L2-SSTF/2021/001/00/OR_ABI-L2-SSTF-M6_G16_s20210010000209_e20210010059517_c20210010105389.nc")

ds = xr.open_dataset(f)
ds.metpy.parse_cf()

This last command yields the following stacktrace

---------------------------------------------------------------------------
DimensionalityError                       Traceback (most recent call last)
/srv/conda/envs/notebook/lib/python3.8/site-packages/metpy/xarray.py in _rebuild_coords(self, var, crs)
    774                 try:
--> 775                     var = var.metpy.convert_coordinate_units(coord_name, 'meters')
    776                 except DimensionalityError:

/srv/conda/envs/notebook/lib/python3.8/site-packages/metpy/xarray.py in convert_coordinate_units(self, coord, units)
    189         new_coord_var = self._data_array[coord].copy(
--> 190             data=self._data_array[coord].metpy.unit_array.m_as(units)
    191         )

/srv/conda/envs/notebook/lib/python3.8/site-packages/pint/quantity.py in m_as(self, units)
    455         """
--> 456         return self.to(units).magnitude
    457 

/srv/conda/envs/notebook/lib/python3.8/site-packages/pint/quantity.py in to(self, other, *contexts, **ctx_kwargs)
    660 
--> 661         magnitude = self._convert_magnitude_not_inplace(other, *contexts, **ctx_kwargs)
    662 

/srv/conda/envs/notebook/lib/python3.8/site-packages/pint/quantity.py in _convert_magnitude_not_inplace(self, other, *contexts, **ctx_kwargs)
    609 
--> 610         return self._REGISTRY.convert(self._magnitude, self._units, other)
    611 

/srv/conda/envs/notebook/lib/python3.8/site-packages/pint/registry.py in convert(self, value, src, dst, inplace)
    953 
--> 954         return self._convert(value, src, dst, inplace)
    955 

/srv/conda/envs/notebook/lib/python3.8/site-packages/pint/registry.py in _convert(self, value, src, dst, inplace)
   1839 
-> 1840         return super()._convert(value, src, dst, inplace)
   1841 

/srv/conda/envs/notebook/lib/python3.8/site-packages/pint/registry.py in _convert(self, value, src, dst, inplace)
   1441         if not (src_offset_unit or dst_offset_unit):
-> 1442             return super()._convert(value, src, dst, inplace)
   1443 

/srv/conda/envs/notebook/lib/python3.8/site-packages/pint/registry.py in _convert(self, value, src, dst, inplace, check_dimensionality)
    986             if src_dim != dst_dim:
--> 987                 raise DimensionalityError(src, dst, src_dim, dst_dim)
    988 

DimensionalityError: Cannot convert from 'radian' (dimensionless) to 'meter' ([length])

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-8-3bf924c09a98> in <module>
----> 1 ds.metpy.parse_cf('SST')

/srv/conda/envs/notebook/lib/python3.8/site-packages/metpy/xarray.py in parse_cf(self, varname, coordinates)
    762 
    763         # Rebuild the coordinates of the dataarray, and return quantified DataArray
--> 764         var = self._rebuild_coords(var, crs)
    765         if crs is not None:
    766             var = var.assign_coords(coords={'metpy_crs': crs})

/srv/conda/envs/notebook/lib/python3.8/site-packages/metpy/xarray.py in _rebuild_coords(self, var, crs)
    778                     if crs is not None:
    779                         height = crs['perspective_point_height']
--> 780                         new_coord_var = coord_var.copy(
    781                             data=(
    782                                 coord_var.metpy.unit_array

/srv/conda/envs/notebook/lib/python3.8/site-packages/xarray/core/dataarray.py in copy(self, deep, data)
    981         pandas.DataFrame.copy
    982         """
--> 983         variable = self.variable.copy(deep=deep, data=data)
    984         coords = {k: v.copy(deep=deep) for k, v in self._coords.items()}
    985         if self._indexes is None:

/srv/conda/envs/notebook/lib/python3.8/site-packages/xarray/core/variable.py in copy(self, deep, data)
    942             data = as_compatible_data(data)
    943             if self.shape != data.shape:
--> 944                 raise ValueError(
    945                     "Data shape {} must match shape of object {}".format(
    946                         data.shape, self.shape

ValueError: Data shape (1,) must match shape of object ()

This seems to be a similar issue to that described here Unidata/python-training#94
But the fix that was implemented doesn't seem to fix my issue.

I'm running the following versions:

  • Python 3.8.6
  • s3fs 0.5.2
  • metpy 1.0
  • xarray 0.16.2

While package versions are controlled by Pangeo across all user instances, I did try with xarray 0.18.2 and the issue persists.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugSomething is not working like it should

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions