|
49 | 49 |
|
50 | 50 |
|
51 | 51 | try:
|
52 |
| - import pyproj |
53 | 52 | import cartopy.crs
|
| 53 | + import pyproj |
54 | 54 | except ImportError:
|
55 | 55 | pyproj = None
|
56 | 56 |
|
@@ -2756,14 +2756,16 @@ def grid_mapping_names(self) -> dict[str, list[str]]:
|
2756 | 2756 | def crs(self):
|
2757 | 2757 | """Cartopy CRS of the dataset's grid mapping."""
|
2758 | 2758 | if pyproj is None:
|
2759 |
| - raise ImportError('`crs` accessor requires optional packages `pyproj` and `cartopy`.') |
| 2759 | + raise ImportError( |
| 2760 | + "`crs` accessor requires optional packages `pyproj` and `cartopy`." |
| 2761 | + ) |
2760 | 2762 | gmaps = list(itertools.chain(*self.grid_mapping_names.values()))
|
2761 | 2763 | if len(gmaps) > 1:
|
2762 | 2764 | raise ValueError("Multiple grid mappings found.")
|
2763 | 2765 | if len(gmaps) == 0:
|
2764 |
| - if 'longitude' in self: |
| 2766 | + if "longitude" in self: |
2765 | 2767 | return cartopy.crs.PlateCarree()
|
2766 |
| - raise ValueError('No grid mapping nor longitude found in dataset.') |
| 2768 | + raise ValueError("No grid mapping nor longitude found in dataset.") |
2767 | 2769 | return cartopy.crs.Projection(pyproj.CRS.from_cf(self._obj[gmaps[0]].attrs))
|
2768 | 2770 |
|
2769 | 2771 | def decode_vertical_coords(
|
@@ -2962,13 +2964,15 @@ def grid_mapping_name(self) -> str:
|
2962 | 2964 | def crs(self):
|
2963 | 2965 | """Cartopy CRS of the dataset's grid mapping."""
|
2964 | 2966 | if pyproj is None:
|
2965 |
| - raise ImportError('`crs` accessor requires optional packages `pyproj` and `cartopy`.') |
| 2967 | + raise ImportError( |
| 2968 | + "`crs` accessor requires optional packages `pyproj` and `cartopy`." |
| 2969 | + ) |
2966 | 2970 |
|
2967 | 2971 | grid_mapping_var = self._get_grid_mapping(ignore_missing=True)
|
2968 | 2972 | if grid_mapping_var is None:
|
2969 |
| - if 'longitude' in self: |
| 2973 | + if "longitude" in self: |
2970 | 2974 | return cartopy.crs.PlateCarree()
|
2971 |
| - raise ValueError('No grid mapping nor longitude found.') |
| 2975 | + raise ValueError("No grid mapping nor longitude found.") |
2972 | 2976 | return cartopy.crs.Projection(pyproj.CRS.from_cf(grid_mapping_var.attrs))
|
2973 | 2977 |
|
2974 | 2978 | def __getitem__(self, key: Hashable | Iterable[Hashable]) -> DataArray:
|
|
0 commit comments