Skip to content

Commit

Permalink
Reorganized files so that each file is a module
Browse files Browse the repository at this point in the history
Some files have changed names because there were name conflicts (e.g.,
the module `OutputVar`, the function `OutputVar`, and the struct
`OutputVar`).
  • Loading branch information
Sbozzolo committed Jun 25, 2024
1 parent 03fa3e4 commit f04f69d
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 16 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
ClimaAnalysis.jl Release Notes
===============================

v0.5.4
------
- Reorganized internal modules so that each file is a module.

v0.5.3
------
- Add `Visualize.contour2D_on_globe!` for discrete contours.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.5.3"
[deps]
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[weakdeps]
Expand All @@ -26,6 +27,7 @@ NCDatasets = "0.13.1, 0.14"
OrderedCollections = "1.3"
SafeTestsets = "0.1"
Statistics = "1"
Reexport = "1"
Test = "1"
julia = "1.9"

Expand Down
2 changes: 1 addition & 1 deletion ext/CairoMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function _sliced_plot_generic(
var_sliced = var

for (dim_name, val) in cut
var_sliced = ClimaAnalysis._slice_general(var_sliced, val, dim_name)
var_sliced = ClimaAnalysis.Var._slice_general(var_sliced, val, dim_name)
end

func(fig, var_sliced; p_loc, more_kwargs)
Expand Down
10 changes: 6 additions & 4 deletions src/ClimaAnalysis.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
module ClimaAnalysis
using Reexport

include("Utils.jl")
import .Utils

include("OutputVar.jl")
include("SimDir.jl")
import .SimDir
include("Var.jl")
@reexport using .Var
include("Sim.jl")
@reexport using .Sim

include("Visualize.jl")
import .Visualize
@reexport using .Visualize

end # module ClimaAnalysis
7 changes: 7 additions & 0 deletions src/SimDir.jl → src/Sim.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
module Sim

import Base: get

export SimDir, available_vars, available_reductions, available_periods

import ..Utils
import ..Var: read_var

"""
SimDir(simulation_path::String)
Expand Down Expand Up @@ -191,3 +196,5 @@ end
Check if the given SimDir contains OutputVars.
"""
Base.isempty(simdir::SimDir) = isempty(simdir.vars)

end
16 changes: 10 additions & 6 deletions src/OutputVar.jl → src/Var.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module Var

import NCDatasets
import OrderedCollections: OrderedDict

import Statistics: mean

import .Utils: nearest_index, seconds_to_prettystr
import ..Utils: nearest_index, seconds_to_prettystr, squeeze

export OutputVar,
read_var,
Expand All @@ -17,7 +19,10 @@ export OutputVar,
slice,
window,
arecompatible,
center_longitude!
center_longitude!,
short_name,
long_name,
units

"""
Representing an output variable
Expand Down Expand Up @@ -184,10 +189,7 @@ function _reduce_over(
dim_index = var.dim2index[dim]

# squeeze removes the unnecessary singleton dimension
data = Utils.squeeze(
reduction(var.data, dims = dim_index),
dims = (dim_index,),
)
data = squeeze(reduction(var.data, dims = dim_index), dims = (dim_index,))

# If we reduce over a dimension, we have to remove it
dims = copy(var.dims)
Expand Down Expand Up @@ -518,3 +520,5 @@ end
@overload_binary_op (-)
@overload_binary_op (*)
@overload_binary_op (/)

end
2 changes: 2 additions & 0 deletions src/Visualize.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Visualize

export plot!

function heatmap2D! end

function sliced_heatmap! end
Expand Down
10 changes: 5 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ using Test
@safetestset "Docstrings" begin @time include("doctest.jl") end
@safetestset "Format" begin @time include("format.jl") end

@safetestset "Utils" begin @time include("Utils.jl") end
@safetestset "SimDir" begin @time include("SimDir.jl") end
@safetestset "OutputVar" begin @time include("OutputVar.jl") end
@safetestset "CairoMakieExt" begin @time include("CairoMakieExt.jl") end
@safetestset "GeoMakieExt" begin @time include("GeoMakieExt.jl") end
@safetestset "Utils" begin @time include("test_Utils.jl") end
@safetestset "SimDir" begin @time include("test_Sim.jl") end
@safetestset "OutputVar" begin @time include("test_Var.jl") end
@safetestset "CairoMakieExt" begin @time include("test_CairoMakieExt.jl") end
@safetestset "GeoMakieExt" begin @time include("test_GeoMakieExt.jl") end
#! format: on

nothing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit f04f69d

Please sign in to comment.