We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
To reproduce:
analysis.py
import param import numpy as np import pandas as pd import lumen.ai as lmai from lumen.layout import Layout from lumen.transforms import Transform from lumen.sources.duckdb import DuckDBSource from lumen.views import hvPlotView, Table class WindSpeedDirection(Transform): u_component = param.String(default="u", doc="Column name of the zonal component") v_component = param.String(default="v", doc="Column name of the meridional component") def apply(self, df): # Calculate wind speed df["wind_speed"] = np.sqrt( df[self.u_component] ** 2 + df[self.v_component] ** 2 ) # Calculate wind direction in degrees (from north) df["wind_direction"] = np.degrees( np.arctan2(df[self.v_component], df[self.u_component]) ) # Ensure wind direction is in the range [0, 360) df["wind_direction"] = (df["wind_direction"] + 360) % 360 return df class WindAnalysis(lmai.Analysis): """ Calculates the wind speed and direction from the u and v components of wind, displaying both the table and meteogram. """ columns = param.List(default=["time", "u", "v"]) def __call__(self, pipeline): wind_pipeline = pipeline.chain(transforms=[WindSpeedDirection()]) wind_speed_view = hvPlotView( pipeline=wind_pipeline, title="Wind Speed", x="time", y="wind_speed", ) wind_direction_view = hvPlotView( pipeline=wind_pipeline, title="Wind Speed", x="time", y="wind_speed", text="wind_direction", kind="labels", ) wind_table = Table(pipeline=wind_pipeline) return Layout( views=[ wind_speed_view, wind_direction_view, wind_table, ], layout=[[0, 1], [2]], )
app.py
import numpy as np import pandas as pd import lumen.ai as lmai from lumen.sources.duckdb import DuckDBSource from analysis import WindAnalysis llm = lmai.llm.OpenAI() uv_df = pd.DataFrame({ "time": pd.date_range('2024-11-11', '2024-11-22'), "u": np.random.rand(12), "v": np.random.rand(12) }) source = lmai.memory["source"] = DuckDBSource.from_df({"uv_df": uv_df}) analysis_agent = lmai.agents.AnalysisAgent(analyses=[WindAnalysis]) ui = lmai.ExplorerUI(llm=llm, agents=[analysis_agent]) ui.servable()
panel serve app.py
Run show me 'uv_df' and click wind analysis button.
show me 'uv_df'
layout: - - 0 - 1 - - 2 title: Layout01936 views: - pipeline: pipeline: source: ephemeral: true tables: show_uv_df_contents: id: e4d924fdbd484ce88eadcdf76352d45a serializer: type: session type: session type: duckdb uri: ':memory:' sql_transforms: - limit: 1000000 type: sql_limit table: show_uv_df_contents table: show_uv_df_contents transforms: - type: analysis.WindSpeedDirection title: Wind Speed type: hvplot x: time y: wind_speed - kind: labels pipeline: pipeline: source: ephemeral: true tables: show_uv_df_contents: id: f22c29eb08bc444592bc2122f4cd3c1a serializer: type: session type: session type: duckdb uri: ':memory:' sql_transforms: - limit: 1000000 type: sql_limit table: show_uv_df_contents table: show_uv_df_contents transforms: - type: analysis.WindSpeedDirection text: wind_direction title: Wind Speed type: hvplot x: time y: wind_speed - pipeline: pipeline: source: ephemeral: true tables: show_uv_df_contents: id: db82505421e74ad59153cc9877800b49 serializer: type: session type: session type: duckdb uri: ':memory:' sql_transforms: - limit: 1000000 type: sql_limit table: show_uv_df_contents table: show_uv_df_contents transforms: - type: analysis.WindSpeedDirection type: table
The text was updated successfully, but these errors were encountered:
philippjfr
No branches or pull requests
To reproduce:
analysis.py
app.py
panel serve app.py
Run
show me 'uv_df'
and click wind analysis button.The text was updated successfully, but these errors were encountered: