Skip to content

Commit

Permalink
Merge pull request #37 from ProjectTorreyPines/add_tool
Browse files Browse the repository at this point in the history
Make translator between grid subset names and indices
  • Loading branch information
anchal-physics authored Mar 20, 2024
2 parents 238d675 + 6099fb3 commit c28f055
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 181 deletions.
324 changes: 162 additions & 162 deletions examples/plotting.ipynb
Original file line number Diff line number Diff line change
@@ -1,163 +1,163 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Plotting examples using GGDUtils\n",
" \n",
" For running this notebook, you need to install package IJulia in your home environment (that is messy, but that is the only way I know right now). So in your terminal:\n",
" ```\n",
" % julia\n",
" julia > ]\n",
" (@v1.9 pkg) pkg> add IJulia\n",
" ```\n",
"\n",
" After this, Julia kernel would appear in your jupyter notebooks as an option. This also works for julia notebooks directly opened on VSCode. Select the Julia kernel to run this notebook."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"using Pkg\n",
"Pkg.activate(\"./\")\n",
"Pkg.add(url=\"[email protected]:ProjectTorreyPines/IMASDD.jl.git\")\n",
"Pkg.develop(path=\"../\")\n",
"Pkg.add(\"Plots\")\n",
"Pkg.add(\"LaTeXStrings\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"using IMASDD\n",
"using GGDUtils\n",
"using Plots\n",
"using LaTeXStrings"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dd = IMASDD.json2imas(\"../samples/time_dep_edge_profiles_last_step_only.json\")\n",
"grid_ggd = dd.edge_profiles.grid_ggd[1]\n",
"space = grid_ggd.space[1]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plotting grid and subsets"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Choose backend\n",
"gr() # Fast and can save pdf\n",
"# plotlyjs() # Use for interactive plot, can only save png\n",
"\n",
"plot(space) # Simply plot the grid described in space, all common arguments to plot can be given here\n",
"\n",
"# You can overlay any subset by giving a second argument\n",
"# Labels \n",
"plot!(space, GGDUtils.get_grid_subset_with_index(grid_ggd, 6), markercolor=:chocolate1)\n",
"plot!(space, GGDUtils.get_grid_subset_with_index(grid_ggd, 7), linecolor=:red, linewidth=2)\n",
"plot!(space, GGDUtils.get_grid_subset_with_index(grid_ggd, 8), linecolor=:darkred, linewidth=2)\n",
"plot!(space, GGDUtils.get_grid_subset_with_index(grid_ggd, 9), linecolor=:limegreen, linewidth=2)\n",
"plot!(space, GGDUtils.get_grid_subset_with_index(grid_ggd, 10), linecolor=:darkgreen, linewidth=2)\n",
"plot!(space, GGDUtils.get_grid_subset_with_index(grid_ggd, 11), linecolor=:cyan, linewidth=2)\n",
"# plot!(space, GGDUtils.get_grid_subset_with_index(grid_ggd, 12), linecolor=:teal, linewidth=1)\n",
"plot!(space, GGDUtils.get_grid_subset_with_index(grid_ggd, 13), linecolor=:royalblue1, linewidth=2)\n",
"plot!(space, GGDUtils.get_grid_subset_with_index(grid_ggd, 14), linecolor=:navyblue, linewidth=2)\n",
"plot!(space, GGDUtils.get_grid_subset_with_index(grid_ggd, 15), linecolor=:fuchsia, linewidth=2, linestyle=:dash)\n",
"plot!(space, GGDUtils.get_grid_subset_with_index(grid_ggd, 16), linecolor=:purple4, linewidth=2, linestyle=:dash)\n",
"plot!(space, GGDUtils.get_grid_subset_with_index(grid_ggd, 101), markershape=:rect, markercolor=:royalblue1)\n",
"# plot!(space, GGDUtils.get_grid_subset_with_index(grid_ggd, 102), markershape=:rect, markercolor=:maroon)\n",
"plot!(space, GGDUtils.get_grid_subset_with_index(grid_ggd, 103), markershape=:diamond, markercolor=:fuchsia)\n",
"plot!(space, GGDUtils.get_grid_subset_with_index(grid_ggd, 104), markershape=:diamond, markercolor=:purple4)\n",
"\n",
"# Legend is supressed unless asked for specifically\n",
"plot!(legend=true)\n",
"# Default labels are subset.identifier.name but can be changed by providing a label argument\n",
"\n",
"# It is recommended to add atleast 10 pt margin to the left to accomodate the y-axis label\n",
"plot!(left_margin=10Plots.pt)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plotting 2D quantities as heatmaps"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Choose backend\n",
"gr() # Fast and can save pdf\n",
"# plotlyjs() # Use for interactive plot, can only save png\n",
"\n",
"n_e = GGDUtils.get_prop_with_grid_subset_index(dd.edge_profiles.ggd[1].electrons.density, 5)\n",
"plot(dd.edge_profiles.grid_ggd, n_e, colorbar_title=\"Electrons density / \" * L\"m^{-3}\",\n",
" left_margin=10Plots.pt)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### You can overlap any grid on top of a quantity"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Choose backend\n",
"gr() # Fast and can save pdf\n",
"# plotlyjs() # Use for interactive plot, can only save png\n",
"\n",
"plot(dd.edge_profiles.grid_ggd, n_e) # Note default label in colorbar\n",
"plot!(space, GGDUtils.get_grid_subset_with_index(grid_ggd, 16), linecolor=:red,\n",
" linewidth=2, linestyle=:solid, label=\"Separatix\", legend=true,\n",
" left_margin=10Plots.pt)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.9.4",
"language": "julia",
"name": "julia-1.9"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.4"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Plotting examples using GGDUtils\n",
" \n",
" For running this notebook, you need to install package IJulia in your home environment (that is messy, but that is the only way I know right now). So in your terminal:\n",
" ```\n",
" % julia\n",
" julia > ]\n",
" (@v1.9 pkg) pkg> add IJulia\n",
" ```\n",
"\n",
" After this, Julia kernel would appear in your jupyter notebooks as an option. This also works for julia notebooks directly opened on VSCode. Select the Julia kernel to run this notebook."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"using Pkg\n",
"Pkg.activate(\"./\")\n",
"Pkg.add(url=\"[email protected]:ProjectTorreyPines/IMASDD.jl.git\")\n",
"Pkg.develop(path=\"../\")\n",
"Pkg.add(\"Plots\")\n",
"Pkg.add(\"LaTeXStrings\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"using IMASDD\n",
"using GGDUtils\n",
"using Plots\n",
"using LaTeXStrings"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dd = IMASDD.json2imas(\"../samples/time_dep_edge_profiles_last_step_only.json\")\n",
"grid_ggd = dd.edge_profiles.grid_ggd[1]\n",
"space = grid_ggd.space[1]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plotting grid and subsets"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Choose backend\n",
"gr() # Fast and can save pdf\n",
"# plotlyjs() # Use for interactive plot, can only save png\n",
"\n",
"plot(space) # Simply plot the grid described in space, all common arguments to plot can be given here\n",
"\n",
"# You can overlay any subset by giving a second argument\n",
"# Labels \n",
"plot!(space, GGDUtils.get_grid_subset(grid_ggd, \"x_points\"), markercolor=:chocolate1)\n",
"plot!(space, GGDUtils.get_grid_subset(grid_ggd, \"core_cut\"), linecolor=:red, linewidth=2)\n",
"plot!(space, GGDUtils.get_grid_subset(grid_ggd, 8), linecolor=:darkred, linewidth=2)\n",
"plot!(space, GGDUtils.get_grid_subset(grid_ggd, 9), linecolor=:limegreen, linewidth=2)\n",
"plot!(space, GGDUtils.get_grid_subset(grid_ggd, 10), linecolor=:darkgreen, linewidth=2)\n",
"plot!(space, GGDUtils.get_grid_subset(grid_ggd, 11), linecolor=:cyan, linewidth=2)\n",
"# plot!(space, GGDUtils.get_grid_subset(grid_ggd, 12), linecolor=:teal, linewidth=1)\n",
"plot!(space, GGDUtils.get_grid_subset(grid_ggd, 13), linecolor=:royalblue1, linewidth=2)\n",
"plot!(space, GGDUtils.get_grid_subset(grid_ggd, 14), linecolor=:navyblue, linewidth=2)\n",
"plot!(space, GGDUtils.get_grid_subset(grid_ggd, 15), linecolor=:fuchsia, linewidth=2, linestyle=:dash)\n",
"plot!(space, GGDUtils.get_grid_subset(grid_ggd, 16), linecolor=:purple4, linewidth=2, linestyle=:dash)\n",
"plot!(space, GGDUtils.get_grid_subset(grid_ggd, 101), markershape=:rect, markercolor=:royalblue1)\n",
"# plot!(space, GGDUtils.get_grid_subset(grid_ggd, 102), markershape=:rect, markercolor=:maroon)\n",
"plot!(space, GGDUtils.get_grid_subset(grid_ggd, 103), markershape=:diamond, markercolor=:fuchsia)\n",
"plot!(space, GGDUtils.get_grid_subset(grid_ggd, 104), markershape=:diamond, markercolor=:purple4)\n",
"\n",
"# Legend is supressed unless asked for specifically\n",
"plot!(legend=true)\n",
"# Default labels are subset.identifier.name but can be changed by providing a label argument\n",
"\n",
"# It is recommended to add atleast 10 pt margin to the left to accomodate the y-axis label\n",
"plot!(left_margin=10Plots.pt)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plotting 2D quantities as heatmaps"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Choose backend\n",
"gr() # Fast and can save pdf\n",
"# plotlyjs() # Use for interactive plot, can only save png\n",
"\n",
"n_e = GGDUtils.get_prop_with_grid_subset_index(dd.edge_profiles.ggd[1].electrons.density, 5)\n",
"plot(dd.edge_profiles.grid_ggd, n_e, colorbar_title=\"Electrons density / \" * L\"m^{-3}\",\n",
" left_margin=10Plots.pt)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### You can overlap any grid on top of a quantity"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Choose backend\n",
"gr() # Fast and can save pdf\n",
"# plotlyjs() # Use for interactive plot, can only save png\n",
"\n",
"plot(dd.edge_profiles.grid_ggd, n_e) # Note default label in colorbar\n",
"plot!(space, GGDUtils.get_grid_subset(grid_ggd, 16), linecolor=:red,\n",
" linewidth=2, linestyle=:solid, label=\"Separatix\", legend=true,\n",
" left_margin=10Plots.pt)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.9.4",
"language": "julia",
"name": "julia-1.10"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.4"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
6 changes: 3 additions & 3 deletions src/interpolations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function interp(
grid_ggd::IMASDD.edge_profiles__grid_ggd,
value_field::Symbol=:values,
)
subset = get_grid_subset_with_index(grid_ggd, prop.grid_subset_index)
subset = get_grid_subset(grid_ggd, prop.grid_subset_index)
space = grid_ggd.space[subset.element[1].object[1].space]
return interp(getfield(prop, value_field), space, subset)
end
Expand Down Expand Up @@ -281,13 +281,13 @@ function interp(
value_field::Symbol=:values,
) where {T <: edge_profiles__prop_on_subset}
prop = get_prop_with_grid_subset_index(prop_arr, grid_subset_index)
subset = get_grid_subset_with_index(grid_ggd, grid_subset_index)
subset = get_grid_subset(grid_ggd, grid_subset_index)
space = grid_ggd.space[subset.element[1].object[1].space]
return interp(getfield(prop, value_field), space, subset)
end

function get_TPS_mats(grid_ggd::IMASDD.edge_profiles__grid_ggd, grid_subset_index::Int)
subset = get_grid_subset_with_index(grid_ggd, grid_subset_index)
subset = get_grid_subset(grid_ggd, grid_subset_index)
space = grid_ggd.space[subset.element[1].object[1].space]
return get_TPS_mats(space, subset)
end
Expand Down
2 changes: 1 addition & 1 deletion src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ end
grid_ggd::IMASDD.edge_profiles__grid_ggd,
prop::IMASDD.IDSvectorElement,
)
subset = get_grid_subset_with_index(grid_ggd, prop.grid_subset_index)
subset = get_grid_subset(grid_ggd, prop.grid_subset_index)
space = grid_ggd.space[subset.element[1].object[1].space]
nodes = space.objects_per_dimension[1].object
cells = space.objects_per_dimension[3].object
Expand Down
Loading

0 comments on commit c28f055

Please sign in to comment.