Skip to content
Merged
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
9 changes: 5 additions & 4 deletions mpas_analysis/download_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


import argparse
import pkg_resources
import importlib.resources as resources
import os

from mpas_analysis.shared.io.download import download_files
Expand Down Expand Up @@ -49,9 +49,10 @@ def download_analysis_data():
pass

urlBase = 'https://web.lcrc.anl.gov/public/e3sm/diagnostics'
analysisFileList = pkg_resources.resource_string(
'mpas_analysis',
'obs/{}_input_files'.format(args.dataset)).decode('utf-8')
resource = resources.files('mpas_analysis.obs').joinpath(
f'{args.dataset}_input_files')
with resource.open('r') as f:
analysisFileList = f.read()

# remove any empty strings from the list
analysisFileList = list(filter(None, analysisFileList.split('\n')))
Expand Down
12 changes: 7 additions & 5 deletions mpas_analysis/ocean/climatology_map_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@

class ClimatologyMapCustom(AnalysisTask):
"""
A felxible analysis task for plotting climatologies of any MPAS-Ocean field
A flexible analysis task for plotting climatologies of any MPAS-Ocean field
on cells from timeSeriesStatsMonthly at various depths (if the field has
vertical levels) and for various seasons. Various derived fields are also
supported:
* velocity magnitude
* thermal forcing (temperature - freezing temperature)
vertical levels) and for various seasons.

Various derived fields are also supported:

* velocity magnitude
* thermal forcing (temperature - freezing temperature)
"""

def __init__(self, config, mpasClimatologyTask, controlConfig=None):
Expand Down
97 changes: 38 additions & 59 deletions mpas_analysis/shared/html/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from os import makedirs
from pathlib import Path

import pkg_resources
import importlib.resources as resources
from lxml import etree

import mpas_analysis.version
Expand Down Expand Up @@ -66,13 +66,13 @@ def generate_html(config, analyses, controlConfig, customConfigFiles):
try:
ComponentPage.add_image(fileName, config, components,
controlConfig)
except IOError:
print(' missing file {}'.format(fileName))
except IOError as e:
print(f'Error reading {fileName}: {e}')
missingCount += 1

if missingCount > 0:
print('Warning: {} XML files were missing and the analysis website'
' will be incomplete.'.format(missingCount))
print(f'Warning: {missingCount} XML files could not be read and the '
f'analysis website will be incomplete.')
# generate the page for each component and add the component to the main
# page
for componentName, component in components.items():
Expand Down Expand Up @@ -155,24 +155,15 @@ def __init__(self, config, controlConfig, customConfigFiles):
self.customConfigFiles = customConfigFiles

# get template text
fileName = \
pkg_resources.resource_filename(__name__,
"templates/main_page.html")

with open(fileName, 'r') as templateFile:
self.pageTemplate = templateFile.read()

fileName = \
pkg_resources.resource_filename(__name__,
"templates/main_component.html")
with open(fileName, 'r') as templateFile:
self.componentTemplate = templateFile.read()

fileName = \
pkg_resources.resource_filename(__name__,
"templates/config.html")
with open(fileName, 'r') as templateFile:
self.configTemplate = templateFile.read()
package = 'mpas_analysis.shared.html.templates'
templates = {}
for name in ['main_page', 'main_component', 'config']:
resource = resources.files(package).joinpath(f'{name}.html')
with resource.open('r') as templateFile:
templates[name] = templateFile.read()
self.pageTemplate = templates['main_page']
self.componentTemplate = templates['main_component']
self.configTemplate = templates['config']

# start with no components
self.components = OrderedDict()
Expand Down Expand Up @@ -273,45 +264,34 @@ def generate(self):

pageText = _replace_tempate_text(self.pageTemplate, replacements)

htmlBaseDirectory = build_config_full_path(self.config, 'output',
'htmlSubdirectory')
htmlBaseDirectory = build_config_full_path(
self.config, 'output', 'htmlSubdirectory'
)

for subdir in ['css', 'js']:
try:
makedirs('{}/{}'.format(htmlBaseDirectory, subdir))
except OSError:
pass
makedirs(f'{htmlBaseDirectory}/{subdir}', exist_ok=True)

outFileName = '{}/index.html'.format(htmlBaseDirectory)
outFileName = f'{htmlBaseDirectory}/index.html'

with open(outFileName, mode='w') as mainFile:
mainFile.write(
pageText.encode('ascii',
'xmlcharrefreplace').decode('ascii'))
pageText.encode('ascii', 'xmlcharrefreplace').decode('ascii')
)

# copy the css and js files as well as general images
fileName = \
pkg_resources.resource_filename(__name__,
"templates/style.css")
copyfile(fileName, '{}/css/style.css'.format(htmlBaseDirectory))

fileName = \
pkg_resources.resource_filename(__name__,
"templates/index.js")
copyfile(fileName, '{}/js/index.js'.format(htmlBaseDirectory))

fileName = \
pkg_resources.resource_filename(__name__,
"templates/mpas_logo.png")
copyfile(fileName, '{}/mpas_logo.png'.format(htmlBaseDirectory))

fileName = \
pkg_resources.resource_filename(__name__,
"templates/config.png")
copyfile(fileName, '{}/config.png'.format(htmlBaseDirectory))

with open('{}/complete.{}.cfg'.format(htmlBaseDirectory,
runName), 'w') as configFile:
resource_targets = [
("style.css", "css/style.css"),
("index.js", "js/index.js"),
("mpas_logo.png", "mpas_logo.png"),
("config.png", "config.png"),
]
for resource_name, target_path in resource_targets:
package = 'mpas_analysis.shared.html.templates'
fileName = resources.files(package).joinpath(resource_name)
copyfile(str(fileName), f'{htmlBaseDirectory}/{target_path}')

outFileName = f'{htmlBaseDirectory}/complete.{runName}.cfg'
with open(outFileName, 'w') as configFile:
self.config.write(configFile)


Expand Down Expand Up @@ -386,11 +366,10 @@ def __init__(self, config, name, subdirectory, controlConfig=None):
for templateName in ['page', 'quicklink', 'group', 'gallery', 'image',
'subtitle']:
# get template text
fileName = pkg_resources.resource_filename(
__name__,
"templates/component_{}.html".format(templateName))

with open(fileName, 'r') as templateFile:
package = 'mpas_analysis.shared.html.templates'
resource = resources.files(package).joinpath(
f'component_{templateName}.html')
with resource.open('r') as templateFile:
self.templates[templateName] = templateFile.read()

# start with no groups
Expand Down
Empty file.