Nils Joseph Gaukroger Posted October 27, 2023 Posted October 27, 2023 Hi! I am trying to use WindKit to create a .tab file via a binned wind climate. However, I get an error when I try and run the code. The minimum working example is: import windkit import pandas as pd import numpy as np import random import xarray as xr # Function to make dummy dataframe def dummy_df(size): df = pd.DataFrame(zip([random.uniform(0, 25) for i in range(size)], [random.uniform(0, 360) for i in range(size)]), index=pd.date_range("01-01-2023 00:00:00", periods=size, freq="10T"), columns=['wind_speed', 'wind_direction']) df.index.name = 'time' df = np.round(df, 2) return df # Dummy pandas dataframe DF = dummy_df(144) # Dataframe to xarray dataset DS = xr.Dataset.from_dataframe(DF) # Assign coords to dataset DS = DS.assign_coords({"west_east":0,"south_north":0,"height":90.0}) # Add CRS to dataset windkit.add_crs(DS, 4326) # Create binned wind cliamte from timeseries bwc = windkit.bwc_from_timeseries( ts=DS ) # Create .tab file from binned wind climate windkit.binned_wind_climate.bwc_to_tabfile( bwc=bwc ) And I get the following error: Traceback (most recent call last): File "C:\Appl\venv\lib\site-packages\spyder_kernels\py3compat.py", line 356, in compat_exec exec(code, globals, locals) File "c:\users\nga\onedrive - equinor\documents\tab_files.py", line 30, in <module> bwc = windkit.bwc_from_timeseries( File "C:\Appl\venv\lib\site-packages\windkit\_validate.py", line 66, in validate obj = args[0] IndexError: tuple index out of range Any advice on where I might be going wrong? Thanks in advance, Nils
Rogier Posted October 27, 2023 Posted October 27, 2023 (edited) Hi Nils, The only thing I had to change in your code is: # Create binned wind cliamte from timeseries bwc = windkit.bwc_from_timeseries( DS ) # Create .tab file from binned wind climate windkit.binned_wind_climate.bwc_to_tabfile( bwc, "/home/rofl/test.tab" ) But I agree what you are doing should also work (the ts=DS part), so I have reported it as a bug. In the last function you have to specify the path. Cheers Edited October 27, 2023 by Rogier
Nils Joseph Gaukroger Posted October 30, 2023 Author Posted October 30, 2023 (edited) Hi Rogier, Thanks for the quick reply, that's working for me too now 🙂 Just wanted to point out also that: The same thing appears to happen with bwc_to_tabfile(), i.e. # Create .tab file from binned wind climate windkit.binned_wind_climate.bwc_to_tabfile( bwc, path="C:/Users/nga/OneDrive - Equinor/Documents/Projects/TAB_files/test.tab" ) works fine, but # Create .tab file from binned wind climate windkit.binned_wind_climate.bwc_to_tabfile( bwc=bwc, path="C:/Users/nga/OneDrive - Equinor/Documents/Projects/TAB_files/test.tab" ) gives me the following error: Traceback (most recent call last): File "C:\Users\nga\OneDrive - Equinor\Documents\Projects\TAB_files\tab_files.py", line 35, in <module> windkit.binned_wind_climate.bwc_to_tabfile( File "C:\Appl\venv\wind\lib\site-packages\windkit\binned_wind_climate.py", line 112, in wv_count_to_bwc obj = args[0] IndexError: tuple index out of range and 2. I was following the WindKit API when I omitted the path, assuming it would be set to the current working directory, and that appears to work fine too. It just writes a file called 'bwc.tab' to the current working directory if you use: # Create .tab file from binned wind climate windkit.binned_wind_climate.bwc_to_tabfile( bwc ) Edited October 30, 2023 by Nils Joseph Gaukroger
Rogier Posted October 30, 2023 Posted October 30, 2023 Ah ok, yes I see you are right about the default path being the current working directory. Yes, the error you have discovered can occur in more places in windkit. Whenever you find that error you can fix it by using positional arguments instead of named arguments for the first argument (e.g. `bwc` instead of `bwc=bwc`)
David Azócar Posted November 1, 2023 Posted November 1, 2023 Hi Nils, the function windkit.bwc_from_timeseries needs the first argument to be positional only, i.e. it cannot be used as windkit.bwc_from_timeseries(ds=ds,... But you are right, the error message is confusing. In the next release of windkit we will include a more meaningful error message, something like this TypeError: bwc_from_timeseries() got some positional-only arguments passed as keyword arguments: 'ds' Also I see you have a piece of code to create a dummy time series. In the next release of windkit we include a function to create dummy time series wind climate datasets, winkit.empty.empty_tswc, like this from windkit import empty import pandas as pd ds_location = wk.create_dataset(west_east=0.0,south_north=0.0,height=90.0,crs=4236) time_values = pd.date_range("2001-01-01", "2010-01-01", freq="10min", inclusive="left") ds_timeseries = wk.empty.empty_tswc(ds_location,time_values) you can use other available functions in the "windkit.empty" module to create dummy binned wind climates, weibull wind climates, etc. I hope you find them useful. best, David Azócar
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now