• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OmegaLambda1998 / ShockCooling.jl / 9802931045

05 Jul 2024 04:07AM UTC coverage: 0.0%. Remained the same
9802931045

push

github

OmegaLambda1998
TruncatedNormal -> Truncated

0 of 1 new or added line in 1 file covered. (0.0%)

0 of 527 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/ModelModule.jl
1
# Model Module
2
module ModelModule
3

4
# Internal Packages 
5

6
# External Packages 
7
using Supernovae
8
using Unitful, UnitfulAstro
9
UNITS = [Unitful, UnitfulAstro]
10
using Distributions
11
using LaTeXStrings
12

13
# Exports
14
export Model
15
export run_model
16
export setup_model
17

18
"""
19
    abstract type Model
20

21
Abstract type for models. All models must be subtypes of this type.
22
"""
23
abstract type Model end
24

25
"""
26
    function run_model(model::Model, param::Dict{String,Unitful.Quantity}, supernova::Supernova)
27

28
Run a model on a supernova with a given set of parameters. Each model should have its own implementation of this function. If a model is missing this implementation, this will through an error
29

30
# Arguments
31
- `model::Model`: The [`Model`](model) to run.
32
- `param::Dict{String,Unitful.Quantity}`: A dictionary of parameters to run the model with.
33
- `supernova::Supernova`: The [`Supernova`](supernova) to run the model on.
34
"""
35
function run_model(model::Model, param::Dict{String,Unitful.Quantity}, supernova::Supernova)
×
36
    error("generic run_model is being used, no method specified for model $(typeof(model))")
×
37
end
38

39
"""
40
    Include all [`Model`](model) files in models directory
41
"""
42
const model_path = joinpath(@__DIR__, "models")
43
for path in readdir(model_path; join = true)
44
    if isfile(path)
45
        include(path)
46
    end
47
end
48

49
"""
50
    function get_model(model_name::String)
51

52
Get a [`Model`](model) by name. This function will return the [`Model`](model) with the given name. If no model with the given name exists, this will throw an error.
53

54
# Arguments
55
- `model_name::String`: The name of the [`Model`](model) to get.
56
"""
57
function get_model(model_name::String)
×
58
    return getfield(ModelModule, Symbol(model_name))
×
59
end
60

61
function get_constraints(constraints_dict::Dict{String,Any})
×
62
    constraints = Dict{String,Tuple{Distribution,Unitful.FreeUnits}}()
×
63
    for param in keys(constraints_dict)
×
64
        param_dict = constraints_dict[param]
×
65
        param_unit = uparse(param_dict["UNIT"], unit_context = UNITS)
×
66
        param_prior = getfield(Distributions, Symbol(param_dict["PRIOR"]))
×
67
        param_values = param_dict["VALUES"]
×
68
        param_min = get(param_dict, "MIN", -Inf)
×
69
        param_max = get(param_dict, "MAX", Inf)
×
NEW
70
        prior = Truncated(param_prior(param_values...), param_min, param_max)
×
71
        constraints[param] = (prior, param_unit)
×
72
    end
×
73
    return constraints
×
74
end
75

76
function setup_model(model_dict::Dict{String,Any})
×
77
    model = get_model(model_dict["NAME"])
×
78
    constraints = get_constraints(model_dict["CONSTRAINTS"])
×
79
    return model(constraints)
×
80
end
81

82
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc