Closed claalmve closed 2 months ago
Getting this error on the WL example in the notebook - I don't think this is tied to this PR??
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In [7], line 1
----> 1 data = cava_data(
2 ## Set-up
3 example_locs.iloc[:1],
4 downscaling_method="Dynamical", # default for now
5 approach="warming_level",
6 warming_level="2.0",
7
8 ## Likely seaonal event specific arguments
9 variable="Air Temperature at 2m",
10 metric_calc="max", # daily high temperature
11 percentile=60, # likeliness percentile
12 season="winter", # season
13 units="degC", # change units
14
15 ## Export
16 export_method="both",
17 file_format="NetCDF",
18 )
File ~/src/climakitae/climakitae/explore/vulnerability.py:516, in cava_data(input_locations, variable, approach, downscaling_method, time_start_year, time_end_year, historical_data, ssp_data, warming_level, metric_calc, heat_idx_threshold, one_in_x, percentile, season, units, wrf_bc, export_method, separate_files, file_format)
499 data = data.sel(
500 simulation=[
501 sim
(...)
512 ]
513 )
515 # Find the closest gridcell from the data to the lat/lon point
--> 516 closest_cell = get_closest_gridcell(data, lat, lon, print_coords=False).squeeze(
517 dim="scenario"
518 )
520 # Storing data differently if all data points should be in one file vs each data point in its own file
521 if not separate_files:
522 # Renaming gridcell so that it can be concatenated with other lat/lon gridcells
File /srv/conda/envs/notebook/lib/python3.9/site-packages/xarray/core/common.py:394, in DataWithCoords.squeeze(self, dim, drop, axis)
364 def squeeze(
365 self: T_DataWithCoords,
366 dim: Hashable | Iterable[Hashable] | None = None,
367 drop: bool = False,
368 axis: int | Iterable[int] | None = None,
369 ) -> T_DataWithCoords:
370 """Return a new object with squeezed data.
371
372 Parameters
(...)
392 numpy.squeeze
393 """
--> 394 dims = get_squeeze_dims(self, dim, axis)
395 return self.isel(drop=drop, **{d: 0 for d in dims})
File /srv/conda/envs/notebook/lib/python3.9/site-packages/xarray/core/common.py:348, in get_squeeze_dims(xarray_obj, dim, axis)
345 alldims = list(xarray_obj.sizes.keys())
346 dim = [alldims[a] for a in axis]
--> 348 if any(xarray_obj.sizes[k] > 1 for k in dim):
349 raise ValueError(
350 "cannot select a dimension to squeeze out "
351 "which has length greater than one"
352 )
353 return dim
File /srv/conda/envs/notebook/lib/python3.9/site-packages/xarray/core/common.py:348, in <genexpr>(.0)
345 alldims = list(xarray_obj.sizes.keys())
346 dim = [alldims[a] for a in axis]
--> 348 if any(xarray_obj.sizes[k] > 1 for k in dim):
349 raise ValueError(
350 "cannot select a dimension to squeeze out "
351 "which has length greater than one"
352 )
353 return dim
File /srv/conda/envs/notebook/lib/python3.9/site-packages/xarray/core/utils.py:458, in Frozen.__getitem__(self, key)
457 def __getitem__(self, key: K) -> V:
--> 458 return self.mapping[key]
KeyError: 'scenario'
Description of PR
Summary of changes and related issue As a part of Phase 2 Goal 3, we are working to include Historical Reconstruction data as an available option for
cava_data
function. In order to do so, we must validate the inputs (year range, ignore SSPs) to do so.Type of change
Checklist: