diff --git a/PSPoperations/__init__.py b/PSPoperations/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/PSPoperations/__pycache__/__init__.cpython-38.pyc b/PSPoperations/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 422e4f327a8acb7cf85b4609c572662b6187ffff..0000000000000000000000000000000000000000 Binary files a/PSPoperations/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/PSPoperations/__pycache__/data_handling.cpython-38.pyc b/PSPoperations/__pycache__/data_handling.cpython-38.pyc deleted file mode 100644 index 49509b62a75d10286c70b8515c840f6b0aa0494a..0000000000000000000000000000000000000000 Binary files a/PSPoperations/__pycache__/data_handling.cpython-38.pyc and /dev/null differ diff --git a/PSPoperations/__pycache__/data_quality.cpython-38.pyc b/PSPoperations/__pycache__/data_quality.cpython-38.pyc deleted file mode 100644 index 66ad3157df0b1fe28a53a232e9dd6b66ac18abab..0000000000000000000000000000000000000000 Binary files a/PSPoperations/__pycache__/data_quality.cpython-38.pyc and /dev/null differ diff --git a/PSPoperations/__pycache__/data_transformation.cpython-38.pyc b/PSPoperations/__pycache__/data_transformation.cpython-38.pyc deleted file mode 100644 index 8991004c53960278dba9ff7e59bf24cb70a95a15..0000000000000000000000000000000000000000 Binary files a/PSPoperations/__pycache__/data_transformation.cpython-38.pyc and /dev/null differ diff --git a/PSPoperations/__pycache__/plot_settings.cpython-38.pyc b/PSPoperations/__pycache__/plot_settings.cpython-38.pyc deleted file mode 100644 index 2e9945b7d6381f47e2d8e13affba059927fd0854..0000000000000000000000000000000000000000 Binary files a/PSPoperations/__pycache__/plot_settings.cpython-38.pyc and /dev/null differ diff --git a/PSPoperations/data_handling.py b/PSPoperations/data_handling.py deleted file mode 100644 index 3772ca29c3fe956936c625488ba57f8e30934eb7..0000000000000000000000000000000000000000 --- a/PSPoperations/data_handling.py +++ /dev/null @@ -1,73 +0,0 @@ -import os -import typing as tp -import numpy as np - -# CDF library (is needed to interface with the measurement data files) -# see https://cdf.gsfc.nasa.gov/ -os.environ["CDF_LIB"] = "/usr/local/cdf/lib" - - -def cdf_slice(cdf_file, key: str): - """ - DOC - - :param cdf_file: - :param key: - :return: - """ - return cdf_file[key][...] - - -def data_generation(cdf_file) -> tp.Dict: - """ - DOC - - :param cdf_file: - :return: - """ - data = { - "dqf": cdf_slice(cdf_file, key="general_flag"), - "epoch": cdf_slice(cdf_file, key="Epoch"), - "pos": cdf_slice(cdf_file, key="sc_pos_HCI"), - "vr": cdf_slice(cdf_file, key="vp_moment_RTN")[:, 0], - "dvrhi": cdf_slice(cdf_file, key="vp_moment_RTN_deltahigh")[:, 0], - "dvrlo": cdf_slice(cdf_file, key="vp_moment_RTN_deltalow")[:, 0], - "wp": cdf_slice(cdf_file, key="wp_moment"), - "dwphi": cdf_slice(cdf_file, key="wp_moment_deltahigh"), - "dwplo": cdf_slice(cdf_file, key="wp_moment_deltalow") - } - - return data - - -def array_reduction(data_array: np.ndarray, - index_list: np.ndarray) -> np.ndarray: - """ - Reduction of an array by a list of indices. - - :param data_array: NDARRAY, - Array that is to be reduced - :param index_list: NDARRAY, - List of indices that should be deleted - :return: NDARRAY, - The reduced array - """ - # Choose axis=0 to delete rows and not flatten the array - reduced_array = np.delete(data_array, index_list, axis=0) - - return reduced_array - - -def full_reduction(data_dict: tp.Dict, - bad_indices: np.array) -> tp.Dict: - """ - DOC - - :param data_dict: - :param bad_indices: - :return: - """ - for key in data_dict.keys(): - data_dict[key] = array_reduction(data_dict[key], bad_indices) - - return data_dict diff --git a/PSPoperations/data_quality.py b/PSPoperations/data_quality.py deleted file mode 100644 index bdb6be47e210f365487e76aa9a3f6cf1522d5806..0000000000000000000000000000000000000000 --- a/PSPoperations/data_quality.py +++ /dev/null @@ -1,56 +0,0 @@ -import numpy as np -import typing as tp - - -def general_flag(general_flag_array: np.ndarray) -> np.ndarray: - """ - This function reads out index locations where data general flag is - set to 0 (see documentation for PSP data). This requires correct - handling of CDF array keys - - :param general_flag_array: NDARRAY, - cdf_data["general_flag"][...] - Only good when set to 0. The - input here must specifically be this array! - :return: NDARRAY, - An array of the "faulty" indices. These indices correspond to - the index m in the m x n GENERAL CDF array, not a measurement - subarray! - """ - # Notable indices are where values are set to non-zero - # From the data user guide: 0 means no condition present - index_list = np.where(general_flag_array != 0)[0] - - return index_list - - -def meas_failed(meas_array: np.ndarray) -> np.ndarray: - """ - Takes a 1D array and returns indices of failed measurements (as - indicated by a value of -1e30, SWEAP documentation) - - :param meas_array: NDARRAY, - Measurement array - :return: NDARRAY, - Index array - """ - index_array = np.where(meas_array <= -0.5e30)[0] - - return index_array - - -def full_meas_eval(data_dict: tp.Dict): - """DOC""" - col_ind = [] - - for key in data_dict.keys(): - - # Skip unnecessary keys (maybe make this more dynamic?) - if key in ["pos", "dqf", "epoch"]: - continue - - col_ind.append(meas_failed(data_dict[key])) - - # Make an array of unique indices - col_ind = np.unique(np.concatenate(col_ind)) - - return col_ind diff --git a/PSPoperations/data_transformation.py b/PSPoperations/data_transformation.py deleted file mode 100644 index a3df0292cb5f080f0d595844cfdfd2644c382d08..0000000000000000000000000000000000000000 --- a/PSPoperations/data_transformation.py +++ /dev/null @@ -1,44 +0,0 @@ -import numpy as np -import typing as tp -# The warnings (for me) here don't seem to matter -from astropy.constants import k_B, m_p - - -def pos_cart_to_sph(position_matrix: np.ndarray) -> tp.Tuple: - """ - Transforms cartesian coordinates to spherical coordinates. - - :param position_matrix: NDARRAY, - (n x 3) matrix of (x, y, z) coordinates - :return: TUPLE, - r = heliocentric distance in KM - theta = inclination in RADIANS - phi = azimuth in RADIANS - """ - # Sanity check: pos_mat MUST BE an (n x 3) matrix - assert position_matrix.shape[1] == 3, \ - "PLEASE CHECK POSITION MATRIX FOR COORDINATE CONVERSION!" - - x = position_matrix[:, 0] - y = position_matrix[:, 1] - z = position_matrix[:, 2] - - r = np.sqrt(x * x + y * y + z * z) - theta = np.arccos(z / r) - phi = np.arctan2(y, x) - - return r, theta, phi - - -def wp_to_temp(thermal_speed: np.ndarray) -> np.ndarray: - """ - Calculate temperature from thermal speed of protons. - - :param thermal_speed: NDARRAY, - Thermal speed (wp) of protons - :return: NDARRAY, - Temperature from wp = sqrt(2k_BT / m) - """ - wp_si = thermal_speed * 1e3 - - return wp_si ** 2 * m_p.value / (2 * k_B.value) diff --git a/PSPoperations/plot_settings.py b/PSPoperations/plot_settings.py deleted file mode 100644 index 8a50ac8149629e0f3a58cfc0687d1861b336adf9..0000000000000000000000000000000000000000 --- a/PSPoperations/plot_settings.py +++ /dev/null @@ -1,63 +0,0 @@ -import matplotlib as mpl -import matplotlib.pyplot as plt - - -def rc_setup(): - """Generalized plot attributes""" - mpl.rcParams["xtick.direction"] = "in" - mpl.rcParams["ytick.direction"] = "in" - mpl.rcParams["xtick.minor.visible"] = "True" - mpl.rcParams["ytick.minor.visible"] = "True" - - -def plot_r_vr(r, vr, v_ulim, v_lolim, save_ind: str = "no"): - """ - Plots radial velocity wrt heliocentric distance - - :param r: NDARRAY, - Distance (must be in km) - :param vr: NDARRAY, - Radial velocity (must be in km/s) - :param v_ulim, v_lolim: NDARRAY, - Upper (lower) uncertainty of vr - :param save_ind: STR, - "yes" if plot should be saved (default: no) - """ - fig, ax = plt.subplots(figsize=(10, 6)) - plt.plot(r / 6.957e5, vr) - plt.fill_between(r / 6.957e5, vr + v_ulim, vr - v_lolim, color="grey", - alpha=0.25) - ax.set( - xlabel="r [R$_\\odot$]", ylabel="v$_r$ [km s$^{-1}$]", - ylim=(0, 800) - ) - ax.grid(True, alpha=0.5) - - if save_ind.lower() == "yes": - plt.savefig("plot_vr.png") - - -def plot_r_temp(r, T, T_ulim, T_lolim, save_ind: str = "no"): - """ - Plots logarithmic temperature wrt heliocentric distance - - :param r: NDARRAY, - Heliocentric distance (mst be in km) - :param T: NDARRAY, - logarithmic Temperature (Kelvin) - :param T_ulim, T_lolim: NDARRAY, - Upper (lower) uncertainty of logT - :param save_ind: STR, - "yes" if plot should be saved (default: no) - """ - fig, ax = plt.subplots(figsize=(10, 6)) - plt.plot(r / 6.957e5, T) - plt.fill_between(r / 6.957e5, T_ulim, T - T_lolim, - color="grey", alpha=0.25) - ax.set( - xlabel="r [R$_\\odot$]", ylabel="T [K]", yscale="log" - ) - ax.grid(True, alpha=0.5) - - if save_ind.lower() == "yes": - plt.savefig("plot_logT.png") diff --git a/psp_swp_spc_l3i_20211117_v02.cdf b/psp_swp_spc_l3i_20211117_v02.cdf deleted file mode 100644 index adb641f3f4584932c96daa492fb563b0579deacc..0000000000000000000000000000000000000000 Binary files a/psp_swp_spc_l3i_20211117_v02.cdf and /dev/null differ diff --git a/psp_swp_spc_l3i_20211118_v02.cdf b/psp_swp_spc_l3i_20211118_v02.cdf deleted file mode 100644 index 024abb5c26e11aec8e66abf3e2de35b3a79d7518..0000000000000000000000000000000000000000 Binary files a/psp_swp_spc_l3i_20211118_v02.cdf and /dev/null differ diff --git a/psp_swp_spc_l3i_20211121_v02.cdf b/psp_swp_spc_l3i_20211121_v02.cdf deleted file mode 100644 index 359ab251b0e6bb60ee7e1314b07e368bbde1707b..0000000000000000000000000000000000000000 Binary files a/psp_swp_spc_l3i_20211121_v02.cdf and /dev/null differ diff --git a/testing.py b/testing.py deleted file mode 100644 index 307a7500cdd935fd6cbb7344912dce20b49ce3af..0000000000000000000000000000000000000000 --- a/testing.py +++ /dev/null @@ -1,40 +0,0 @@ -import os -import numpy as np -import matplotlib.pyplot as plt -from spacepy import pycdf -from PSPoperations import data_quality as dq -from PSPoperations import data_transformation as dt - -# CDF library (is needed to interface with the measurement data files) -# see https://cdf.gsfc.nasa.gov/ -os.environ["CDF_LIB"] = "/usr/local/cdf/lib" - -# open CDF file and generate faulty index array -cdf_data = pycdf.CDF("psp_swp_spc_l3i_20211117_v02.cdf") -dqf = cdf_data["general_flag"][...] -bad_ind = dq.general_flag(dqf) - -# generate reduced epoch array -time = dq.array_reduction(cdf_data["Epoch"][...], bad_ind) - -# generate reduced position array and spherical coordinates -pos = dq.array_reduction(cdf_data["sc_pos_HCI"][...], bad_ind) -r, theta, phi = dt.pos_cart_to_sph(pos) - -# generate (prelim.) velocity array (is [0] in RTN right?) -vr = dq.array_reduction(cdf_data["vp_moment_RTN"][...][:, 0], bad_ind) -del_vr_lo = dq.array_reduction(cdf_data["vp_moment_RTN_deltalow"][...][:, 0], - bad_ind) -del_vr_hi = dq.array_reduction(cdf_data["vp_moment_RTN_deltahigh"][...][:, 0], - bad_ind) - -plt.figure() -plt.plot(r / 1.49e8, vr) -plt.fill_between(r / 1.49e8, vr + del_vr_hi, vr - del_vr_lo, color="grey", - alpha=0.15) -plt.ylim(0, 1000) - -plt.figure() -plt.scatter(time, r / 1.49e8) - -plt.show()