# Coordinate Transformation on mass density

**URL:** https://discourse.julialang.org/t/coordinate-transformation-on-mass-density/51040
**Category:** General Usage
**Created:** [December 1, 2020, 10:24am UTC](https://discourse.julialang.org/t/coordinate-transformation-on-mass-density/51040 "2020-12-01T10:24:00Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [December 1, 2020, 10:24am UTC](https://discourse.julialang.org/t/coordinate-transformation-on-mass-density/51040/1 "2020-12-01T10:24:00Z")

</div>

I have a mass density, which comes from measurement and is represented by a cartesian grid and the average density over each grid cell.

I need to do some computations with this density. The final computation output of the computation represents again cell averages over the same grid. However for the internals of the computation, I need to pass to a spherical coordinate system.

Numerical there are many variants of transforming a density. A property I would really like to have is that  
transforming a density to spherical and back is very close to the original density.

The kind of algorithms I tried so far is to just transform cell centers and then use `Interpolations.jl` (e.g. `Gridded(Linear()), Gridded(Constant())`). However with these the error between a density and a density transformed back and forth is too big.

Any recommendations? Julia packages or algorithms?

---

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [December 1, 2020, 1:19pm UTC](https://discourse.julialang.org/t/coordinate-transformation-on-mass-density/51040/2 "2020-12-01T13:19:49Z")

</div>

Given a diffeomorphism `f : X -> Y` between manifolds, we want numerical approximations `F, G` of the pullbacks along `f` and `g = f⁻¹`. One hacky way to guarantee `G ∘ F = id` is to make the grid on `X` fine enough and using nearest neighbor interpolation. Of course this has a lot of other bad properties. In particular `F∘G` is a projection and not the identity.

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [December 1, 2020, 1:48pm UTC](https://discourse.julialang.org/t/coordinate-transformation-on-mass-density/51040/3 "2020-12-01T13:48:47Z")

</div>

It might be necessary to understand why the grid points must be different in the spherical coordinate system and the Cartesian system. From outside one could imagine that there might be solutions in which we keep the same points, and define interpolation functions for each of the coordinate systems if intermediate points are required, but without propagating the interpolation errors.

---

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [December 1, 2020, 2:20pm UTC](https://discourse.julialang.org/t/coordinate-transformation-on-mass-density/51040/4 "2020-12-01T14:20:52Z")

</div>

Yes good question. Some of the spherical processing is done by libraries, that work best on just an array of values and a uniform spherical grid. So if there is a better pair of transforms, that would be the path of least work for me.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [December 1, 2020, 5:47pm UTC](https://discourse.julialang.org/t/coordinate-transformation-on-mass-density/51040/5 "2020-12-01T17:47:20Z")

</div>

> [@jw3126](#):
>
> Some of the spherical processing is done by libraries, that work best on just an array of values and a uniform spherical grid.

What kind of spherical processing do you need? I’m wondering how hard it would be to rewrite it to work directly with the Cartesian data.

---

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [December 3, 2020, 8:41am UTC](https://discourse.julialang.org/t/coordinate-transformation-on-mass-density/51040/6 "2020-12-03T08:41:23Z")

</div>

Imagine there is a source of radiation at one point and I am interested in how much radiation arrives at each point in space. There are many places, where a spherical grid is advantageous, but here is one example. We need to know the amount of matter between the origin of radiation and each point in space. In cartesian coordinates, I do not know an efficient way to do this. In spherical coordinates, this is just a `cumsum` along the `r` axis.

---

<div class="post-metadata">

### Author: ![austinbradshaw](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@austinbradshaw](https://discourse.julialang.org/u/austinbradshaw)
#### Post date: [June 3, 2026, 9:28am UTC](https://discourse.julialang.org/t/coordinate-transformation-on-mass-density/51040/7 "2026-06-03T09:28:18Z")

</div>

This post was temporarily hidden by the community for possibly being off-topic, unfocused, inappropriate, or spammy.
