Skip to content

Commit

Permalink
Merge pull request #62 from zssherman/warning_fixes
Browse files Browse the repository at this point in the history
FIX: Fix for datetime and xarray depreciation warning.
  • Loading branch information
rcjackson authored May 8, 2024
2 parents 3684668 + cb2ffa1 commit 9fce2e7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pysp2/io/read_sp2b.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -119,7 +119,8 @@ 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, tz=timezone.utc).replace(tzinfo=None) for x in UTCtime])

DateTimeWave = (dt - datetime(1904, 1, 1)).total_seconds() + TimeWave

Expand Down
8 changes: 4 additions & 4 deletions pysp2/util/deadtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]
Expand Down Expand Up @@ -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
return my_binary
1 change: 1 addition & 0 deletions pysp2/util/particle_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down

0 comments on commit 9fce2e7

Please sign in to comment.