Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 6 additions & 74 deletions doc/user-guide/climada_entity_MeasureSet.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"# new impact functions\n",
"new_exp, new_impfs, new_haz = meas.apply(exp, impf_all, haz)\n",
"axes = new_impfs.plot()\n",
"axes.set_title(\"TC: Modified impact function\")"
"axes.set_title(\"TC: Modified impact function\");"
]
},
{
Expand Down Expand Up @@ -553,103 +553,35 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Read measures of an Excel file\n",
"## Read/write measure sets to/from Excel files\n",
"\n",
"Measures defined in an excel file following the template provided in sheet `measures` of `climada_python/data/system/entity_template.xlsx` can be ingested directly using the method `from_excel()`."
"Measures defined in an excel file following the template provided in sheet `measures` of `climada_python/data/system/entity_template.xlsx` can be ingested directly using the method `from_excel()`. Measure sets can be written to file with the method `write_excel()`."
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2021-03-05T12:22:41.336852Z",
"start_time": "2021-03-05T12:22:41.266438Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"<climada.entity.measures.measure_set.MeasureSet at 0x1f30d913b80>"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from climada.entity.measures import MeasureSet\n",
"from climada.util import ENT_TEMPLATE_XLS\n",
"\n",
"# Fill DataFrame from Excel file\n",
"file_name = ENT_TEMPLATE_XLS # provide absolute path of the excel file\n",
"meas_set = MeasureSet.from_excel(file_name)\n",
"meas_set"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Write measures\n",
"\n",
"Measures can be writen in Excel format using `write_excel()` method."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"ExecuteTime": {
"end_time": "2021-03-05T11:44:20.460278Z",
"start_time": "2021-03-05T11:44:16.581Z"
}
},
"outputs": [],
"source": [
"from climada.entity.measures import MeasureSet\n",
"from climada.util import ENT_TEMPLATE_XLS\n",
"\n",
"# Fill DataFrame from Excel file\n",
"file_name = ENT_TEMPLATE_XLS # provide absolute path of the excel file\n",
"meas_set = MeasureSet.from_excel(file_name)\n",
"\n",
"# write file\n",
"meas_set.write_excel(\"results/tutorial_meas_set.xlsx\")"
]
},
{
"cell_type": "markdown",
"id": "adb8d606",
"metadata": {},
"source": [
"Pickle can be used as well, but note that pickle has a [transient format](saving-with-pickle) and should be avoided when possible:"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"ExecuteTime": {
"end_time": "2021-03-05T11:44:20.462069Z",
"start_time": "2021-03-05T11:44:16.599Z"
}
},
"outputs": [],
"source": [
"from climada.util.save import save\n",
"\n",
"# this generates a results folder in the current path and stores the output there\n",
"save(\"tutorial_meas_set.p\", meas_set)"
"meas_set = MeasureSet.from_excel(file_name)"
]
}
],
"metadata": {
"hide_input": false,
"kernelspec": {
"display_name": "Python 3.8.12 ('climada_core')",
"display_name": "Python 3 (ipykernel)",
Comment on lines -652 to +584
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chahank @spjuhel I think this is stuff that nbstripout would remove. Maybe we should reconsider?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is indeed my understanding!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly :). I think it would be nice to have, but not critical at the moment. Shall we simply put it into the scrum backlog?

"language": "python",
"name": "python3"
},
Expand Down
Loading