Skip to content

Commit 8bd24b8

Browse files
committed
Fix importlib.resources calls for colormap data
At least for python 3.10, we cannot supplly a path as part of the filename. In general, we do not want to do this anyway, and instead want to use the full package path.
1 parent 3c079f6 commit 8bd24b8

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

mpas_analysis/shared/plot/colormap.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,9 @@ def register_custom_colormaps():
289289
'grayC', 'hawaii', 'imola', 'lajolla', 'lapaz', 'lisbon',
290290
'nuuk', 'oleron', 'oslo', 'roma', 'romaO', 'tofino',
291291
'tokyo', 'turku', 'vanimo', 'vik', 'vikO']:
292-
filename = f'ScientificColourMaps7/{map_name}/{map_name}_PARAVIEW.xml'
293-
with importlib.resources.path(__package__, filename) as xml_file:
292+
package = f'mpas_analysis.shared.plot.ScientificColourMaps7.{map_name}'
293+
filename = f'{map_name}_PARAVIEW.xml'
294+
with importlib.resources.path(package, filename) as xml_file:
294295
_read_xml_colormap(xml_file, map_name)
295296

296297
# add SciVisColor colormaps from
@@ -302,17 +303,19 @@ def register_custom_colormaps():
302303
'green-7', 'green-8', 'orange-5', 'orange-6',
303304
'orange-green-blue-gray', 'purple-7', 'purple-8', 'red-1',
304305
'red-3', 'red-4', 'yellow-1', 'yellow-7']:
305-
filename = f'SciVisColorColormaps/{map_name}.xml'
306-
with importlib.resources.path(__package__, filename) as xml_file:
306+
package = 'mpas_analysis.shared.plot.SciVisColorColormaps'
307+
filename = f'{map_name}.xml'
308+
with importlib.resources.path(package, filename) as xml_file:
307309
_read_xml_colormap(xml_file, map_name)
308310

309311
# add SciVisColor colormaps created by hand using
310312
# https://sciviscolor.org/color-moves-app/
311313
for map_name in ['3wave-green-red-purple', '3wave-blue-red-brown',
312314
'div-one-third-blue-two-thirds-red',
313315
'div-one-third-green-two-thirds-red',]:
314-
filename = f'SciVisColorCustom/{map_name}.xml'
315-
with importlib.resources.path(__package__, filename) as xml_file:
316+
package = 'mpas_analysis.shared.plot.SciVisColorCustom'
317+
filename = f'{map_name}.xml'
318+
with importlib.resources.path(package, filename) as xml_file:
316319
_read_xml_colormap(xml_file, map_name)
317320

318321
name = 'white_cmo_deep'

0 commit comments

Comments
 (0)