Skip to content

Commit

Permalink
Fix PEP8
Browse files Browse the repository at this point in the history
  • Loading branch information
xylar committed Apr 20, 2022
1 parent 1cee1b7 commit c76d76d
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 48 deletions.
5 changes: 2 additions & 3 deletions mpas_analysis/ocean/sose_transects.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,8 @@ def combine_observations(self):
continue
print(' {}'.format(field['prefix']))

fileName = '{}/SOSE_2005-2010_monthly_{}_SouthernOcean' \
'_0.167x0.167degree_20180710.nc'.format(
observationsDirectory, prefix)
fileName = f'{observationsDirectory}/SOSE_2005-2010_monthly_' \
f'{prefix}_SouthernOcean_0.167x0.167degree_20180710.nc'

dsLocal = xr.open_dataset(fileName)

Expand Down
4 changes: 2 additions & 2 deletions mpas_analysis/ocean/time_series_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,12 +604,12 @@ def run_task(self):
fields = [transport]
lineColors = [config.get('timeSeries', 'mainColor')]
lineWidths = [2.5]
meanString = 'mean={:.2f} $\pm$ {:.2f}'.format(trans_mean, trans_std)
meanString = 'mean={:.2f} $\\pm$ {:.2f}'.format(trans_mean, trans_std)
if plotControl:
controlRunName = self.controlConfig.get('runs', 'mainRunName')
ref_transport, ref_mean, ref_std = \
self._load_transport(self.controlConfig)
refMeanString = 'mean={:.2f} $\pm$ {:.2f}'.format(ref_mean, ref_std)
refMeanString = f'mean={ref_mean:.2f} $\\pm$ {ref_std:.2f}'
fields.append(ref_transport)
lineColors.append(config.get('timeSeries', 'controlColor'))
lineWidths.append(1.2)
Expand Down
12 changes: 6 additions & 6 deletions mpas_analysis/shared/analysis_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,12 @@ def check_analysis_enabled(self, analysisOptionName, default=False,
except ValueError:
enabled = default
if default:
print('Warning: namelist option {} not found.\n'
'This likely indicates that the simulation you '
'are analyzing was run with an\n'
'older version of MPAS-O that did not support '
'this flag. Assuming enabled.'.format(
analysisOptionName))
print(f'Warning: namelist option {analysisOptionName} not '
f'found.\n'
f'This likely indicates that the simulation you '
f'are analyzing was run with an\n'
f'older version of MPAS-O that did not support '
f'this flag. Assuming enabled.')

if not enabled and raiseException:
raise RuntimeError('*** MPAS-Analysis relies on {} = .true.\n'
Expand Down
4 changes: 2 additions & 2 deletions mpas_analysis/shared/climatology/climatology.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,8 @@ def _cache_aggregated_climatology(startYearClimo, endYearClimo, cachePrefix,
done = True

elif climatology is not None:
monthsIfDone = (
endYearClimo - startYearClimo + 1) * len(monthValues)
monthsIfDone = ((endYearClimo - startYearClimo + 1)
* len(monthValues))
if climatology.attrs['totalMonths'] == monthsIfDone:
# also complete, so we can move on
done = True
Expand Down
22 changes: 11 additions & 11 deletions mpas_analysis/shared/climatology/mpas_climatology_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,10 @@ def run_task(self):
# subtasks will take care of it, so nothing to do
return

self.logger.info('\nComputing MPAS climatologies from files:\n'
' {} through\n {}'.format(
os.path.basename(self.inputFiles[0]),
os.path.basename(self.inputFiles[-1])))
self.logger.info(
f'\nComputing MPAS climatologies from files:\n'
f' {os.path.basename(self.inputFiles[0])} through\n'
f' {os.path.basename(self.inputFiles[-1])}')

seasonsToCheck = list(constants.abrevMonthNames)

Expand Down Expand Up @@ -419,9 +419,9 @@ def _create_symlinks(self):
make_directories(symlinkDirectory)

for inFileName, year, month in zip(fileNames, years, months):
outFileName = '{}/{}.hist.am.timeSeriesStatsMonthly.{:04d}-' \
'{:02d}-01.nc'.format(symlinkDirectory, self.ncclimoModel,
year, month)
outFileName = \
f'{symlinkDirectory}/{self.ncclimoModel}.hist.am.' \
f'timeSeriesStatsMonthly.{year:04d}-{month:02d}-01.nc'

try:
os.symlink(inFileName, outFileName)
Expand Down Expand Up @@ -621,10 +621,10 @@ def run_task(self):
# nothing to do
return

self.logger.info('\nComputing MPAS climatology from files:\n'
' {} through\n {}'.format(
os.path.basename(parentTask.inputFiles[0]),
os.path.basename(parentTask.inputFiles[-1])))
self.logger.info(
f'\nComputing MPAS climatologies from files:\n'
f' {os.path.basename(parentTask.inputFiles[0])} through\n'
f' {os.path.basename(parentTask.inputFiles[-1])}')

climatologyFileName = parentTask.get_file_name(season)
climatologyDirectory = get_unmasked_mpas_climatology_directory(
Expand Down
30 changes: 18 additions & 12 deletions mpas_analysis/shared/html/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ def generate(self):

# substitute entries in the template and add the component to
# the text describing all components
componentsText = componentsText + \
_replace_tempate_text(self.componentTemplate, replacements)
componentsText = \
componentsText + \
_replace_tempate_text(self.componentTemplate, replacements)

githash = _get_git_hash()
if githash is None:
Expand All @@ -245,14 +246,16 @@ def generate(self):
replacements = {'@configName': os.path.basename(configFileName),
'@configDesc': shortName}

configsText = configsText + \
_replace_tempate_text(self.configTemplate, replacements)
configsText = \
configsText + \
_replace_tempate_text(self.configTemplate, replacements)

replacements = {'@configName': 'complete.{}.cfg'.format(runName),
'@configDesc': 'Complete Configuration File'}

configsText = configsText + \
_replace_tempate_text(self.configTemplate, replacements)
configsText = \
configsText + \
_replace_tempate_text(self.configTemplate, replacements)

replacements = {'@runName': runName,
'@controlRunText': controlRunText,
Expand Down Expand Up @@ -494,11 +497,13 @@ def generate(self):
quickLinkText = ''
galleriesText = ''
for groupName, groupDict in self.groups.items():
quickLinkText = quickLinkText + \
self._generate_quick_link_text(groupName, groupDict)
quickLinkText = \
quickLinkText + \
self._generate_quick_link_text(groupName, groupDict)

galleriesText = galleriesText + \
self._generate_group_text(groupName, groupDict)
galleriesText = \
galleriesText + \
self._generate_group_text(groupName, groupDict)

replacements = {'@runName': runName,
'@controlRunText': controlRunText,
Expand Down Expand Up @@ -592,8 +597,9 @@ def _generate_group_text(self, groupName, groupDict):
"""
galleriesText = ''
for galleryName, galleryDict in groupDict['galleries'].items():
galleriesText = galleriesText + \
self._generate_gallery_text(galleryName, galleryDict['images'])
galleriesText = \
galleriesText + \
self._generate_gallery_text(galleryName, galleryDict['images'])

replacements = {'@analysisGroupName': groupName,
'@analysisGroupLink': groupDict['link'],
Expand Down
7 changes: 4 additions & 3 deletions mpas_analysis/shared/plot/vertical_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,15 +963,16 @@ def plot_vertical_section(
h2, _ = cs2.legend_elements()
if labelContours:
originalFieldName = originalFieldName + " (" + colorbarLabel + ")"
comparisonFieldName = comparisonFieldName + " (" + \
colorbarLabel + ")"
comparisonFieldName = (comparisonFieldName + " (" +
colorbarLabel + ")")
ax.legend([h1[0], h2[0]], [originalFieldName, comparisonFieldName],
loc='upper center', bbox_to_anchor=(0.5, -0.25), ncol=1)

if title is not None:
if plotAsContours and labelContours \
and contourComparisonField is None:
title = limit_title(title, maxTitleLength - (3 + len(colorbarLabel)))
title = limit_title(title,
maxTitleLength - (3 + len(colorbarLabel)))
title = title + " (" + colorbarLabel + ")"
else:
title = limit_title(title, maxTitleLength)
Expand Down
9 changes: 4 additions & 5 deletions mpas_analysis/shared/time_series/mpas_time_series_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,10 @@ def setup_and_check(self):
raise IOError('No files were found in stream {} between {} and '
'{}.'.format(streamName, startDate, endDate))

self.runMessage = '\nComputing MPAS time series from first year ' \
'plus files:\n' \
' {} through\n {}'.format(
os.path.basename(self.inputFiles[0]),
os.path.basename(self.inputFiles[-1]))
self.runMessage = \
f'\nComputing MPAS time series from first year plus files:\n' \
f' {os.path.basename(self.inputFiles[0])} through\n' \
f' {os.path.basename(self.inputFiles[-1])}'

# Make sure first year of data is included for computing anomalies
if config.has_option('timeSeries', 'anomalyRefYear'):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class ComputeTransectMasksSubtask(AnalysisTask):
# Xylar Asay-Davis

def __init__(self, parentTask, transectGroup, subprocessCount=None):

"""
Construct the analysis task and adds it as a subtask of the
``parentTask``.
Expand Down
6 changes: 3 additions & 3 deletions mpas_analysis/test/test_remap_obs_clim_subtask.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,6 @@ def test_subtask_get_file_name(self):

fileName = remapSubtask.get_file_name(stage=stage, season='JFM',
comparisonGridName='antarctic')
assert (fileName == '{}/clim/obs/remapped/mld_4.0x4.0degree_to_'
'6000.0x6000.0km_10.0km_Antarctic_stereo_JFM.nc'.format(
str(self.test_dir)))
assert (fileName == f'{str(self.test_dir)}/clim/obs/remapped/'
f'mld_4.0x4.0degree_to_6000.0x6000.0km_10.0km_'
f'Antarctic_stereo_JFM.nc')

0 comments on commit c76d76d

Please sign in to comment.