.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/tswc_to_bwc.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_tswc_to_bwc.py: TSWC to BWC ======================= This example demonstrates how to convert a time series wind climate (TSWC) object to a binned wind climate (BWC) object using the `bwc_from_tswc` function from the windkit library. .. GENERATED FROM PYTHON SOURCE LINES 12-16 Prepare Sample Data ------------------------ First, we need to prepare the sample data. This is done by creating a DataFrame with the wind speed and direction data. .. GENERATED FROM PYTHON SOURCE LINES 16-33 .. code-block:: Python import numpy as np import pandas as pd import windkit as wk size = 8760 # 1 year of hourly data df = pd.DataFrame( { "wspd_50": np.random.uniform(5, 15, size=size), # Wind speed in m/s "wdir_50": np.random.uniform(0, 360, size=size), # Wind direction in degrees }, index=pd.date_range("2023-01-01", periods=size, freq="h"), ) df.index.name = "time" # Set the index name to 'time' print(df.head()) .. rst-class:: sphx-glr-script-out .. code-block:: none wspd_50 wdir_50 time 2023-01-01 00:00:00 9.743766 113.243837 2023-01-01 01:00:00 13.118488 156.759630 2023-01-01 02:00:00 8.976591 246.589094 2023-01-01 03:00:00 10.284349 120.045583 2023-01-01 04:00:00 14.598357 74.204209 .. GENERATED FROM PYTHON SOURCE LINES 34-36 Create TSWC ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 36-46 .. code-block:: Python tswc = wk.tswc_from_dataframe( df, west_east=0.0, south_north=0.0, crs=4326, height_to_columns={50: ["wspd_50", "wdir_50"]}, ) print(tswc) .. rst-class:: sphx-glr-script-out .. code-block:: none Size: 210kB Dimensions: (time: 8760, height: 1, stacked_point: 1) Coordinates: west_east (stacked_point) float64 8B 0.0 south_north (stacked_point) float64 8B 0.0 crs int8 1B 0 * time (time) datetime64[ns] 70kB 2023-01-01 ... 2023-12-31T23:0... * height (height) int64 8B 50 Dimensions without coordinates: stacked_point Data variables: wind_speed (time, height, stacked_point) float64 70kB 9.744 ... 6.334 wind_direction (time, height, stacked_point) float64 70kB 113.2 ... 157.9 Attributes: history: 2025-07-21T09:49:26+00:00:\twindkit==1.0.2\twk.tswc_fro... Conventions: CF-1.8 Package name: windkit Package version: 1.0.2 Creation date: 2025-07-21T09:49:26+00:00 Object type: Time Series Wind Climate author: Default User author_email: default_email@example.com institution: Default Institution .. GENERATED FROM PYTHON SOURCE LINES 47-50 Convert TSWC to BWC ------------------------ Now, we can convert the time series wind climate (TSWC) object to a binned wind climate (BWC) object .. GENERATED FROM PYTHON SOURCE LINES 50-55 .. code-block:: Python bwc = wk.bwc_from_tswc(tswc) print(bwc) bwc.wsfreq.sel(sector=270).plot() .. image-sg:: /auto_examples/images/sphx_glr_tswc_to_bwc_001.png :alt: crs = 0, sector_ceil = 285.0 [degree], sector_f... :srcset: /auto_examples/images/sphx_glr_tswc_to_bwc_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Size: 4kB Dimensions: (wsbin: 30, sector: 12, height: 1, stacked_point: 1) Coordinates: crs int8 1B 0 wsceil (wsbin) float64 240B 1.0 2.0 3.0 4.0 ... 27.0 28.0 29.0 30.0 wsfloor (wsbin) float64 240B 0.0 1.0 2.0 3.0 ... 26.0 27.0 28.0 29.0 sector_ceil (sector) float64 96B 15.0 45.0 75.0 ... 285.0 315.0 345.0 sector_floor (sector) float64 96B 345.0 15.0 45.0 ... 255.0 285.0 315.0 west_east (stacked_point) float64 8B 0.0 south_north (stacked_point) float64 8B 0.0 * height (height) int64 8B 50 * wsbin (wsbin) float64 240B 0.5 1.5 2.5 3.5 ... 26.5 27.5 28.5 29.5 * sector (sector) float64 96B 0.0 30.0 60.0 90.0 ... 270.0 300.0 330.0 Dimensions without coordinates: stacked_point Data variables: wsfreq (wsbin, sector, height, stacked_point) float64 3kB 0.0 ... 0.0 wdfreq (sector, height, stacked_point) float64 96B 0.07934 ... 0.0... Attributes: (12/20) description: long_name: Horizontal Wind Speed standard_name: wind_speed units: m s-1 Conventions: CF-1.8 Package name: windkit ... ... end_time: 2023-12-31 23:00:00 interval: 0 days 01:00:00 count_expected: 8760 count: 8760 count_missing: 0 recovery_percentage: 100.0 [] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.189 seconds) .. _sphx_glr_download_auto_examples_tswc_to_bwc.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: tswc_to_bwc.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: tswc_to_bwc.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: tswc_to_bwc.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_