# Python map\_coordinates() equivalent in Julia

**URL:** https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461
**Category:** General Usage
**Tags:** question, interpolations
**Created:** [July 25, 2024, 10:14am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461 "2024-07-25T10:14:51Z")
**Posts on this page:** 10
**Page:** 2

<div class="post-metadata">

### Author: ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)
#### Post date: [July 31, 2024, 9:05am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/21 "2024-07-31T09:05:35Z")

</div>

No, I will not debug a 300+ lines of code for you. You basically ask me to finish you task. And You have not yet posted whether you have tried changing `(r_grid_stream_pix, theta_grid_stream_pix)`to `[r_grid_stream_pix, theta_grid_stream_pix]` in you function call, which I suspect is the fix. if it is, I would be a bit angry at this point.

_edit:_ Are you kidding me? The linked file does contain `datafile ="./home/raman/Pictures/sane00.athinput/"` that In no way runs on my machine. How much work do you expect me to put in to get that to run on my machine? And do I then get your salary?

---

<div class="post-metadata">

### Author: ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)
#### Post date: [July 31, 2024, 9:23am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/22 "2024-07-31T09:23:51Z")

</div>

Hi @kellertuer Earlier i have tried using `Vector(r_grid_stream_pix, theta_grid_stream_pix)` but that didn’t work. Now on doing `[r_grid_stream_pix, theta_grid_stream_pix]` i am getting error:

```julia-auto
ERROR: LoadError: MethodError: no method matching (::var"#map_coordinates#3"{var"#map_coordinates#1#4"})(::Matrix{Float64}, ::Vector{Matrix{Float64}})
Stacktrace:
 [1] main()
   @ Main ~/Fluxes.jl:278
 [2] top-level scope
   @ ~/Fluxes.jl:358
in expression starting at /home/raman/Fluxes.jl:358

```

> [@kellertuer](#):
>
> The linked file does contain `datafile ="./home/raman/Pictures/sane00.athinput/"` that In no way runs on my machine.

You have to specify the location where you have downloaded that folder.

---

<div class="post-metadata">

### Author: ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)
#### Post date: [July 31, 2024, 9:29am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/23 "2024-07-31T09:29:15Z")

</div>

Tha is not how this works.  
Please read (already linked, but I am not sure you read it)

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

point 4.

I will especially not download source code, files and do a full setup of stuff to maybe reproduce your error locally – because it might also just be that our setups are different or so.

For the error you currently get: Yes, that tells you that the two elements of your vector are matrices and the function we already wrote for you expects a vector of two SVectors.

So maybe think about how you can turn your two matrices into SVectors. That is probably domain specific.

In general, this interpretation of the error message is no magic, please learn how to read them, then you can infer that yourself.

---

<div class="post-metadata">

### Author: ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)
#### Post date: [July 31, 2024, 10:14am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/24 "2024-07-31T10:14:03Z")

</div>

I tried using `theta_grid_stream_pix = [SVector(theta_grid_stream_pixar[i, :])(zeros(1000,50)) for i in 1:size(theta_grid_stream_pixar, 1)]`  
to convert matrix to SVector but i got

> **Error Message**
>
> ```julia
> ERROR: LoadError: The size of type `SVector` is not known.
> 
> If you were trying to construct (or `convert` to) a `StaticArray` you
> may need to add the size explicitly as a type parameter so its size is
> inferrable to the Julia compiler (or performance would be terrible). For
> example, you might try
> 
> m = zeros(3,3)
> SMatrix(m) # this error
> SMatrix{3,3}(m) # correct - size is inferrable
> SArray{Tuple{3,3}}(m) # correct, note Tuple{3,3}
> 
> Stacktrace:
> [1] error(s::String)
> @ Base ./error.jl:35
> [2] missing_size_error(::Type{SVector})
> @ StaticArraysCore ~/.julia/packages/StaticArraysCore/7xxEJ/src/StaticArraysCore.jl:500
> [3] Size(::Type{SVector})
> @ StaticArraysCore ~/.julia/packages/StaticArraysCore/7xxEJ/src/StaticArraysCore.jl:517
> [4] length(a::Type{SVector})
> @ StaticArrays ~/.julia/packages/StaticArrays/MSJcA/src/abstractarray.jl:2
> [5] convert
> @ ~/.julia/packages/StaticArrays/MSJcA/src/convert.jl:208 [inlined]
> [6] StaticArray
> @ ~/.julia/packages/StaticArrays/MSJcA/src/convert.jl:182 [inlined]
> [7] (::var"#1#5"{Matrix{Float64}})(i::Int64)
> @ Main ./none:0
> [8] iterate
> @ ./generator.jl:47 [inlined]
> [9] collect(itr::Base.Generator{UnitRange{Int64}, var"#1#5"{Matrix{Float64}}})
> @ Base ./array.jl:834
> [10] main()
> @ Main ~/Fluxes.jl:235
> [11] top-level scope
> @ ~/Fluxes.jl:358
> in expression starting at /home/raman/Fluxes.jl:358
> 
> ```

I am using `zeros(1000,50)` to provide `m` mentioned in error output.

---

<div class="post-metadata">

### Author: ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)
#### Post date: [July 31, 2024, 10:17am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/25 "2024-07-31T10:17:29Z")

</div>

Sorry, but that error message even has an example where the error comes from and how to fix that?!

You can not just call `SVector(X)` you have to provide the size explicitly, so if `n= length(X)` you can do `SVector{n}(X)`. This is _exactly_ even with an example the error message tells you.  
So _please_ read your error messages and start working on fixing those yourself – especially when the error message explicitly tells you how to fix that.

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [July 31, 2024, 10:21am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/26 "2024-07-31T10:21:15Z")

</div>

All of your issues ultimately stem from the fact that you still appear to lack a basic understanding of how Julia works. It would probably be useful to go through the Julia manual and some tutorials. There’s a lot of resources here:

> **[Get started with Julia](https://julialang.org/learning/)**
>
> The official website for the Julia Language. Julia is a language that is fast, dynamic, easy to use, and open source. Click here to learn more.

or watch a video maybe:

[![](https://global.discourse-cdn.com/julialang/original/3X/c/7/c7aeb4cdb56cacf82c0dbf59ea6d0ea7592109a7.jpeg "Learn Julia in 4 hours in 4K | Full Course | Julia for Absolute Beginners") ](https://www.youtube.com/watch?v=KlorfxsdWDw)

If you insist on continuing with your approach of just blindly changing things around and then asking for help with error messages, I’d suggest that an AI assistant like ChatGPT or Claude might be a better discussion partner for that than this forum.

---

<div class="post-metadata">

### Author: ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)
#### Post date: [July 31, 2024, 3:53pm UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/27 "2024-07-31T15:53:16Z")

</div>

I have already watched videos of _Doggo_ channel.

> [@kellertuer](#):
>
> You can not just call `SVector(X)` you have to provide the size explicitly, so if `n= length(X)` you can do `SVector{n}(X)`.

Now i am getting error due to `SVector` definition. `theta_grid_stream_pix = [SVector{n}(theta_grid_stream_pixar[i, :]) for i in 1:size(theta_grid_stream_pixar, 1)]`

```julia-auto
("lina, T[lina], T[ntheta-1]=", 1, <py np.float64(0.03681553890925539)>, <py np.float64(3.129320807286708)>)
("phic, P[phic], P[nphi-1]=", 1, <py np.float64(0.14726215563702155)>, <py np.float64(6.234097921967246)>)
zsh: killed julia Fluxes.jl

```

---

<div class="post-metadata">

### Author: ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)
#### Post date: [August 3, 2024, 4:08am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/28 "2024-08-03T04:08:58Z")

</div>

I changed `SVector` part to segments or chunks to overcome memory issue. But still my programme gets **killed**.

```julia
# Define the chunk size
    chunk_size = 100
# Initialize the resulting array
    theta_grid_stream_pix = Vector{SVector{n, Float64}}(undef, size(theta_grid_stream_pixar, 1))

# Process in chunks
	for i in 1:chunk_size:size(theta_grid_stream_pixar, 1)
  	  chunk_end = min(i + chunk_size - 1, size(theta_grid_stream_pixar, 1))
  	   for j in i:chunk_end
           theta_grid_stream_pix[j] = SVector{n}(theta_grid_stream_pixar[j, :])
       end
	end

```

---

<div class="post-metadata">

### Author: ![Michele878](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@Michele878](https://discourse.julialang.org/u/Michele878)
#### Post date: [August 3, 2024, 7:21am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/29 "2024-08-03T07:21:48Z")

</div>

In Julia, you can use the Interpolations package to achieve functionality similar to Python’s map\_coordinates from the scipy.ndimage module. The Interpolations package allows for interpolation of multidimensional data, which is what map\_coordinates does.

---

<div class="post-metadata">

### Author: ![Michele878](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@Michele878](https://discourse.julialang.org/u/Michele878)
#### Post date: [August 4, 2024, 8:53am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/30 "2024-08-04T08:53:42Z")

</div>

thanks for sharing.[.](https://ncedcloud.fun/).

[Previous page](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461.md?page=1)
