{ "cells": [ { "cell_type": "markdown", "id": "c551f591", "metadata": {}, "source": [ "# Light Demo\n", "\n", "This demo shows the simpelst way to create mobility and charging profiles with `CHAMPPY`. Therefore, no paramerization is performed, but existing model parameters are used. " ] }, { "cell_type": "markdown", "id": "b973d20d", "metadata": {}, "source": [ "## 1. Import Required Libraries\n", "Import all necessary libraries, including pandas and champpy." ] }, { "cell_type": "code", "execution_count": 1, "id": "a8f96fa5", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import champpy" ] }, { "cell_type": "markdown", "id": "d47a1cd8", "metadata": {}, "source": [ "## 2. Check available model parameters\n", "\n", "The model champpy provides different sets of model parameters, e.g. for different vehicles types. First you have to check which parameters are available using the `ParamsLoader`. " ] }, { "cell_type": "code", "execution_count": 2, "id": "3b588fa8", "metadata": {}, "outputs": [ { "data": { "application/vnd.microsoft.datawrangler.viewer.v0+json": { "columns": [ { "name": "index", "rawType": "int64", "type": "integer" }, { "name": "id_params", "rawType": "int64", "type": "integer" }, { "name": "description", "rawType": "object", "type": "string" }, { "name": "vehicle_type", "rawType": "object", "type": "string" }, { "name": "temp_res", "rawType": "float64", "type": "float" }, { "name": "annual_km", "rawType": "float64", "type": "float" }, { "name": "locations", "rawType": "object", "type": "unknown" }, { "name": "share_of_time_at_locations", "rawType": "object", "type": "unknown" }, { "name": "number_typedays", "rawType": "int64", "type": "integer" }, { "name": "number_clusters", "rawType": "int64", "type": "integer" }, { "name": "labels_locations", "rawType": "object", "type": "unknown" }, { "name": "labels_clusters", "rawType": "object", "type": "unknown" }, { "name": "created_user", "rawType": "object", "type": "string" }, { "name": "created_dt", "rawType": "datetime64[ns]", "type": "datetime" } ], "ref": "75cd188a-cddb-4094-a7b9-7f67dad3c77d", "rows": [ [ "0", "1", "Vans based on REM2030 Dataset (https://www.isi-lehre.de/rem2030-de/REM-2030-Driving-Profiles.php)", "Van", "0.25", "21743.995", "[0 1 3]", "[12.411 58.285 29.304]", "7", "1", "['Driving' 'Depot' 'Other location']", "['Cluster 1']", "FBiedenbach", "2026-03-11 12:28:44.336818" ], [ "1", "2", "Trucks based on Nefton Dataset (https://doi.org/10.5281/zenodo.7599687)", "Truck", "0.25", "59064.024", "[0 1 3 5 6]", "[15.821 54.941 15.94 4.322 8.976]", "7", "1", "['Driving' 'Depot' 'Other location' 'Rest area' 'Industrial area']", "['Cluster 1']", "FBiedenbach", "2026-03-11 12:33:13.254130" ], [ "2", "3", "Passenger cars based on KID 2010", "Passenger car", "0.25", "11568.039", "[0 1 3]", "[ 9.588 18.307 72.105]", "7", "1", "['Driving' 'Company site' 'Other location']", "['Cluster 1']", "FBiedenbach", "2026-03-11 12:39:39.712594" ] ], "shape": { "columns": 13, "rows": 3 } }, "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
id_paramsdescriptionvehicle_typetemp_resannual_kmlocationsshare_of_time_at_locationsnumber_typedaysnumber_clusterslabels_locationslabels_clusterscreated_usercreated_dt
01Vans based on REM2030 Dataset (https://www.isi...Van0.2521743.995[0, 1, 3][12.411, 58.285, 29.304]71[Driving, Depot, Other location][Cluster 1]FBiedenbach2026-03-11 12:28:44.336818
12Trucks based on Nefton Dataset (https://doi.or...Truck0.2559064.024[0, 1, 3, 5, 6][15.821, 54.941, 15.94, 4.322, 8.976]71[Driving, Depot, Other location, Rest area, In...[Cluster 1]FBiedenbach2026-03-11 12:33:13.254130
23Passenger cars based on KID 2010Passenger car0.2511568.039[0, 1, 3][9.588, 18.307, 72.105]71[Driving, Company site, Other location][Cluster 1]FBiedenbach2026-03-11 12:39:39.712594
\n", "
" ], "text/plain": [ " id_params description \\\n", "0 1 Vans based on REM2030 Dataset (https://www.isi... \n", "1 2 Trucks based on Nefton Dataset (https://doi.or... \n", "2 3 Passenger cars based on KID 2010 \n", "\n", " vehicle_type temp_res annual_km locations \\\n", "0 Van 0.25 21743.995 [0, 1, 3] \n", "1 Truck 0.25 59064.024 [0, 1, 3, 5, 6] \n", "2 Passenger car 0.25 11568.039 [0, 1, 3] \n", "\n", " share_of_time_at_locations number_typedays number_clusters \\\n", "0 [12.411, 58.285, 29.304] 7 1 \n", "1 [15.821, 54.941, 15.94, 4.322, 8.976] 7 1 \n", "2 [9.588, 18.307, 72.105] 7 1 \n", "\n", " labels_locations labels_clusters \\\n", "0 [Driving, Depot, Other location] [Cluster 1] \n", "1 [Driving, Depot, Other location, Rest area, In... [Cluster 1] \n", "2 [Driving, Company site, Other location] [Cluster 1] \n", "\n", " created_user created_dt \n", "0 FBiedenbach 2026-03-11 12:28:44.336818 \n", "1 FBiedenbach 2026-03-11 12:33:13.254130 \n", "2 FBiedenbach 2026-03-11 12:39:39.712594 " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# generate instance of ParamsLoader\n", "params_loader= champpy.ParamsLoader()\n", "\n", "# load info DataFrame\n", "params_info_df = params_loader.load_info()\n", "params_info_df\n" ] }, { "cell_type": "markdown", "id": "9a3cedf5", "metadata": {}, "source": [ "Select the `id_params` of the model parameters you want to use. In this example, we use parameters for vans." ] }, { "cell_type": "code", "execution_count": 3, "id": "ea738930", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[2026-03-12 11:45:05 - INFO - champpy.core.mobility.parameterization] Load parameters with id_params=1.\n" ] } ], "source": [ "selected_id_params = 1\n", "model_params = params_loader.load_params(id_params=selected_id_params)" ] }, { "cell_type": "markdown", "id": "981cdc31", "metadata": {}, "source": [ "## 3. Generate Mobility Profiles\n", "Using the `MobModel` and `UserParamsMobModel` to generate synthetic mobility profiles for a specified number of vehicles and date range. The model parameters loaded in the previous step, serves as input to create the instance of `MobModel`." ] }, { "cell_type": "code", "execution_count": 4, "id": "b46c2e33", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[2026-03-12 11:46:41 - INFO - champpy.core.mobility.mobility_model] Start generating mobility profiles for 50 vehicles from 2025-01-01 00:00:00 to 2025-12-31 23:00:00\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "dbab76bf798745c8b3f8d74ff1c9e2e8", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n"
      ],
      "text/plain": []
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Generate synthetic mobility profiles\n",
    "mob_model = champpy.MobModel(model_params=model_params)\n",
    "user_params_mob = champpy.UserParamsMobModel(\n",
    "    number_vehicles=50,\n",
    "    start_date=pd.Timestamp(\"2025-01-01-00:00:00\"),\n",
    "    end_date=pd.Timestamp(\"2025-12-31-23:00:00\"),\n",
    ")\n",
    "mob_profiles = mob_model.generate_mob_profiles(user_params=user_params_mob)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9ec22e1f",
   "metadata": {},
   "source": [
    "Display logbook of the generated mobility profile:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "5e0d8ecf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.microsoft.datawrangler.viewer.v0+json": {
       "columns": [
        {
         "name": "index",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "id_journey",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "id_vehicle",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "dep_dt",
         "rawType": "datetime64[ns]",
         "type": "datetime"
        },
        {
         "name": "arr_dt",
         "rawType": "datetime64[ns]",
         "type": "datetime"
        },
        {
         "name": "dep_loc",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "arr_loc",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "distance",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "duration",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "speed",
         "rawType": "float64",
         "type": "float"
        }
       ],
       "ref": "b07b3202-d9ab-402c-80f6-d5c03b313919",
       "rows": [
        [
         "0",
         "1",
         "1",
         "2025-01-01 07:00:00",
         "2025-01-01 08:45:00",
         "1",
         "3",
         "40.73805583911964",
         "1.75",
         "23.278889050925507"
        ],
        [
         "1",
         "2",
         "1",
         "2025-01-01 10:30:00",
         "2025-01-01 11:15:00",
         "3",
         "1",
         "15.549081834501322",
         "0.75",
         "20.73210911266843"
        ],
        [
         "2",
         "3",
         "1",
         "2025-01-01 11:30:00",
         "2025-01-01 12:00:00",
         "1",
         "1",
         "1.205889262455724",
         "0.5",
         "2.411778524911448"
        ],
        [
         "3",
         "4",
         "1",
         "2025-01-02 07:30:00",
         "2025-01-02 07:45:00",
         "1",
         "1",
         "1.4205970834566366",
         "0.25",
         "5.682388333826546"
        ],
        [
         "4",
         "5",
         "1",
         "2025-01-02 09:15:00",
         "2025-01-02 09:45:00",
         "1",
         "1",
         "5.628536592248186",
         "0.5",
         "11.257073184496372"
        ]
       ],
       "shape": {
        "columns": 9,
        "rows": 5
       }
      },
      "text/html": [
       "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
id_journeyid_vehicledep_dtarr_dtdep_locarr_locdistancedurationspeed
0112025-01-01 07:00:002025-01-01 08:45:001340.7380561.7523.278889
1212025-01-01 10:30:002025-01-01 11:15:003115.5490820.7520.732109
2312025-01-01 11:30:002025-01-01 12:00:00111.2058890.502.411779
3412025-01-02 07:30:002025-01-02 07:45:00111.4205970.255.682388
4512025-01-02 09:15:002025-01-02 09:45:00115.6285370.5011.257073
\n", "
" ], "text/plain": [ " id_journey id_vehicle dep_dt arr_dt dep_loc \\\n", "0 1 1 2025-01-01 07:00:00 2025-01-01 08:45:00 1 \n", "1 2 1 2025-01-01 10:30:00 2025-01-01 11:15:00 3 \n", "2 3 1 2025-01-01 11:30:00 2025-01-01 12:00:00 1 \n", "3 4 1 2025-01-02 07:30:00 2025-01-02 07:45:00 1 \n", "4 5 1 2025-01-02 09:15:00 2025-01-02 09:45:00 1 \n", "\n", " arr_loc distance duration speed \n", "0 3 40.738056 1.75 23.278889 \n", "1 1 15.549082 0.75 20.732109 \n", "2 1 1.205889 0.50 2.411779 \n", "3 1 1.420597 0.25 5.682388 \n", "4 1 5.628537 0.50 11.257073 " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mob_profiles.logbooks.df.head()" ] }, { "cell_type": "markdown", "id": "32d96056", "metadata": {}, "source": [ "## 4. Generate charging profiles\n", "Use classes`ChargeModel` and `UserParamsChargeModel` to generate synthetic charging profiles." ] }, { "cell_type": "code", "execution_count": 6, "id": "cdd91cf2", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[2026-03-12 11:46:48 - INFO - champpy.core.mobility.mobility_data] Creating MobArray from MobProfiles\n", "[2026-03-12 11:46:48 - INFO - champpy.core.mobility.mobility_data] Extending MobProfiles\n", "[2026-03-12 11:46:50 - INFO - root] Generating charging profiles based on mobility data and user parameters...\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "33b85660f5f145b791beadabfff8bd36", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n"
      ],
      "text/plain": []
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Initilaize the charging model with the modeled mobility prfiles\n",
    "charging_model = champpy.ChargingModel(mob_profiles)\n",
    "\n",
    "# Define user parameters for the charging model\n",
    "user_params_charging = champpy.UserParamsChargingModel(\n",
    "    energy_consumption_kwh_per_km=[0.2],\n",
    "    battery_capacity_kwh=[80.0],\n",
    "    charging_power_max_kw=[11],\n",
    "    efficiency_charging=[0.9],\n",
    "    soc_min=[0.1],\n",
    "    soc_min_dep=[0.8],\n",
    "    soc_initial=1,\n",
    "    distribute_energy_consumption=True,\n",
    "    charging_locations=[1], \n",
    "    temp_res=0.25\n",
    ")\n",
    "\n",
    "# Generate charging profiles based on the mobility profiles and the user parameters for charging\n",
    "charging_profiles = charging_model.generate_charging_profiles(user_params=user_params_charging)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f823e8c9",
   "metadata": {},
   "source": [
    "Display timeseries of the generated charging profiles:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a6eb68d3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.microsoft.datawrangler.viewer.v0+json": {
       "columns": [
        {
         "name": "index",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "id_vehicle",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "datetime",
         "rawType": "datetime64[ns]",
         "type": "datetime"
        },
        {
         "name": "connected",
         "rawType": "bool",
         "type": "boolean"
        },
        {
         "name": "energy_consumption_kwh",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "energy_stored_kwh",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "power_charging_kw",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "energy_missing_kwh",
         "rawType": "float64",
         "type": "float"
        }
       ],
       "ref": "10598a34-3bbd-4dbb-a8f6-1194b1a31a6d",
       "rows": [
        [
         "0",
         "1",
         "2025-01-01 00:00:00",
         "False",
         "0.0",
         "50.0",
         "0.0",
         "0.0"
        ],
        [
         "1",
         "1",
         "2025-01-01 00:15:00",
         "False",
         "0.0",
         "50.0",
         "0.0",
         "0.0"
        ],
        [
         "2",
         "1",
         "2025-01-01 00:30:00",
         "False",
         "0.0",
         "50.0",
         "0.0",
         "0.0"
        ],
        [
         "3",
         "1",
         "2025-01-01 00:45:00",
         "False",
         "0.0",
         "50.0",
         "0.0",
         "0.0"
        ],
        [
         "4",
         "1",
         "2025-01-01 01:00:00",
         "False",
         "0.0",
         "50.0",
         "0.0",
         "0.0"
        ]
       ],
       "shape": {
        "columns": 7,
        "rows": 5
       }
      },
      "text/html": [
       "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
id_vehicledatetimeconnectedenergy_consumption_kwhenergy_stored_kwhpower_charging_kwenergy_missing_kwh
012025-01-01 00:00:00False0.050.00.00.0
112025-01-01 00:15:00False0.050.00.00.0
212025-01-01 00:30:00False0.050.00.00.0
312025-01-01 00:45:00False0.050.00.00.0
412025-01-01 01:00:00False0.050.00.00.0
\n", "
" ], "text/plain": [ " id_vehicle datetime connected energy_consumption_kwh \\\n", "0 1 2025-01-01 00:00:00 False 0.0 \n", "1 1 2025-01-01 00:15:00 False 0.0 \n", "2 1 2025-01-01 00:30:00 False 0.0 \n", "3 1 2025-01-01 00:45:00 False 0.0 \n", "4 1 2025-01-01 01:00:00 False 0.0 \n", "\n", " energy_stored_kwh power_charging_kw energy_missing_kwh \n", "0 50.0 0.0 0.0 \n", "1 50.0 0.0 0.0 \n", "2 50.0 0.0 0.0 \n", "3 50.0 0.0 0.0 \n", "4 50.0 0.0 0.0 " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "charging_profiles.charging_timeseries.df.head()" ] }, { "cell_type": "markdown", "id": "0ecf73f1", "metadata": {}, "source": [ "## 5. Plot mobility and charging profiles\n", "\n", "You can visulize the modeld mobility and charging profiles using the `MobPlotter` and `ChargingPlotter` classed. They must be initialized by different user parameters defined in the `UserParamsMobPlotter` and `UserParamsChargingPlotter` data classes. " ] }, { "cell_type": "code", "execution_count": null, "id": "8741d5db", "metadata": {}, "outputs": [], "source": [ "# Initialize user parameters for plotting the mobiltiy profiles\n", "user_params_plot = champpy.UserParamsMobPlotter(\n", " filename=\"demo01_mobility_profiles_plot.html\",\n", " clustering = False\n", ")\n", "\n", "# Create instance of the mobility plotter\n", "mobplot = champpy.MobPlotter(user_params_plot)\n", "\n", "# Plot the mobility profiles for the merged data (ref + model)\n", "mobplot.plot_mob_profiles(mob_profiles)\n", "\n", "# Initialize user parameters for plotting the charging profiles\n", "user_params_plot = champpy.UserParamsChargingPlotter(\n", " filename=\"demo01_charging_profiles_plot.html\",\n", " clustering = False\n", ")\n", "\n", "# Create an instance of the ChargingPlotter\n", "chargeplot = champpy.ChargingPlotter(user_params_plot)\n", "\n", "# Plot the charging profiles\n", "chargeplot.plot_charging_profiles(charging_profiles)" ] } ], "metadata": { "kernelspec": { "display_name": ".venv (3.13.7)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.7" } }, "nbformat": 4, "nbformat_minor": 5 }