|
| 1 | + |
| 2 | +# Creating custom arguments for perturbation experiments |
| 3 | +In cases where it is of interest to run ensembles of the same model configuration but with perturbed initial conditions, it may be of use to add new keyword arguments to the .yml file. The idea is to allow modifications to initial conditions to be passed directly through the .yml file and then creating multiple copies of the files but with different variations and combinations of these parameters. |
| 4 | + |
| 5 | +As an example, we will explore modifying the total water mixing ratio (`q_tot_0`), liquid-ice potential temperature profiles (`theta_0` & `theta_i`), and initial boundary layer height (`z_i`) in the DYCOMS-RF02 simulation setup. |
| 6 | + |
| 7 | +### Modify initial_conditions.jl |
| 8 | +To start, we need to go to the part of the source code responsible for defining the initial conditions. For both of the DYCOMS research flight simulation setups, the total water mixing ratio and liquid-ice potential temperature are pulled from another library called AtmosphericProfilesLibrary (APL). |
| 9 | + |
| 10 | +There are many ways to modify the functions to allow for perturbation to the initial conditions, but for the sake of this example we will overwrite the function signature with our own version where we can pass in our own custom profiles. We must import the functions from the APL library and then define a new function with the same signature. This looks like: |
| 11 | + |
| 12 | +``` |
| 13 | +import AtmosphericProfilesLibrary: Dycoms_RF02_θ_liq_ice, Dycoms_RF02_q_tot |
| 14 | +[...] |
| 15 | +
|
| 16 | +# Redefine the profile functions here. Here we redefine the functions such that |
| 17 | +# we can pass in our own values for q_tot and θ_liq_ice, as well as modifying |
| 18 | +# the initial boundary layer height. |
| 19 | +
|
| 20 | +""" [Ackerman2009](@cite) """ |
| 21 | +Dycoms_RF02_θ_liq_ice(::Type{FT}, theta_0, theta_i, z_i) where {FT} = |
| 22 | + APL.ZProfile(z -> if z <= z_i |
| 23 | + FT(theta_0) |
| 24 | + else |
| 25 | + FT(theta_i) + (z - FT(z_i))^FT(1.0 / 3.0) |
| 26 | + end) |
| 27 | +
|
| 28 | +""" [Ackerman2009](@cite) """ |
| 29 | +Dycoms_RF02_q_tot(::Type{FT}, q_tot_0, z_i) where {FT} = |
| 30 | + APL.ZProfile(z -> if z <= z_i |
| 31 | + FT(q_tot_0) / FT(1000.0) |
| 32 | + else |
| 33 | + (FT(5) - FT(3) * (FT(1) - exp(-(z - FT(z_i)) / FT(500)))) / FT(1000) |
| 34 | + end) |
| 35 | +``` |
| 36 | + |
| 37 | +Now that we have redefined our functions, we can pass these new functions to our intial conditions structure for the DYCOMS-RF02 setup. Here we can also begin to define our new keyword arguments that will serve as inputs for the new functions we defined. In the `DYCOMS_RF02` structure, we add the names of our new inputs: |
| 38 | + |
| 39 | +``` |
| 40 | +Base.@kwdef struct DYCOMS_RF02 <: InitialCondition |
| 41 | + prognostic_tke::Bool = false |
| 42 | + q_tot_0_dycoms_rf02 # Define total water mixing ratio. |
| 43 | + theta_0_dycoms_rf02 # Define liquid-ice θ at surface. |
| 44 | + theta_i_dycoms_rf02 # Define liquid-ice θ at initial boundary layer height. |
| 45 | + z_i_dycoms_rf02 # Define initial boundary layer height. |
| 46 | +end |
| 47 | +
|
| 48 | +for IC in (:Dycoms_RF01, :Dycoms_RF02) |
| 49 | + IC_Type = Symbol(uppercase(string(IC))) |
| 50 | + θ_func_name = Symbol(IC, :_θ_liq_ice) |
| 51 | + q_tot_func_name = Symbol(IC, :_q_tot) |
| 52 | + [...] |
| 53 | + if IC == :Dycoms_RF02 |
| 54 | + @eval function (initial_condition::$IC_Type)(params) |
| 55 | + (; prognostic_tke, q_tot_0_dycoms_rf02, theta_0_dycoms_rf02, theta_i_dycoms_rf02, z_i_dycoms_rf02) = initial_condition #unpack the new arguments here. These arguments will be provided through the model .yml file. |
| 56 | + FT = eltype(params) |
| 57 | + [...] |
| 58 | + θ = $θ_func_name(FT, FT(theta_0_dycoms_rf02), FT(theta_i_dycoms_rf02), FT(z_i_dycoms_rf02)) # Change function signature here. |
| 59 | + q_tot = $q_tot_func_name(FT, FT(q_tot_0_dycoms_rf02), FT(z_i_dycoms_rf02)) # Change function signature here. |
| 60 | + end |
| 61 | + else |
| 62 | + [...] |
| 63 | + end |
| 64 | +end |
| 65 | +``` |
| 66 | + |
| 67 | +### Add keywords to .yml & Modify default_config.yml |
| 68 | +Now that we have added a new keyword argument to be used in initial conditions, it is time to define the keyword argument in the YAML files responsible for configuring the model runs. In the YAML file for running a DYCOMS-RF02 single column experiment, we add and adjust the following lines: |
| 69 | + |
| 70 | +``` |
| 71 | +q_tot_0_dycoms_rf02: 9.45 # Define variables here. |
| 72 | +theta_0_dycoms_rf02: 288.3 # Define variables here. |
| 73 | +theta_i_dycoms_rf02: 295.0 # Define variables here. |
| 74 | +z_i_dycoms_rf02: 795.0 # Define variables here. |
| 75 | +``` |
| 76 | + |
| 77 | +These are the same default values being used by the original APL function, but we can modify it in the YAML file if we want to test different initial conditions. Additionally, we need to provide a backup default value in the case that the keyword argument is not used or provided in the setup YAML file. To do this, we go to default_config.yml and add the following: |
| 78 | + |
| 79 | +``` |
| 80 | +q_tot_0_dycoms_rf02: # Additional variables here. |
| 81 | + help: "Surface total water mixing ratio for DYCOMS RF02." |
| 82 | + value: 9.45 # Default value. |
| 83 | +theta_0_dycoms_rf02: # Additional variables here. |
| 84 | + help: "Surface liquid-ice potential temperature for DYCOMS RF02." |
| 85 | + value: 288.3 # Default value. |
| 86 | +theta_i_dycoms_rf02: # Additional variables here. |
| 87 | + help: "Initial boundary layer liquid-ice potential temperature for DYCOMS RF02." |
| 88 | + value: 295.0 # Default value. |
| 89 | +z_i_dycoms_rf02: # Additional variables here. |
| 90 | + help: "Initial boundary layer height." |
| 91 | + value: 795.0 # Default value. |
| 92 | +``` |
| 93 | + |
| 94 | +### Modify type_getters.jl |
| 95 | +Finally, we need to update type_getters.jl with our new keyword arguments as well. We find where DYCOMS-RF02 is specified and then we replace it with a separate block that looks like: |
| 96 | + |
| 97 | +``` |
| 98 | +[...] |
| 99 | + elseif parsed_args["initial_condition"] == "DYCOMS_RF02" |
| 100 | + return getproperty(ICs, Symbol(parsed_args["initial_condition"]))( |
| 101 | + parsed_args["prognostic_tke"], |
| 102 | + parsed_args["q_tot_0_dycoms_rf02"], # Add parsed args here. |
| 103 | + parsed_args["theta_0_dycoms_rf02"], # Add parsed args here. |
| 104 | + parsed_args["theta_i_dycoms_rf02"], # Add parsed args here. |
| 105 | + parsed_args["z_i_dycoms_rf02"], # Add parsed args here. |
| 106 | + ) |
| 107 | +[...] |
| 108 | +``` |
| 109 | + |
| 110 | +With this step complete, we are now ready to pass a new keyword argument that we defined ourselves to modify or change the initial conditions. |
| 111 | + |
| 112 | +The recommended workflow is the create multiple copies of the .yml files and label them according to the initial conditions used. For example, the default file might look like `prognostic_edmfx_dycoms_rf02_column_qtot0_6.5_theta0_284.0_thetai_290.0_zi_795.0_prescribedN_1.0e8.yml`. |
0 commit comments