From 2c974bf822f2cefc923785cf0791984d3b0f6948 Mon Sep 17 00:00:00 2001 From: yokochin Date: Thu, 7 Nov 2024 18:12:11 -0600 Subject: [PATCH] Removed xarrays from mechanalyzer/mechanalyzer Directory --- mechanalyzer/xarray_demo_DataArray.py | 60 ----------------- mechanalyzer/xarray_demo_DataSet.py | 26 -------- mechanalyzer/xarray_wrappers.py | 94 --------------------------- mechanalyzer/xarray_wrappers_test.py | 67 ------------------- 4 files changed, 247 deletions(-) delete mode 100644 mechanalyzer/xarray_demo_DataArray.py delete mode 100644 mechanalyzer/xarray_demo_DataSet.py delete mode 100644 mechanalyzer/xarray_wrappers.py delete mode 100644 mechanalyzer/xarray_wrappers_test.py diff --git a/mechanalyzer/xarray_demo_DataArray.py b/mechanalyzer/xarray_demo_DataArray.py deleted file mode 100644 index 7015ed9..0000000 --- a/mechanalyzer/xarray_demo_DataArray.py +++ /dev/null @@ -1,60 +0,0 @@ -import xarray -import numpy - -temps = [1000, 1500, 2000, 2500] -press = [1, 10, numpy.inf] - -# Define the array of rates (note: it makes sense to structure it as a list -# of rates at a given P based on how the MESS parser is written, though it -# doesn't really matter) -ktp_vals = [[1e1, 1e2, 1e3, 1e4], [1e5, 1e6, 1e7, 1e8], [1e9, 1e10, 1e11, 1e12]] - -# Create the DataArray -ktp = xarray.DataArray(ktp_vals, [("pres", press), ("temp", temps)]) -print(ktp) - -# Get a slice at a selected pressure or temperature value -print('\nPressure slice by value') -print(ktp.sel(pres=numpy.inf)) # the fact that you can use np.inf is very convenient! -print('\nTemperature slice by value') -print(ktp.sel(temp=1500)) - -# Get a specific value at a selected temperature value and pressure value -print('\nTemperature slice by value') -print(ktp.sel(temp=1500, pres=1)) - -# Get a slice at a selected pressure or temperature index -print('\nPressure slice by index') -print(ktp.isel(pres=0)) -print('\nTemperature slice by index') -print(ktp.isel(temp=0)) - -# Can also add some metadata (probably unnecessary for ktp objects, but cool) -ktp.attrs["units"] = "s^-1" # any number of arbitrary attributes can be added -ktp.name = "N2O=N2+O" - -# Can do various arithmetic operations -print('\nVarious operations') -print(ktp + ktp) -print(3 * ktp) - -# To get the actual values, use the values OR data attribute -print('\nGet the values, which should be a numpy array') -print(ktp.values) -print('type of ktp.values: ', type(ktp.values)) -print('\nTemperature slice by value, as an array') -print(ktp.sel(temp=1500, pres=1).data) -print(type(ktp.sel(temp=1500, pres=1).data)) - -# Can get all dimensions associated with an array usings the dims attribute -print('\nNames of all dimensions, as a tuple') -print(ktp.dims) - -# Can get the coordinates associated with a dimension by using that coordinate name -print('\nPressure values: ', ktp.pres.data) -print('\nTemperature values: ', ktp.temp.data) - -# Can do lookup on values with the nearest value -# This is giving an error even though I thought I copied it from the website? -#print('\nTemperature slice by nearest lookup') -#print(ktp.sel(temp=1600), method='nearest') diff --git a/mechanalyzer/xarray_demo_DataSet.py b/mechanalyzer/xarray_demo_DataSet.py deleted file mode 100644 index 2148424..0000000 --- a/mechanalyzer/xarray_demo_DataSet.py +++ /dev/null @@ -1,26 +0,0 @@ -import xarray -import numpy - -temps = [1000, 1500, 2000, 2500] -enthalpy = [60, 70, 80, 90] -gibbs = [10, 15, 20, 25] -c_p = [1, 1.1, 1.2, 1.3] -entropy = [3, 4, 5, 6] - -therm = xarray.Dataset( - { - "enthalpy": (["temp"], enthalpy), - "gibbs": (["temp"], gibbs), - "c_p": (["temp"], c_p), - "entropy": (["temp"], entropy), - }, - coords={ - "temp": temps, - }, -) - -print(therm) -print(therm.temp) -print(therm.temp.values) - - diff --git a/mechanalyzer/xarray_wrappers.py b/mechanalyzer/xarray_wrappers.py deleted file mode 100644 index 6feae39..0000000 --- a/mechanalyzer/xarray_wrappers.py +++ /dev/null @@ -1,94 +0,0 @@ -""" -Wrappers for the new xarray system. Constructors, Getters, then Setters. -""" - -import xarray - -# Constructors -def from_data(temps, press, rates): - """ - Construct a KTP DataArray from data - """ - - ktp = xarray.DataArray(rates, [("pres", press), ("temp", temps)]) - - return ktp - - - -# Getters -def get_pressures(ktp): - """ - Gets the temperature values - """ - - return ktp.pres.data - - -def get_temperatures(ktp): - """ - Gets the pressure values - """ - - return ktp.temp.data - - -def get_values(rates): - """ - WORK IN PROGRESS - Gets the KTP values - """ - - return rates - - -def get_pslice(ktp, ip): - """ - Get a slice at a selected pressure value - """ - - return ktp.sel(pres=ip) - - -def get_tslice(ktp, it): - """ - Get a slice at a selected temperature value - """ - - return ktp.sel(temp=it) - - -def get_spec_vals(ktp, it, ip): - """ - Get a specific value at a selected temperature and pressure value - """ - - return ktp.sel(temp=it, pres=ip) - - -def get_ipslice(ktp, ip): - """ - Get a slice at a selected pressure index - """ - - return ktp.isel(pres=ip) - - -def get_itslice(ktp, it): - """ - Get a slice at a selected temperature index - """ - - return ktp.isel(temp=it) - - - -# Setters -def set_rates(ktp, rates, pres, temp): - """ - DOES NOT WORK YET. Still fixing! - Sets the KTP values - """ - - ktp.loc[dict(pres=pres, temp=temp)] = rates - return ktp diff --git a/mechanalyzer/xarray_wrappers_test.py b/mechanalyzer/xarray_wrappers_test.py deleted file mode 100644 index 6d19717..0000000 --- a/mechanalyzer/xarray_wrappers_test.py +++ /dev/null @@ -1,67 +0,0 @@ -import xarray_wrappers -import xarray -import numpy - -Temps = [1000, 1500, 2000, 2500] -Press = [1, 10, numpy.inf] -Rates = [[1e1, 1e2, 1e3, 1e4], [1e5, 1e6, 1e7, 1e8], [1e9, 1e10, 1e11, 1e12]] - -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(): - temp = xarray_wrappers.get_temperatures(Ktp) - print(temp) - - -def test_get_pressures(): - pres = xarray_wrappers.get_pressures(Ktp) - print(pres) - - -def test_get_values(): - vals = xarray_wrappers.get_values(Rates) - print(vals) - - -def test_get_pslice(): - pslice = xarray_wrappers.get_pslice(Ktp, numpy.inf) - print(pslice) - - -def test_get_tslice(): - tslice = xarray_wrappers.get_tslice(Ktp, 1500) - print(tslice) - - -def test_get_spec_vals(): - vals = xarray_wrappers.get_spec_vals(Ktp, 1500, 1) - print(vals) - - -def test_get_ipslice(): - ipslice = xarray_wrappers.get_ipslice(Ktp, 0) - print(ipslice) - - -def test_get_itslice(): - itslice = xarray_wrappers.get_itslice(Ktp, 0) - print(itslice) - -def test_set_rates(): - new_rates = xarray_wrappers.set_rates(Ktp, 1e11, 10, 2000) - print(new_rates) - -test_get_pressures() -test_get_temperatures() -test_get_values() -test_get_pslice() -test_get_tslice() -test_get_spec_vals() -test_get_ipslice() -test_get_itslice() -test_set_rates()