Skip to content

Commit 0a1adfc

Browse files
committed
feat: offset Map
docs: add example of "Finding the brightest pixel"
1 parent e691bae commit 0a1adfc

File tree

7 files changed

+66
-8
lines changed

7 files changed

+66
-8
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ authors = ["Beforerr <zzj956959688@gmail.com> and contributors"]
77
projects = ["test", "docs"]
88

99
[deps]
10+
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
1011
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
1112

1213
[compat]
14+
OffsetArrays = "1"
1315
PythonCall = "0.9"
1416
julia = "1.10"

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[deps]
2+
Chairmarks = "0ca39b1e-fe0b-4e98-acfc-b1656634c4de"
23
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
34
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
45
SunPy = "d53ba2b8-6a4a-4633-896a-a050af4da271"

docs/make.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ makedocs(;
2222
"Tutorials" => [
2323
"Coordinates" => "tutorials/coordinates.md",
2424
],
25+
"Example Gallery" => [
26+
"gallery/brightness_pixel_location.md",
27+
],
2528
],
2629
)
2730

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Finding the brightest pixel
2+
3+
Reference: corresponding [sunpy webpage](https://docs.sunpy.org/en/stable/generated/gallery/map/brightness_pixel_location.html).
4+
5+
```@example pixel
6+
using SunPy, PythonCall
7+
using SunPy: Map
8+
@py import sunpy.data.sample: AIA_171_IMAGE
9+
@py import astropy.units as u
10+
11+
aia = Map(AIA_171_IMAGE)
12+
pixel_pos = Tuple(argmax(aia')) .* u.pixel
13+
hpc_max = aia.wcs.pixel_to_world(pixel_pos...)
14+
```
15+
16+
Let’s now plot the results.
17+
18+
```@example pixel
19+
@py import matplotlib.pyplot as plt
20+
21+
fig = plt.figure()
22+
ax = fig.add_subplot(projection=aia)
23+
aia.plot(axes=ax)
24+
ax.plot_coord(hpc_max, "wx", fillstyle="none", markersize=10)
25+
fig
26+
```
27+
28+
29+
## Acceleration
30+
31+
```@repl pixel
32+
using Chairmarks
33+
@py import numpy as np
34+
35+
@b sunpy.map.Map(AIA_171_IMAGE) @py(np.argwhere(_.data == _.data.max()))
36+
@b Map(AIA_171_IMAGE) argmax(_)
37+
```

docs/src/index.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# SunPy
22

3-
Documentation for [SunPy](https://github.com/JuliaSpacePhysics/SunPy.jl).
3+
A Julia wrapper around [SunPy](https://www.sunpy.org).
4+
5+
## Motivation
6+
7+
This package brings SunPy's solar physics capabilities to Julia, enabling:
8+
9+
- **Performant Array manipulation**: Leverage Julia's powerful and flexible array manipulation for accelerated numerical computations
10+
- **Ecosystem integration**: Combine solar data analysis with the broader Julia scientific computing stack (e.g., [SciML](https://sciml.ai/), [JuliaAstro](https://juliaastro.org/home/))
411

512
```@index
613
```
@@ -13,7 +20,7 @@ Modules = [SunPy]
1320

1421
Obtaining solar data using the [`Fido`](https://docs.sunpy.org/en/stable/generated/api/sunpy.net.Fido.html) interface (a unified data search and retrieval tool).
1522

16-
```@example sunpy
23+
```@repl sunpy
1724
using SunPy, PythonCall
1825
@py import sunpy.net: Fido, attrs as a
1926
Fido
@@ -25,7 +32,6 @@ Fido.search(a.Time("2012/3/4", "2012/3/6"), a.Instrument.lyra, a.Level.two)
2532
`Map` object in [sunpy](https://docs.sunpy.org/en/stable/tutorial/maps.html).
2633

2734
```@example sunpy
28-
pyimport("sunpy.data.sample")
29-
sunpy.data.sample.AIA_171_IMAGE
30-
my_map = sunpy.map.Map(sunpy.data.sample.AIA_171_IMAGE)
35+
@py import sunpy.data.sample: AIA_171_IMAGE
36+
my_map = sunpy.map.Map(AIA_171_IMAGE)
3137
```

src/SunPy.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module SunPy
22

33
using PythonCall
4+
using OffsetArrays
5+
using OffsetArrays: Origin
46

57
export sunpy
68

src/types.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,18 @@ struct Map{T, N, A <: AbstractArray{T, N}} <: AbstractArray{T, N}
1818
data::A
1919
end
2020

21-
Base.size(m::Map) = Base.size(m.data)
21+
for f in (:size, :axes)
22+
@eval Base.$f(m::Map) = Base.$f(m.data)
23+
end
24+
2225
Base.getindex(m::Map, args...) = Base.getindex(m.data, args...)
2326
Base.show(io::IO, m::MIME"text/plain", map::Map) = Base.show(io, m, map.py)
2427

2528
function Map(path)
26-
py = sunpy.map.Map(path)
27-
return Map(py, PyArray(py.data; copy = false))
29+
py = (@pyconst sunpy.map.Map)(path)
30+
pyarr = PyArray(@py py.data; copy = false)
31+
return Map(py, Origin(0)(pyarr))
2832
end
33+
34+
@inline Base.getproperty(m::Map, s::Symbol) =
35+
s in fieldnames(Map) ? getfield(m, s) : getproperty(m.py, s)

0 commit comments

Comments
 (0)