Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ c00e0adae1b1e8695e173f4482369face82206ee

# style: adopt isort to enforce import ordering (#2150)
030a78b0f5cd6a88b04dd2fbe78f12b4b3e5e60d

# style: adopt ruff formatter (#2540)
a44e1d66406b69a3fb11d6c2b2d91c8cedb65013
14 changes: 6 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ repos:
- id: codespell
types_or: [python, markdown, rst]
additional_dependencies: [tomli]
- repo: https://github.com/aio-libs/sort-all
rev: "v1.3.0"
hooks:
- id: sort-all
types: [file, python]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.11.4'
rev: 'v0.11.11'
hooks:
- id: ruff
args: [--fix]
# Run the linter.
- id: ruff-check
args: [ --fix ]
# Run the formatter.
- id: ruff-format
5 changes: 3 additions & 2 deletions benchmarks/cases/gridliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class Gridliner:
def setup(self, draw_labels, inline):
self.proj = ccrs.PlateCarree()
fig, ax = plt.subplots(subplot_kw=dict(projection=self.proj))
ax.gridlines(draw_labels=draw_labels, x_inline=inline, y_inline=inline,
auto_inline=False)
ax.gridlines(
draw_labels=draw_labels, x_inline=inline, y_inline=inline, auto_inline=False
)
self.figure = fig

def time_gridlines(self, draw_labels, inline):
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/cases/project_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

class Suite:
params = [
('PlateCarree', 'NorthPolarStereo', 'Robinson',
'InterruptedGoodeHomolosine'),
('PlateCarree', 'NorthPolarStereo', 'Robinson', 'InterruptedGoodeHomolosine'),
('110m', '50m'),
]
param_names = ['projection', 'resolution']

def setup(self, projection, resolution):
shpfilename = shpreader.natural_earth(
resolution=resolution, category='physical', name='ocean')
resolution=resolution, category='physical', name='ocean'
)
reader = shpreader.Reader(shpfilename)
oceans = list(reader.geometries())
self.geoms = oceans[0]
Expand Down
125 changes: 78 additions & 47 deletions docs/make_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
ccrs.RotatedPole: {'pole_longitude': 177.5, 'pole_latitude': 37.5},
ccrs.AzimuthalEquidistant: {'central_latitude': 90},
ccrs.NearsidePerspective: {
'central_longitude': -3.53, 'central_latitude': 50.72,
'satellite_height': 10.0e6},
'central_longitude': -3.53,
'central_latitude': 50.72,
'satellite_height': 10.0e6,
},
ccrs.OSGB: {'approx': False},
ccrs.OSNI: {'approx': False},
ccrs.TransverseMercator: {'approx': False},
Expand All @@ -35,24 +37,32 @@ def plate_carree_plot():
for i in range(0, nplots):
central_longitude = 0 if i == 0 else 180
ax = fig.add_subplot(
nplots, 1, i+1,
projection=ccrs.PlateCarree(central_longitude=central_longitude))
nplots,
1,
i + 1,
projection=ccrs.PlateCarree(central_longitude=central_longitude),
)
ax.coastlines(resolution='110m')
ax.gridlines()


def igh_plot():
fig = plt.figure(figsize=(6.9228, 6))

ax1 = fig.add_subplot(2, 1, 1,
projection=ccrs.InterruptedGoodeHomolosine(
emphasis='land'))
ax1 = fig.add_subplot(
2, 1, 1, projection=ccrs.InterruptedGoodeHomolosine(emphasis='land')
)
ax1.coastlines(resolution='110m')
ax1.gridlines()

ax2 = fig.add_subplot(2, 1, 2,
projection=ccrs.InterruptedGoodeHomolosine(
central_longitude=-160, emphasis='ocean'))
ax2 = fig.add_subplot(
2,
1,
2,
projection=ccrs.InterruptedGoodeHomolosine(
central_longitude=-160, emphasis='ocean'
),
)
ax2.coastlines(resolution='110m')
ax2.gridlines()

Expand All @@ -63,9 +73,9 @@ def utm_plot():
fig = plt.figure(figsize=(10, 3))

for i in range(0, nplots):
ax = fig.add_subplot(1, nplots, i+1,
projection=ccrs.UTM(zone=i+1,
southern_hemisphere=True))
ax = fig.add_subplot(
1, nplots, i + 1, projection=ccrs.UTM(zone=i + 1, southern_hemisphere=True)
)
ax.coastlines(resolution='110m')
ax.gridlines()

Expand All @@ -77,33 +87,56 @@ def utm_plot():
}


COASTLINE_RESOLUTION = {ccrs.OSNI: '10m',
ccrs.OSGB: '50m',
ccrs.EuroPP: '50m',
ccrs.LambertZoneII: '10m'}
COASTLINE_RESOLUTION = {
ccrs.OSNI: '10m',
ccrs.OSGB: '50m',
ccrs.EuroPP: '50m',
ccrs.LambertZoneII: '10m',
}


PRJ_SORT_ORDER = {'PlateCarree': 1,
'Mercator': 2, 'Mollweide': 2, 'Robinson': 2,
'TransverseMercator': 2, 'ObliqueMercator': 2,
'LambertCylindrical': 2,
'LambertConformal': 2, 'EquidistantConic': 2,
'Stereographic': 2, 'Miller': 2,
'Orthographic': 2, 'UTM': 2, 'AlbersEqualArea': 2,
'AzimuthalEquidistant': 2, 'Sinusoidal': 2,
'InterruptedGoodeHomolosine': 3, 'RotatedPole': 3,
'OSGB': 4, 'LambertZoneII': 4.1, 'EuroPP': 5,
'Geostationary': 6, 'NearsidePerspective': 7,
'EckertI': 8.1, 'EckertII': 8.2, 'EckertIII': 8.3,
'EckertIV': 8.4, 'EckertV': 8.5, 'EckertVI': 8.6,
'Spilhaus': 9}
PRJ_SORT_ORDER = {
'PlateCarree': 1,
'Mercator': 2,
'Mollweide': 2,
'Robinson': 2,
'TransverseMercator': 2,
'ObliqueMercator': 2,
'LambertCylindrical': 2,
'LambertConformal': 2,
'EquidistantConic': 2,
'Stereographic': 2,
'Miller': 2,
'Orthographic': 2,
'UTM': 2,
'AlbersEqualArea': 2,
'AzimuthalEquidistant': 2,
'Sinusoidal': 2,
'InterruptedGoodeHomolosine': 3,
'RotatedPole': 3,
'OSGB': 4,
'LambertZoneII': 4.1,
'EuroPP': 5,
'Geostationary': 6,
'NearsidePerspective': 7,
'EckertI': 8.1,
'EckertII': 8.2,
'EckertIII': 8.3,
'EckertIV': 8.4,
'EckertV': 8.5,
'EckertVI': 8.6,
'Spilhaus': 9,
}


def find_projections():
for obj_name, o in vars(ccrs).copy().items():
if isinstance(o, type) and issubclass(o, ccrs.Projection) and \
not obj_name.startswith('_') and obj_name not in ['Projection']:

if (
isinstance(o, type)
and issubclass(o, ccrs.Projection)
and not obj_name.startswith('_')
and obj_name not in ['Projection']
):
yield o


Expand All @@ -112,12 +145,11 @@ def create_instance(prj_cls, instance_args):

# Format instance arguments into strings
instance_params = ',\n '.join(
f'{k}={v}'
for k, v in sorted(instance_args.items()))
f'{k}={v}' for k, v in sorted(instance_args.items())
)

if instance_params:
instance_params = '\n ' \
+ instance_params
instance_params = '\n ' + instance_params

instance_creation_code = f'{name}({instance_params})'

Expand Down Expand Up @@ -147,8 +179,7 @@ def create_instance(prj_cls, instance_args):
table.write(textwrap.dedent(header))

def prj_class_sorter(cls):
return (PRJ_SORT_ORDER.get(cls.__name__, 100),
cls.__name__)
return (PRJ_SORT_ORDER.get(cls.__name__, 100), cls.__name__)

for prj in sorted(find_projections(), key=prj_class_sorter):
name = prj.__name__
Expand All @@ -164,8 +195,7 @@ def prj_class_sorter(cls):

prj_inst, instance_repr = create_instance(prj, instance_args)

aspect = (np.diff(prj_inst.x_limits) /
np.diff(prj_inst.y_limits))[0]
aspect = (np.diff(prj_inst.x_limits) / np.diff(prj_inst.y_limits))[0]

width = 3 * aspect
width = f'{width:.4f}'.rstrip('0').rstrip('.')
Expand All @@ -183,16 +213,17 @@ def prj_class_sorter(cls):
ax.gridlines()


""").format(width=width,
proj_constructor=instance_repr,
coastline_resolution=COASTLINE_RESOLUTION.get(prj,
'110m'))
""").format(
width=width,
proj_constructor=instance_repr,
coastline_resolution=COASTLINE_RESOLUTION.get(prj, '110m'),
)

else:
func = MULTI_PLOT_CASES[prj]

lines = inspect.getsourcelines(func)
func_code = "".join(lines[0][1:])
func_code = ''.join(lines[0][1:])

code = textwrap.dedent("""
.. plot::
Expand Down
Loading
Loading