Closed hdrake closed 3 years ago
If you find yourself frequently doing the above to extract data from ClimateMARGO types and saving them as CSV files, I would recommend writing a function to do so. See examples of how we've done this with the JSON file structure here: https://github.com/ClimateMARGO/ClimateMARGO.jl/blob/master/src/IO/json_io.jl
Thank you for your detailed response. I've tried adapting this solution to extract a time-series of the control deployment percentages but each control has the same values throughout the time-series in the resulting csv.
df = DataFrame(
year =t(m),
M = m.controls.mitigate,
R = m.controls.remove,
G = m.controls.geoeng,
A = m.controls.adapt
)
Would you be able to advise me on where I might be going wrong?
Kind regards, Tilly
Hi @txlauren, thanks for reaching out on here! I think the issue is that the example here has not yet been run through the optimization. So the controls are likely set to their defaults of zero at all times.
Try running the following commands to import the optimization functions and run the model through the control-optimizer.
using ClimateMARGO.Optimization
@time optimize_controls!(m);
You can see a more complete example in the documentation. Hope that helps!
Thank you so much @hdrake, that did the trick!
There are two ways of extracting data from the ClimateModel type. If the data you want is already an argument within the type (or a subtype), then you can just extract it like this:
m.economics.baseline_emissions
If the data does not live within the ClimateModel type (e.g. diagnostics like temperature or CO2 concentrations), then you need to use a diagnostic function that computes those timeseries based on the information in the ClimateModel type. Many of these are included in the Diagnostics submodule. For example, to extract the temperature resulting from mitigated emissions:temperature = T(m, M=true)
Here is a minimal example of using extracting data to make a csv file (see also the attached csv file that it creates).
You can see the source code for all of the different diagnostics here: https://github.com/ClimateMARGO/ClimateMARGO.jl/tree/master/src/DiagnosticsIf there is a diagnostic that you are interested in, but that is not yet computed, then you can use the existing diagnostics as a template.