This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const x = 1.0 ; | |
function foo(y) | |
println("x = ", x) | |
end | |
foo("a string") # should print "x = 1.0" | |
# Invoking foo just JIT-compiled foo to use x = 1.0 if the argument is a string. | |
x = 2.0 ; # modify constant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using DualNumbers, LinearAlgebra, SparseArrays, SuiteSparse | |
n = 10 | |
A = randn(n, n) # a real-valued matrix | |
B = randn(n, n) # another real-valued matrix | |
# Create a dual-valued matrix | |
M = A + ε * B | |
# And a sparse version of it |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mutable struct ThreeVec <: AbstractVector{Float64} | |
x::Float64 | |
y::Float64 | |
z::Float64 | |
end | |
Base.size(V::ThreeVec) = (3,) | |
Base.IndexStyle(::Type{<:ThreeVec}) = IndexLinear() | |
using Match | |
Base.getindex(V::ThreeVec, i::Int) = @match i begin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using VegaLite, DataFrames | |
df = DataFrame(x = [0, 1, 2, 3, 4, 0, 1, 2, 3, 4], y = 1:10, style = ["A", "A", "A", "A", "A", "B", "B", "B", "B", "B"]) | |
list_styles = ["B", "A"] | |
mycolors = ["#000000", "#ee00ff"] | |
p = df |> | |
@vlplot( | |
mark={ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Load packages | |
using DualMatrixTools, DualNumbers, SparseArrays | |
# 2. Create a random dual-valued vector x | |
n = 10 | |
a, b = rand(n), rand(n) # real and dual parts | |
x = a + ε * b # dual-valued x | |
# 3. Create a sparse random dual-valued matrix M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Makie | |
using GeometryTypes | |
wet3d = falses(2, 2, 2) | |
wet3d[[1, 2, 3, 5, 6]] .= true | |
shoebox3d = permutedims(wet3d, [2, 1, 3]) | |
mycolor(x) = x ? RGBAf0(0,0,1,0.4) : RGBAf0(0.5,0.5,0,1) | |
Ind = CartesianIndices(size(shoebox3d)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
length(ARGS) == 1 && (sheet = "Sheet1") | |
# Use the installed packages | |
using ExcelFiles, DataFrames, Interpolations | |
# Replace by your file with just the data! | |
df = DataFrame(load(abspath(ARGS[1]), sheet)) | |
println("Resampling $(ARGS[1]) - $sheet") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ENV["MPLBACKEND"]="qt5agg" | |
"qt5agg" | |
using PyPlot, PyCall | |
clf() | |
ax = subplot(projection=ccrs.NearsidePerspective(central_latitude=10.0, central_longitude=170.0, satellite_height=100000000.0)) | |
ax.add_feature(cfeature.NaturalEarthFeature("physical", "ocean", "50m", edgecolor="face", facecolor="#4063d8")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using SparseArrays, LinearAlgebra, SuiteSparse | |
using Unitful | |
""" | |
elunit(x) | |
Returns the unit of the elements of `x`. | |
(Returns a `Unitful.FreeUnits{(),NoDims,nothing}` object `x`'s unit is heterogeneous.) | |
""" | |
elunit(::SparseMatrixCSC{U,Int64}) where {U<:Quantity} = unit(U) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load World Ocean Atlas 2D fields for PO₄, Si(OH)₄, and NO₄ | |
using WorldOceanAtlasTools | |
product_year = 2018 | |
tracer = "p" | |
period = 0 | |
resolution = "1°" | |
ds = WorldOceanAtlasTools.WOA_Dataset(product_year, tracer, period, resolution, verbose=false) ; | |
field = "an" | |
field3D, lat, lon, depth = WorldOceanAtlasTools.get_gridded_3D_field(ds, tracer, field) ; | |
map_2D = field3D[:,:,1] ; |