This is an automated email from the ASF dual-hosted git repository.

rkk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-sdap-nexus.git


The following commit(s) were added to refs/heads/master by this push:
     new 9ab3ec9  SDAP-436 - Added special case for uniform time arrays in 
multi-var swath tiles (#227)
9ab3ec9 is described below

commit 9ab3ec966a1c42db5c1e1ad932cf0ffdc484e324
Author: Riley Kuttruff <[email protected]>
AuthorDate: Tue Feb 21 09:42:15 2023 -0800

    SDAP-436 - Added special case for uniform time arrays in multi-var swath 
tiles (#227)
    
    * Don't simplify time_data arrays, this seems to cause issues down the line
    
    * Restored simplification, added case for desired_shape[0] == 1 and 
multi_var
    
    * Changelog
    
    * Simplify _to_standard_index (#7)
    
    Co-authored-by: skorper <[email protected]>
    
    ---------
    
    Co-authored-by: rileykk <[email protected]>
    Co-authored-by: skorper <[email protected]>
---
 CHANGELOG.md                                 |  1 +
 data-access/nexustiles/dao/CassandraProxy.py | 49 +++++++++++++---------------
 2 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4ed345f..ae01564 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@ and this project adheres to [Semantic 
Versioning](https://semver.org/spec/v2.0.0
 ### Fixed
 - Made `platforms` param optional in `/cdmssubset`, and removed int requirement
 - Updated OpenAPI specification for `/cdmssubset` to accurately reflect 
`platforms` and `parameter` field options.
+- SDAP-436: Added special case for handling Cassandra SwathMulti tiles with 
uniform time arrays
 ### Security
 
 ## [1.0.0] - 2022-12-05
diff --git a/data-access/nexustiles/dao/CassandraProxy.py 
b/data-access/nexustiles/dao/CassandraProxy.py
index 4ce684a..96f7c4c 100644
--- a/data-access/nexustiles/dao/CassandraProxy.py
+++ b/data-access/nexustiles/dao/CassandraProxy.py
@@ -226,40 +226,37 @@ class NexusTileData(Model):
         :rtype: np.array
         """
 
-        if desired_shape[0] == 1:
-            reshaped_array = np.ma.masked_all((desired_shape[1], 
desired_shape[2]))
-            row, col = np.indices(data_array.shape)
-
-            reshaped_array[np.diag_indices(desired_shape[1], 
len(reshaped_array.shape))] = data_array[
-                row.flat, col.flat]
-            reshaped_array.mask[np.diag_indices(desired_shape[1], 
len(reshaped_array.shape))] = data_array.mask[
-                row.flat, col.flat]
-            reshaped_array = reshaped_array[np.newaxis, :]
-        elif is_multi_var == True:
-            # Break the array up by variable. Translate shape from
-            # len(times) x len(latitudes) x len(longitudes) x num_vars,
-            # to
-            # num_vars x len(times) x len(latitudes) x len(longitudes)
+        reshaped_array = []
+        if is_multi_var:
             reshaped_data_array = np.moveaxis(data_array, -1, 0)
-            reshaped_array = []
+        else:
+            reshaped_data_array = [data_array]
 
-            for variable_data_array in reshaped_data_array:
+        for variable_data_array in reshaped_data_array:
+            if desired_shape[0] == 1:
+                variable_reshaped_array = np.ma.masked_all((desired_shape[1], 
desired_shape[2]))
+            else:
                 variable_reshaped_array = np.ma.masked_all(desired_shape)
-                row, col = np.indices(variable_data_array.shape)
 
-                variable_reshaped_array[np.diag_indices(desired_shape[1], 
len(variable_reshaped_array.shape))] = variable_data_array[
+            row, col = np.indices(variable_data_array.shape)
+
+            variable_reshaped_array[
+                np.diag_indices(desired_shape[1], 
len(variable_reshaped_array.shape))] = \
+                variable_data_array[
                     row.flat, col.flat]
-                variable_reshaped_array.mask[np.diag_indices(desired_shape[1], 
len(variable_reshaped_array.shape))] = variable_data_array.mask[
+            variable_reshaped_array.mask[
+                np.diag_indices(desired_shape[1], 
len(variable_reshaped_array.shape))] = \
+                variable_data_array.mask[
                     row.flat, col.flat]
+
+            if desired_shape[0] == 1:
+                reshaped_array.append(variable_reshaped_array[np.newaxis, :])
+            else:
                 reshaped_array.append(variable_reshaped_array)
-        else:
-            reshaped_array = np.ma.masked_all(desired_shape)
-            row, col = np.indices(data_array.shape)
 
-            reshaped_array[np.diag_indices(desired_shape[1], 
len(reshaped_array.shape))] = data_array[
-                row.flat, col.flat]
-            reshaped_array.mask[np.diag_indices(desired_shape[1], 
len(reshaped_array.shape))] = data_array.mask[
-                row.flat, col.flat]
+        if not is_multi_var:
+            # If single var, squeeze extra dim out of array
+            reshaped_array = reshaped_array[0]
 
         return reshaped_array
 

Reply via email to