# Neutral density calculation

**URL:** https://discourse.pangeo.io/t/neutral-density-calculation/1185
**Category:** Science
**Created:** [January 26, 2021, 10:30pm UTC](https://discourse.pangeo.io/t/neutral-density-calculation/1185 "2021-01-26T22:30:20Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![dcherian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pangeo.io/dcherian/32/2235_2.png) [@dcherian](https://discourse.pangeo.io/u/dcherian)
#### Post date: [January 26, 2021, 10:30pm UTC](https://discourse.pangeo.io/t/neutral-density-calculation/1185/1 "2021-01-26T22:30:20Z")

</div>

Has anyone in the pangeo orbit ported the ocean neutral density calculation code to Python, or have a python wrapper for the old FORTRAN program?

---

<div class="post-metadata">

### Author: ![ocefpaf](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pangeo.io/ocefpaf/32/24_2.png) [@ocefpaf](https://discourse.pangeo.io/u/ocefpaf)
#### Post date: [February 2, 2021, 7:22pm UTC](https://discourse.pangeo.io/t/neutral-density-calculation/1185/2 "2021-02-02T19:22:47Z")

</div>

I have the Python version of the Matlab “gamma NP” but I would not recommend you to use that. I never really had the time to test it properly.

Eric Firing has the Fortran wrapper here: [pygamma: log](https://currents.soest.hawaii.edu/hgstage/pygamma/)

---

<div class="post-metadata">

### Author: ![dcherian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pangeo.io/dcherian/32/2235_2.png) [@dcherian](https://discourse.pangeo.io/u/dcherian)
#### Post date: [February 3, 2021, 12:31am UTC](https://discourse.pangeo.io/t/neutral-density-calculation/1185/3 "2021-02-03T00:31:16Z")

</div>

oh perfect! I had totally forgotten about that. Very easy to wrap with apply\_ufunc.

---

<div class="post-metadata">

### Author: ![rabernat](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pangeo.io/rabernat/32/22_2.png) [@rabernat](https://discourse.pangeo.io/u/rabernat)
#### Post date: [February 3, 2021, 2:29am UTC](https://discourse.pangeo.io/t/neutral-density-calculation/1185/4 "2021-02-03T02:29:27Z")

</div>

I once spent some time looking closely at the original Jacket and McDougal gamma\_n code. (I think it was in Fortran.) I was trying to understand why it was so slow. I remember discovering that it opened a read a file with a reference T/S profile for every single profile in the inputs. So if you passed in arrays of T / S / P with shape `Nt, Nz, Ny, Nx`, it would open and read the same file `Nt * Ny * Nx` times. This was hard coded! An exponentially faster approach would have been to just load that data into memory one time when the library was imported.

In any case, if anyone has a fast implementation of neutral density, we would be happy to stick in fastjmd95:

> **[xgcm/fastjmd95](https://github.com/xgcm/fastjmd95)**
>
> Numba implementation of Jackett &amp; McDougall (1995) ocean equation of state

---

<div class="post-metadata">

### Author: ![Gobishankar](https://avatars.discourse-cdn.com/v4/letter/g/8e8cbc/32.png) [@Gobishankar](https://discourse.pangeo.io/u/Gobishankar)
#### Post date: [December 28, 2023, 9:07am UTC](https://discourse.pangeo.io/t/neutral-density-calculation/1185/5 "2023-12-28T09:07:20Z")

</div>

Hi Everyone, I tried to install the pygamma in windows platform and encountered the following error “ModuleNotFoundError: No module named ‘numpy’” error. Would it be possible for you to guide me towards a solution? Thank you

 ![Error_Message](https://canada1.discourse-cdn.com/flex030/uploads/pangeo/original/2X/8/877611d29cc3305a942c52e82b826f3ac711b8bc.png)
