Skip to content

Commit

Permalink
Merge pull request #590 from NVJY/dev
Browse files Browse the repository at this point in the history
 Fixed xarray_wrappers.py and test, Removed Demos, Fixed __init__.py
  • Loading branch information
NVJY authored Dec 4, 2024
2 parents 99b961f + d0b03a5 commit 5a89ff8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 95 deletions.
2 changes: 2 additions & 0 deletions autoreact/ktp_xarray/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Initializes the ktp_xarray folder"""

from autoreact.ktp_xarray import xarray_wrappers

__all__ = [
Expand Down
60 changes: 0 additions & 60 deletions autoreact/ktp_xarray/xarray_demo_DataArray.py

This file was deleted.

26 changes: 0 additions & 26 deletions autoreact/ktp_xarray/xarray_demo_DataSet.py

This file was deleted.

4 changes: 2 additions & 2 deletions autoreact/ktp_xarray/xarray_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def from_data(temps, press, rates):
Construct a KTP DataArray from data
"""

ktp = xarray.DataArray(rates, [("pres", press), ("temp", temps)])
ktp = xarray.DataArray(rates, (("pres", press), ("temp", temps)))

return ktp

Expand Down Expand Up @@ -88,5 +88,5 @@ def set_rates(ktp, rates, pres, temp):
Sets the KTP values
"""

ktp.loc[dict(pres=pres, temp=temp)] = rates
ktp.loc[{"pres": pres, "temp": temp}] = rates
return ktp
22 changes: 15 additions & 7 deletions autoreact/ktp_xarray/xarray_wrappers_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import xarray_wrappers
import xarray
"""Tests xarray_wrappers.py's functions"""

import numpy
from autoreact.ktp_xarray import xarray_wrappers

Temps = [1000, 1500, 2000, 2500]
Press = [1, 10, numpy.inf]
Expand All @@ -9,53 +10,60 @@
Ktp = xarray_wrappers.from_data(Temps, Press, Rates)
print(Ktp)

def test_set_rates():
ktp = xarray_wrappers.set_rates(Ktp, Rates)
print(ktp)

def test_get_temperatures():
"""Tests the get_temperatures function"""
temp = xarray_wrappers.get_temperatures(Ktp)
print(temp)


def test_get_pressures():
"""Tests the get_pressures function"""
pres = xarray_wrappers.get_pressures(Ktp)
print(pres)


def test_get_values():
"""Tests the get_values function"""
vals = xarray_wrappers.get_values(Ktp)
print(vals)


def test_get_pslice():
"""Tests the get_pslice function"""
pslice = xarray_wrappers.get_pslice(Ktp, numpy.inf)
print(pslice)


def test_get_tslice():
"""Tests the get_tslice function"""
tslice = xarray_wrappers.get_tslice(Ktp, 1500)
print(tslice)


def test_get_spec_vals():
"""Tests the get_spec_values function"""
vals = xarray_wrappers.get_spec_vals(Ktp, 1500, 1)
print(vals)


def test_get_ipslice():
"""Tests the get_ipslice function"""
ipslice = xarray_wrappers.get_ipslice(Ktp, 0)
print(ipslice)


def test_get_itslice():
"""Tests the get_itslice function"""
itslice = xarray_wrappers.get_itslice(Ktp, 0)
print(itslice)


def test_set_rates():
"""Tests the set_rates function"""
new_rates = xarray_wrappers.set_rates(Ktp, 1e11, 10, 2000)
print(new_rates)



test_get_pressures()
test_get_temperatures()
test_get_values()
Expand Down

0 comments on commit 5a89ff8

Please sign in to comment.