|
1129 | 1129 | "source": [ |
1130 | 1130 | "We have shown, so far, how to perform to use the `MonteCarlo` class and visualize its results. By default, some variables exported to the output files, such as *apogee* and *x_impact*. The `export_list` argument provides a simplified way for the user to export additional variables listed in the documentation, such as *inclination* and *heading*. \n", |
1131 | 1131 | "\n", |
1132 | | - "There are applications in which you might need to extract more information in the results than the `export_list` argument can handle. To that end, the `MonteCarlo` class has a `export_function` argument which allows you customize further the output of the simulation.\n", |
| 1132 | + "There are applications in which you might need to extract more information in the results than the `export_list` argument can handle. To that end, the `MonteCarlo` class has a `data_collector` argument which allows you customize further the output of the simulation.\n", |
1133 | 1133 | "\n", |
1134 | 1134 | "To exemplify its use, we show how to export the *date* of the environment used in the simulation together with the *average reynolds number* along with the default variables." |
1135 | 1135 | ] |
|
1138 | 1138 | "cell_type": "markdown", |
1139 | 1139 | "metadata": {}, |
1140 | 1140 | "source": [ |
1141 | | - "We will use the `stochastic_env`, `stochastic_rocket` and `stochastic_flight` objects previously defined, and only change the `MonteCarlo` object. First, we need to define our customized export function." |
| 1141 | + "We will use the `stochastic_env`, `stochastic_rocket` and `stochastic_flight` objects previously defined, and only change the `MonteCarlo` object. First, we need to define our customized data collector." |
1142 | 1142 | ] |
1143 | 1143 | }, |
1144 | 1144 | { |
1145 | 1145 | "cell_type": "code", |
1146 | | - "execution_count": 1, |
| 1146 | + "execution_count": null, |
1147 | 1147 | "metadata": {}, |
1148 | 1148 | "outputs": [], |
1149 | 1149 | "source": [ |
1150 | 1150 | "import numpy as np\n", |
1151 | 1151 | "\n", |
1152 | | - "\n", |
1153 | | - "def custom_export_function(flight):\n", |
| 1152 | + "# Defining custom callback functions\n", |
| 1153 | + "def get_average_reynolds_number(flight):\n", |
1154 | 1154 | " reynold_number_list = flight.reynolds_number(flight.time)\n", |
1155 | 1155 | " average_reynolds_number = np.mean(reynold_number_list)\n", |
1156 | | - " custom_exports = {\n", |
1157 | | - " \"average_reynolds_number\": average_reynolds_number,\n", |
1158 | | - " \"date\": flight.env.date,\n", |
1159 | | - " }\n", |
1160 | | - " return custom_exports" |
| 1156 | + " return average_reynolds_number\n", |
| 1157 | + "\n", |
| 1158 | + "def get_date(flight):\n", |
| 1159 | + " return flight.env.date\n", |
| 1160 | + "\n", |
| 1161 | + "custom_data_collector = {\n", |
| 1162 | + " \"average_reynolds_number\": get_average_reynolds_number,\n", |
| 1163 | + " \"date\": get_date,\n", |
| 1164 | + "}" |
1161 | 1165 | ] |
1162 | 1166 | }, |
1163 | 1167 | { |
1164 | 1168 | "cell_type": "markdown", |
1165 | 1169 | "metadata": {}, |
1166 | 1170 | "source": [ |
| 1171 | + "The `data_collector` must be a dictionary whose keys are the names of the variables we want to export and the values are callback functions (python callables) that compute these variable values. Notice how we can compute complex expressions in this function and just export the result. For instance, the *get_average_reynolds_number* calls the `flight.reynolds_number` method for each value in `flight.time` list and computes the average value using numpy's `mean`. The *date* variable is straightforward.\n", |
1167 | 1172 | "\n", |
1168 | | - "The `export_function` must be a function which takes a `Flight` object and outputs a dictionary whose keys are variables names to export and their values. Notice how we can compute complex expressions in this function and just export the result. For instance, the *average_reynolds_number* calls the `flight.reynolds_number` method for each value in `flight.time` list and computes the average value using numpy's `mean`. The *date* variable is straightforward.\n", |
1169 | | - "\n", |
1170 | | - "After we define the export function, we pass it as an argument to the `MonteCarlo` class." |
| 1173 | + "After we define the data collector, we pass it as an argument to the `MonteCarlo` class." |
1171 | 1174 | ] |
1172 | 1175 | }, |
1173 | 1176 | { |
|
1181 | 1184 | " environment=stochastic_env,\n", |
1182 | 1185 | " rocket=stochastic_rocket,\n", |
1183 | 1186 | " flight=stochastic_flight,\n", |
1184 | | - " export_function=custom_export_function,\n", |
| 1187 | + " export_list=[\"apogee\", \"apogee_time\", \"x_impact\"],\n", |
| 1188 | + " data_collector=custom_data_collector,\n", |
1185 | 1189 | ")" |
1186 | 1190 | ] |
1187 | 1191 | }, |
|
0 commit comments