Commit 4459a215 authored by Eteri's avatar Eteri

add funcionality to get array slice with start and stop dates

parent 31c27c22
......@@ -149,12 +149,30 @@ class DataArray(BigFile):
# chunk out of our data.
# convert ranges from bytes to array indices
slice_index = REQUEST.get('slice_index', None)
start_date = REQUEST.get('start_date', None)
stop_date = REQUEST.get('stop_date', None)
if slice_index is not None or (start_date is not None and stop_date is not None):
if slice_index is not None:
slice_index_list = []
for index in slice_index:
slice_index_list.append(slice(index.get('start'),
index.get('stop'),
index.get('step')))
elif start_date is not None and stop_date is not None:
import numpy as np
import pandas as pd
start_date_vector = self.getArray()[:]['start_date']
stop_date_vector = self.getArray()[:]['stop_date']
valid_start_idx = np.where(start_date_vector >= np.datetime64(start_date))[0]
valid_stop_idx = np.where(stop_date_vector <= np.datetime64(stop_date))[0]
if len(valid_start_idx) != 0 and len(valid_stop_idx) != 0:
start_index = valid_start_idx[start_date_vector[valid_start_idx].argmin()]
stop_index = valid_stop_idx[stop_date_vector[valid_stop_idx].argmax()]
slice_index_list = [slice(start_index, stop_index+1)]
else:
slice_index_list = [slice(0, 0)]
list_index = REQUEST.get('list_index', None)
if list_index is not None:
RESPONSE.write(self.getArray()[tuple(slice_index_list)][list_index].tobytes())
......
......@@ -47,8 +47,9 @@
<value>
<tuple>
<string>W:133, 42: Redefining built-in \'format\' (redefined-builtin)</string>
<string>W:165, 4: Redefining built-in \'range\' (redefined-builtin)</string>
<string>W:192, 10: No exception type(s) specified (bare-except)</string>
<string>W:183, 4: Redefining built-in \'range\' (redefined-builtin)</string>
<string>W:210, 10: No exception type(s) specified (bare-except)</string>
<string>W:163, 8: Unused variable \'pd\' (unused-variable)</string>
</tuple>
</value>
</item>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment