Skip to content

Commit

Permalink
Style
Browse files Browse the repository at this point in the history
  • Loading branch information
MoseleyS committed Jul 23, 2024
1 parent 9763c9f commit dc67866
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
25 changes: 12 additions & 13 deletions improver/utilities/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,20 @@

import copy
import warnings
from typing import List, Optional, Tuple, Union
from abc import ABC, abstractmethod
from typing import List, Optional, Tuple, Union

import cartopy.crs as ccrs
from cartopy.crs import CRS
import iris
import netCDF4
import numpy as np
from numpy import ndarray
from numpy.ma import MaskedArray
from cartopy.crs import CRS
from cf_units import Unit
import iris
from iris.coord_systems import GeogCS
from iris.coord_systems import CoordSystem, GeogCS
from iris.coords import AuxCoord, CellMethod, Coord, DimCoord
from iris.cube import Cube, CubeList
from iris.coord_systems import (
CoordSystem,
GeogCS,
)

from numpy import ndarray
from numpy.ma import MaskedArray
from scipy.ndimage.filters import maximum_filter
from scipy.stats import circmean

Expand Down Expand Up @@ -203,14 +198,18 @@ def get_midpoints(axis: Coord) -> np.ndarray:

if axis.circular:
endpoints_mean = np.deg2rad((axis.points[0] + axis.points[-1]) / 2)
# Force angle to sit on the upper quadrant so that eg. for endpoints of 10 degrees,
# and 350 degrees, midpoint is zero degrees rather than 180.
extra_point = np.rad2deg(
np.arctan(np.sin(endpoints_mean) / np.cos(endpoints_mean))
) # Forces angle to sit on the upper quadrant so that eg. for endpoints of 10 degrees, and 350 degrees, midpoint is zero degrees rather than 180.
)
if extra_point < 0:
extra_point += 360 # Forces angle to be between 0 and 360
# Stable sort fasted in this case, where list is already nearly sorted with only the
# one out-of-order element.
midpoints = np.sort(
np.hstack((midpoints, np.array(extra_point))), kind="stable"
) # Stable sort fasted in this case, where list is already nearly sorted with only the one out-of-order element.
)

return midpoints.astype(axis.dtype)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from improver.synthetic_data.set_up_test_cubes import set_up_variable_cube
from improver.utilities.spatial import GradientBetweenAdjacentGridSquares


EXAMPLE_INPUT_DATA_1 = np.array(
[[0, 100, 200], [300, 400, 500], [400, 500, 600]], dtype=np.float32
)
Expand Down

0 comments on commit dc67866

Please sign in to comment.