Github user jarifibrahim commented on a diff in the pull request:

    https://github.com/apache/climate/pull/361#discussion_r67598748
  
    --- Diff: ocw/dataset_processor.py ---
    @@ -202,130 +214,158 @@ def spatial_regrid(target_dataset, new_latitudes, 
new_longitudes, boundary_check
         ny_new, nx_new = new_lats.shape
     
         # Make masked array of shape (times, new_latitudes,new_longitudes)
    -    new_values = ma.zeros([len(target_dataset.times), 
    -                           ny_new, nx_new]) 
    +    new_values = ma.zeros([len(target_dataset.times),
    +                           ny_new, nx_new])
         # Make masked array of shape (times, new_latitudes,new_longitudes)
    -    new_values = ma.zeros([len(target_dataset.times), 
    +    new_values = ma.zeros([len(target_dataset.times),
                                ny_new, nx_new])
     
         # Boundary vertices of target_dataset
         vertices = []
     
    -    if regular_grid: 
    -        vertices.append([lons[0,0], lats[0,0]])
    -        vertices.append([lons[-1,0], lats[-1,0]])
    -        vertices.append([lons[-1,-1], lats[-1,-1]])
    -        vertices.append([lons[0,-1], lats[0,-1]])
    -    else: 
    -        for iy in np.arange(ny_old):   # from south to north along the 
west boundary
    -            vertices.append([lons[iy,0], lats[iy,0]]) 
    -        for ix in np.arange(nx_old):   # from west to east along the north 
boundary
    +    if regular_grid:
    +        vertices.append([lons[0, 0], lats[0, 0]])
    +        vertices.append([lons[-1, 0], lats[-1, 0]])
    +        vertices.append([lons[-1, -1], lats[-1, -1]])
    +        vertices.append([lons[0, -1], lats[0, -1]])
    +    else:
    +        # from south to north along the west boundary
    +        for iy in np.arange(ny_old):
    +            vertices.append([lons[iy, 0], lats[iy, 0]])
    +        # from west to east along the north boundary
    +        for ix in np.arange(nx_old):
                 vertices.append([lons[-1, ix], lats[-1, ix]])
    -        for iy in np.arange(ny_old)[::-1]:   # from north to south along 
the east boundary
    +        # from north to south along the east boundary
    +        for iy in np.arange(ny_old)[::-1]:
                 vertices.append([lons[iy, -1], lats[iy, -1]])
    -        for ix in np.arange(nx_old)[::-1]:   # from east to west along the 
south boundary
    +        # from east to west along the south boundary
    +        for ix in np.arange(nx_old)[::-1]:
                 vertices.append([lons[0, ix], lats[0, ix]])
         path = Path(vertices)
     
         # Convert new_lats and new_lons to float indices
         new_lons_indices = np.zeros(new_lons.shape)
         new_lats_indices = np.zeros(new_lats.shape)
    -  
    +
         for iy in np.arange(ny_new):
             for ix in np.arange(nx_new):
    -            if path.contains_point([new_lons[iy,ix], new_lats[iy,ix]]) or 
not boundary_check: 
    +            if path.contains_point([new_lons[iy, ix],
    +                                    new_lats[iy, ix]]) or not 
boundary_check:
                     if regular_grid:
    -                    new_lats_indices[iy,ix] = (ny_old 
-1.)*(new_lats[iy,ix] - lats.min())/(lats.max() - lats.min())  
    -                    new_lons_indices[iy,ix] = (nx_old 
-1.)*(new_lons[iy,ix] - lons.min())/(lons.max() - lons.min())  
    +                    mn = lats.min()
    +                    mx = lats.max()
    +                    new_lats_indices[iy, ix] = (
    +                        ny_old - 1.) * (new_lats[iy, ix] - mn / (mx - mn))
    --- End diff --
    
    `mx`, `mn` are used to reduce line length.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to