Skip to content

Commit

Permalink
Replace glob with native Julia
Browse files Browse the repository at this point in the history
  • Loading branch information
henry2004y committed Feb 2, 2024
1 parent 571dfe0 commit 3719b92
Show file tree
Hide file tree
Showing 25 changed files with 56 additions and 51 deletions.
4 changes: 2 additions & 2 deletions docs/examples/postprocess/demo_convert2vti.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

To convert VLSV time series files to VTK image files using multithreads,
```julia
using Vlasiator, Glob
using Vlasiator

files = glob("*.vlsv")
files = filter(endswith(".vlsv"), readdir())

Threads.@threads for file in files
@info file, Threads.threadid()
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/postprocess/demo_em_extract_slice.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

To save Epar, Eperp, B in a selected slice region from 3D VLSV outputs,
```julia
using Vlasiator, Glob
using Vlasiator
using JLD2: jldsave
using StaticArrays
using LinearAlgebra: norm
Expand Down Expand Up @@ -66,7 +66,7 @@ function main()
outdir = "EM/"
outfile = "EM.jld2"

files = glob("bulk1.*vlsv", directory)
files = filter(contains(r"^bulk.*\.vlsv$"), readdir(directory))
# Only orthogonal slices are supported
normal = :y # (:x, :y, :z)
origin = 0.0
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/postprocess/demo_lineextracting_mt.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

To extract variables along a line across multiple frames using multithreads,
```julia
using Vlasiator, Glob
using Vlasiator
using JLD2: jldsave

function main()
files = glob("bulk*.vlsv", ".")
files = filter(contains(r"^bulk.*\.vlsv$"), readdir())
nfile = length(files)
# Define end points of the line in Earth radius
x1, x2 = 6.0, 20.0
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/postprocess/demo_magnetopause_2d_mt.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ JULIA_NUM_THREADS=4 julia demo_magnetopause_2d_mt.jl
```

```julia
using Vlasiator, Glob
using Vlasiator
using Vlasiator: RE # Earth radius, [m]
using JLD2: jldsave

Expand Down Expand Up @@ -79,7 +79,7 @@ end

######

files = glob("bulk*.vlsv", ".")
files = filter(contains(r"^bulk.*\.vlsv$"), readdir())

@time z,x,v,ey = extract_magnetopause_var(files)

Expand Down
4 changes: 2 additions & 2 deletions docs/examples/postprocess/demo_pointextracting.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ JULIA_NUM_THREADS=nthreads julia demo_virtual_satellite.jl
```

```julia
using Glob, DelimitedFiles, Vlasiator, DataFrames
using DelimitedFiles, Vlasiator, DataFrames
using Vlasiator: RE # Earth radius [m]

function extract_vars(files, loc)
Expand Down Expand Up @@ -54,7 +54,7 @@ end

#####

files = glob("bulk*.vlsv", "./")
files = filter(contains(r"^bulk.*\.vlsv$"), readdir())

# virtual satellite location
const loc = Float64[12, 0, 0] .* RE
Expand Down
7 changes: 5 additions & 2 deletions docs/examples/postprocess/demo_pointsextracting.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ This demo shows how to extract data for virtual satellites at multiple locations
Outputs are stored in binary format for sharing within Julia.

Usage:

```shell
julia -t nthreads demo_pointsextracting.jl
```

or

```shell
JULIA_NUM_THREADS=nthreads julia demo_pointsextracting.jl
```

```julia
using Glob, Vlasiator
using Vlasiator
using Vlasiator: RE # Earth radius, [m]
using JLD2: jldsave

Expand Down Expand Up @@ -59,7 +62,7 @@ end

#####

files = glob("bulk*.vlsv", "./")
files = filter(contains(r"^bulk.*\.vlsv$"), readdir())

# virtual satellite locations
const locations = [[7RE, 0, 0], [9RE, 0, 0], [11RE, 0, 0], [12RE, 0, 0],
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/postprocess/demo_pointsextracting_2d_uniform.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This demo shows how to extract data for virtual satellites at uniformly sampled
Outputs are stored in binary format for sharing within Julia.

```julia
using Glob, Vlasiator
using Vlasiator
using JLD2: jldsave

"Select cells in 2D `meta` with uniform distance `dx`."
Expand Down Expand Up @@ -74,7 +74,7 @@ end

#####

files = glob("bulk*.vlsv", "./")
files = filter(contains(r"^bulk.*\.vlsv$"), readdir())

const dx = 5RE # uniform sampling distance [m]

Expand Down
4 changes: 2 additions & 2 deletions docs/examples/postprocess/demo_wave_satellite_mt.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ JULIA_NUM_THREADS=4 julia demo_wave_satellite_mt.jl
```julia
using Statistics: mean
using LinearAlgebra: , normalize!, norm
using DSP, PyPlot, Glob
using DSP, PyPlot
using Vlasiator
using Vlasiator: μ₀, mᵢ, RE
using Polyester
Expand Down Expand Up @@ -114,7 +114,7 @@ function align_yaxis(ax1, ax2)
end

function main()
files = glob("bulk*.vlsv", ".")
files = filter(contains(r"^bulk.*\.vlsv$"), readdir())

# virtual satellite location
loc = [12Vlasiator.RE, 0, 0]
Expand Down
7 changes: 4 additions & 3 deletions docs/examples/postprocess/demo_wave_search_mt.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ JULIA_NUM_THREADS=4 julia demo_wave_search_mt.jl
```

```julia
using Glob, Vlasiator, PyPlot, LaTeXStrings
using Vlasiator, PyPlot, LaTeXStrings

"Extract time series variable"
function extract_var(files, ncells, varname, component=0)
Expand Down Expand Up @@ -147,7 +147,8 @@ function plot_dist(files, varnames, varnames_print, components, Δt, nboxlength;
for i in eachindex(varnames)
outdir = "../out/$(lowercase(varnames_print[i]))"
!isdir(outdir) && mkdir(outdir)
length(glob("spatial*.png", outdir)) == length(files) - nboxlength + 1 && continue
length(filter(contains(r"^spatial.*\.png$"), readdir(outdir))) ==
length(files) - nboxlength + 1 && continue

# Obtain time series data
var = extract_var(files, ncells, varnames[i], components[i])
Expand Down Expand Up @@ -181,7 +182,7 @@ function main()
nplotstride = 50 # plot intervals in frames
dir = "./" # data directory

files = glob("bulk*.vlsv", dir)
files = filter(contains(r"^bulk.*\.vlsv$"), readdir(dir))

println("Total number of snapshots: $(length(files))")
println("Running with $(Threads.nthreads()) threads...")
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/postprocess/demo_wave_tracing_mt.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ JULIA_NUM_THREADS=4 julia demo_wave_tracing_mt.jl
```julia
using Vlasiator, VlasiatorPyPlot
using Vlasiator: qᵢ, μ₀, c, mᵢ, ϵ₀, RE
using Glob, DSP, FFTW, ImageFiltering, Interpolations
using DSP, FFTW, ImageFiltering, Interpolations
using Statistics: mean
using LinearAlgebra

Expand Down Expand Up @@ -397,7 +397,7 @@ function main()
components = [0, 3, 1, 0] # 0 for scalar, 1-3 for vector components

dir = "../run_rho2_bz-5_timevarying_startfrom300s"
files = glob("bulk.*.vlsv", dir)
files = filter(contains(r"^bulk.*\.vlsv$"), readdir(dir))

vars = Variables(varnames, varnames_print, components)

Expand Down
4 changes: 2 additions & 2 deletions docs/examples/postprocess/demo_x_points_extracting.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ save the coordinates as well as extracted reconnection rate Ey from multiple out
Here we assume a X-Z plane.
```julia
using JLD2: jldsave
using Vlasiator, Glob, ProgressMeter
using Vlasiator, ProgressMeter

function main()
files = glob("bulk*.vlsv", ".")
files = filter(contains(r"^bulk.*\.vlsv$"), readdir())

nG = 2 # number of ghost cells

Expand Down
4 changes: 2 additions & 2 deletions docs/examples/visualization/demo_1d2d_mp_pyplot.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ julia -p $ncores demo_1d2d_mp_pyplot.jl
```

```julia
using Distributed, Glob
using Distributed
@everywhere using Vlasiator, VlasiatorPyPlot, Printf, LaTeXStrings

@assert matplotlib.__version__ "3.4" "Require Matplotlib version 3.4+ to use subfigure!"
Expand Down Expand Up @@ -225,7 +225,7 @@ end
end

################################################################################
files = glob("bulk*.vlsv", ".")
files = filter(contains(r"^bulk.*\.vlsv$"), readdir())

nfile = length(files)
# Set output directory
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/visualization/demo_1d2d_pyplot.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

To generate combined 1D/2D plots across multiple frames,
```julia
using Vlasiator, VlasiatorPyPlot, Glob, Printf, LaTeXStrings
using Vlasiator, VlasiatorPyPlot, Printf, LaTeXStrings
using Vlasiator: set_args, prep2d

@assert VERSION v"1.7.0" "Compatible with Julia v1.7+!"
Expand Down Expand Up @@ -207,7 +207,7 @@ end

####### Main

files = glob("bulk*.vlsv", ".")
files = filter(contains(r"^bulk.*\.vlsv$"), readdir())
nfile = length(files)
# Set output directory
const outdir = "out/"
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/visualization/demo_1d_animation_pyplot.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

This example demonstrates 1D plot animation. `ffmpeg` is required to be installed for saving into mp4.
```julia
using Vlasiator, Glob, VlasiatorPyPlot, Printf
using Vlasiator, VlasiatorPyPlot, Printf
using PyCall
@pyimport matplotlib.animation as anim

files = glob("bulk.*.vlsv", ".")
files = filter(contains(r"^bulk.*\.vlsv$"), readdir())
# Choose plotting variable
const var = "proton/vg_rho"
const comp = 0 # component of vector, if used
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/visualization/demo_2d_animation_pyplot.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
This example shows how to plot 2D colored contours with `pcolormesh`.
`ffmpeg` is required to be installed for saving into mp4.
```julia
using Vlasiator, Glob, VlasiatorPyPlot, Printf
using Vlasiator, VlasiatorPyPlot, Printf
using PyCall
@pyimport matplotlib.animation as anim

files = glob("bulk*.vlsv", ".")
files = filter(contains(r"^bulk.*\.vlsv$"), readdir())
const var = "proton/vg_rho"
const comp = 0 # vector component for plotting (if applicable)

Expand Down
4 changes: 2 additions & 2 deletions docs/examples/visualization/demo_2d_mp_pyplot.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ julia -p $ncores demo_2d_mp_pyplot.jl
```

```julia
using Distributed, ParallelDataTransfer, Glob
using Distributed, ParallelDataTransfer
@everywhere using Vlasiator, VlasiatorPyPlot, Printf, LaTeXStrings

@everywhere function init_figure(cmaps, norms, ticks, pArgs1, extent)
Expand Down Expand Up @@ -135,7 +135,7 @@ end
end

################################################################################
files = glob("bulk*.vlsv", ".")
files = filter(contains(r"^bulk.*\.vlsv$"), readdir())

nfile = length(files)
# Set output directory
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/visualization/demo_2dcontourseries_pyplot.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
This script creates contours from a series of input files with a fixed color range.
Combined with `ffmpeg`, we can easily make animations from data.
```julia
using Vlasiator, Glob, VlasiatorPyPlot, Printf
using Vlasiator, VlasiatorPyPlot, Printf

files = glob("bulk*.vlsv")
files = filter(contains(r"^bulk.*\.vlsv$"), readdir())
nfile = length(files)
# Set output directory
const outdir = "out/"
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/visualization/demo_B_fieldline_mp_pyplot.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ julia -p $ncores demo_fieldline_mp_pyplot.jl
```

```julia
using Distributed, ParallelDataTransfer, Glob
using Distributed, ParallelDataTransfer
@everywhere using Vlasiator, VlasiatorPyPlot, PyCall, Printf, LaTeXStrings, FieldTracer
@everywhere using Vlasiator: RE

Expand Down Expand Up @@ -128,7 +128,7 @@ end
end

################################################################################
files = glob("bulk*.vlsv", ".")
files = filter(contains(r"^bulk.*\.vlsv$"), readdir())

nfile = length(files)
# Set output directory
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/visualization/demo_bowshock_2d_mt.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ JULIA_NUM_THREADS=$nthreads julia demo_bowshock_2d_mt.jl
```

```julia
using Vlasiator, Glob
using Vlasiator
using Vlasiator: RE # Earth radius, [m]
using JLD2: jldsave

Expand Down Expand Up @@ -63,7 +63,7 @@ function extract_bowshock_position(files; verbose=true)
end

#####
files = glob("bulk*.vlsv", ".")
files = filter(contains(r"^bulk.*\.vlsv$"), readdir())

@time x_crossing, y_crossing = extract_bowshock_position(files)

Expand Down
4 changes: 2 additions & 2 deletions docs/examples/visualization/demo_lineextracting_mp_pyplot.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ julia -p $ncores demo_vars_extracting_mp.jl
```

```julia
using Distributed, ParallelDataTransfer, Glob
using Distributed, ParallelDataTransfer
using Vlasiator: RE
@everywhere using Vlasiator, PyPlot, Printf

Expand Down Expand Up @@ -116,7 +116,7 @@ end
end

################################################################################
files = glob("bulk*.vlsv", ".")
files = filter(contains(r"^bulk.*\.vlsv$"), readdir())
nfile = length(files)

const x1, x2 = 8.0, 29.0
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/visualization/demo_lineextracting_pyplot.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

This demo shows how to plot variables along a line.
```julia
using Vlasiator, PyPlot, Glob, Printf
using Vlasiator, PyPlot, Printf
using Vlasiator: RE # Earth radius [m]

function main()
files = glob("bulk*.vlsv", ".")
files = filter(contains(r"^bulk.*\.vlsv$"), readdir())
nfiles = length(files)

x1, x2 = 8.0, 29.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ This demo shows how to extract data alone a line across frames.
This can be made faster by updating the data without deleting the lines.

```julia
using Vlasiator, Glob, PyPlot, Printf
using Vlasiator, PyPlot, Printf
using Vlasiator: RE # Earth radius, [m]

function main()
files = glob("run4/bulk*.vlsv")
files = filter(contains(r"^bulk.*\.vlsv$"), readdir())

point1 = [0e8, 0, 0]
point2 = [1.9e8, 0, 0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

This demo shows how to plot pressure along a line across multiple frames.
```julia
using Vlasiator, PyPlot, Glob, Printf
using Vlasiator, PyPlot, Printf
using Vlasiator: RE # Earth radius [m]

function main()
files = glob("bulk*.vlsv", ".")
files = filter(contains(r"^bulk.*\.vlsv$"), readdir())
nfile = length(files)

x1, x2 = 8.0, 29.0
Expand Down
Loading

0 comments on commit 3719b92

Please sign in to comment.