From 82ddc7a8a55168a3242496c1bee956535e611178 Mon Sep 17 00:00:00 2001 From: zssherman Date: Thu, 11 Apr 2024 14:02:53 -0500 Subject: [PATCH] FIX: Fix for datetime and xarray depreciation warning. --- pysp2/io/read_sp2b.py | 4 ++-- pysp2/util/deadtime.py | 8 ++++---- pysp2/util/particle_properties.py | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pysp2/io/read_sp2b.py b/pysp2/io/read_sp2b.py index ebad7df..7d5b7d8 100644 --- a/pysp2/io/read_sp2b.py +++ b/pysp2/io/read_sp2b.py @@ -3,7 +3,7 @@ import numpy as np import platform -from datetime import datetime +from datetime import datetime, timezone def read_sp2(file_name, debug=False, arm_convention=True): @@ -119,7 +119,7 @@ def read_sp2(file_name, debug=False, arm_convention=True): diff_epoch_1904 = ( datetime(1970, 1, 1) - datetime(1904, 1, 1)).total_seconds() UTCdatetime = np.array([ - datetime.utcfromtimestamp(x - diff_epoch_1904) for x in UTCtime]) + datetime.fromtimestamp(x - diff_epoch_1904, timezone.utc) for x in UTCtime]) DateTimeWave = (dt - datetime(1904, 1, 1)).total_seconds() + TimeWave diff --git a/pysp2/util/deadtime.py b/pysp2/util/deadtime.py index 9e32ddb..5888529 100644 --- a/pysp2/util/deadtime.py +++ b/pysp2/util/deadtime.py @@ -27,7 +27,7 @@ def deadtime(my_binary, my_ini): in the SP2 at high concentrations. """ #numpy array to store the relative bias in - bias = np.zeros(my_binary.dims['event_index'], ) + bias = np.zeros(my_binary.sizes['event_index'], ) #scattering triggered scatter_triggered = np.any(np.isfinite(np.vstack((my_binary['PkHt_ch0'].values, my_binary['PkHt_ch4'].values))), axis=0) @@ -47,8 +47,8 @@ def deadtime(my_binary, my_ini): #find locations where those unique time stamps should be inserted ind = np.searchsorted(my_binary['TimeWave'].values, unique_buffer_time_stamps) #add the end to the list of indexes if needed - if ind[-1] < my_binary.dims['event_index']: - ind = np.append(ind, my_binary.dims['event_index']) + if ind[-1] < my_binary.sizes['event_index']: + ind = np.append(ind, my_binary.sizes['event_index']) for i in range(len(ind)-1): #from index fr = ind[i] @@ -76,4 +76,4 @@ def deadtime(my_binary, my_ini): bias[fr:to] = B_rel #add the bias containing array to the xarray my_binary['DeadtimeRelativeBias'] = xr.DataArray(bias, dims=['event_index']) - return my_binary \ No newline at end of file + return my_binary diff --git a/pysp2/util/particle_properties.py b/pysp2/util/particle_properties.py index 125a6ed..26773e7 100644 --- a/pysp2/util/particle_properties.py +++ b/pysp2/util/particle_properties.py @@ -337,6 +337,7 @@ def process_psds(particle_ds, hk_ds, config, deltaSize=0.005, num_bins=199, avg_ base_time = pd.Timestamp('1904-01-01') time = np.array([(base_time + datetime.timedelta(seconds=x)).to_datetime64() for x in time_bins[:-1]]) + time = time.astype('datetime64[ns]') time = xr.DataArray(time, dims=('time')) time_wave = xr.DataArray(time_bins[:-1], dims=('time'))