Hi all,
I am trying to use PyWAsP to export weibull wind climates as rsf and wrg files but have been having trouble with the windkit to_rsffile and to_wrgfile functions.
After loading in a tab file, contour map, roughness map, and turbine locations, I calculated the generalised wind climate and the predicted wind climate at each turbine. I then attempted to output the results to an rsf using the code below but I keep getting the following error.
site_effects = topo_map.get_site_effects(output_locs, nsecs=12)
pwc_rsf = pw.wasp.get_wasp_down(gwc, site_effects, genwc_interp="nearest")
wk.to_rsffile(pwc_rsf, 'test.rsf')
KeyError Traceback (most recent call last)
File ~/mambaforge/envs/pywasp_env/lib/python3.8/site-packages/xarray/core/dataset.py:1340, in Dataset._construct_dataarray(self, name)
1339 try:
-> 1340 variable = self._variables[name]
1341 except KeyError:
KeyError: 'elevation'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
Cell In[104], line 1
----> 1 wk.to_rsffile(pwc_rsf, 'test.rsf')
File ~/mambaforge/envs/pywasp_env/lib/python3.8/site-packages/windkit/weibull_wind_climate.py:408, in to_rsffile(wwc, rsffile, wrg_header)
398 def to_rsffile(wwc, rsffile, wrg_header=False):
399 """Write weibull wind climate dataset to .rsf file.
400
401 Parameters
(...)
406 Path to .rsf file
407 """
--> 408 return _to_resource_file(wwc, rsffile, wrg_header=wrg_header)
File ~/mambaforge/envs/pywasp_env/lib/python3.8/site-packages/windkit/_validate.py:71, in create_validator.<locals>.validator_wrapper.<locals>.validate(*args, **kwargs)
68 # Do bwc checks
69 validator(obj) # Raises ValueError if errors exist
---> 71 result = func(*args, **kwargs)
72 return result
File ~/mambaforge/envs/pywasp_env/lib/python3.8/site-packages/windkit/weibull_wind_climate.py:363, in _to_resource_file(wwc, rsffile, wrg_header)
360 wwc_cp["k"] = (wwc_cp["k"] * 100.0).astype(np.int16)
361 wwc_cp["wdfreq"] = (wwc_cp["wdfreq"] * 1000.0).astype(np.int16)
--> 363 df = wwc_cp["elevation"].to_dataframe().reset_index()
364 new_columns = ["point", "Name", "west_east", "south_north", "elevation", "height"]
365 df = df.reindex(columns=new_columns)
File ~/mambaforge/envs/pywasp_env/lib/python3.8/site-packages/xarray/core/dataset.py:1431, in Dataset.__getitem__(self, key)
1429 return self.isel(**key)
1430 if utils.hashable(key):
-> 1431 return self._construct_dataarray(key)
1432 if utils.iterable_of_hashable(key):
1433 return self._copy_listed(key)
File ~/mambaforge/envs/pywasp_env/lib/python3.8/site-packages/xarray/core/dataset.py:1342, in Dataset._construct_dataarray(self, name)
1340 variable = self._variables[name]
1341 except KeyError:
-> 1342 _, name, variable = _get_virtual_variable(self._variables, name, self.dims)
1344 needed_dims = set(variable.dims)
1346 coords: dict[Hashable, Variable] = {}
File ~/mambaforge/envs/pywasp_env/lib/python3.8/site-packages/xarray/core/dataset.py:178, in _get_virtual_variable(variables, key, dim_sizes)
176 split_key = key.split(".", 1)
177 if len(split_key) != 2:
--> 178 raise KeyError(key)
180 ref_name, var_name = split_key
181 ref_var = variables[ref_name]
KeyError: 'elevation'
Does anyone know why I'm getting this error and/or how I could fix this issue? Am I missing some steps between downscaling to a wwc and outputting the rsf?
Any help is much appreciated, thank you