Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Jul 28, 2024
1 parent fa4a85b commit 7382e0e
Show file tree
Hide file tree
Showing 68 changed files with 5,200 additions and 4,992 deletions.
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ include doc/examples/README
recursive-include doc/manual/source *.rst *.txt
include doc/manual/source/conf.py
include doc/manual/Makefile

34 changes: 18 additions & 16 deletions devutils/prep.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python
# Run examples and other scripts that should be updated before release.

import io, os, sys
import io
import os
import re
import sys

__basedir__ = os.getcwdu()

Expand All @@ -25,15 +27,15 @@ def test(self, call, *args, **kwds):
except Exception, e:
self.messages.append("%s: error, details below.\n%s" %(testname, e))
finally:
os.chdir(__basedir__)
os.chdir(__basedir__)

def report(self):
print '==== Results of Tests ===='
print '\n'.join(self.messages)

def scrubeol(directory, filerestr):
"""Use unix-style endlines for files in directory matched by regex string.
Parameters
----------
directory - A directory to scrub
Expand All @@ -42,22 +44,22 @@ def scrubeol(directory, filerestr):
os.chdir(directory)
files = [re.match(filerestr, f) for f in os.listdir(".")]
files = [f.group(0) for f in files if f]

for f in files:
original = open(f)
text = unicode(original.read())
original.close()

updated = io.open(f, 'w', newline='\n')
updated.write(text)
updated.close()

print "Updated %s to unix-style endlines." %f


def rm(directory, filerestr):
"""Delete files in directory matched by regex string.
Parameters
----------
directory - A directory to scrub
Expand All @@ -66,20 +68,20 @@ def rm(directory, filerestr):
os.chdir(directory)
files = [re.match(filerestr, f) for f in os.listdir(".")]
files = [f.group(0) for f in files if f]

for f in files:
os.remove(f)

print "Deleted %s." %f



if __name__ == "__main__":

# Temporarily add examples to path
lib_path = os.path.abspath(os.path.join('..','doc','examples'))
sys.path.append(lib_path)

# Delete existing files that don't necessarily have a fixed name.
rm("../doc/examples/output", r"known_dG.*\.pwa")
rm("../doc/examples/output", r"unknown_dG.*\.pwa")
Expand All @@ -88,7 +90,7 @@ def rm(directory, filerestr):
examples = Test()
test_names = ["extract_single_peak",
"parameter_summary",
"fit_initial",
"fit_initial",
"query_results",
"multimodel_known_dG1",
"multimodel_known_dG2",
Expand All @@ -103,11 +105,11 @@ def rm(directory, filerestr):
examples.test(test.run, plot=False)

examples.report()

### Convert output of example files to Unix-style endlines for sdist.
if os.linesep != '\n':
print "==== Scrubbing Endlines ===="
# All *.srmise and *.pwa files in examples directory.
scrubeol("../doc/examples/output", r".*(\.srmise|\.pwa)")


2 changes: 1 addition & 1 deletion diffpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"""


__import__('pkg_resources').declare_namespace(__name__)
__import__("pkg_resources").declare_namespace(__name__)


# End of file
22 changes: 16 additions & 6 deletions diffpy/srmise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,28 @@

"""Tools for peak extraction from PDF."""

__all__ = ["basefunction", "srmiseerrors", "srmiselog", "dataclusters",
"modelcluster", "modelparts", "pdfdataset", "pdfpeakextraction",
"peakextraction", "peakstability", "multimodelselection"]

from diffpy.srmise.version import __version__
__all__ = [
"basefunction",
"srmiseerrors",
"srmiselog",
"dataclusters",
"modelcluster",
"modelparts",
"pdfdataset",
"pdfpeakextraction",
"peakextraction",
"peakstability",
"multimodelselection",
]

from basefunction import BaseFunction
from dataclusters import DataClusters
from modelcluster import ModelCluster, ModelCovariance
from modelparts import ModelPart, ModelParts
from multimodelselection import MultimodelSelection
from pdfdataset import PDFDataSet
from pdfpeakextraction import PDFPeakExtraction
from peakextraction import PeakExtraction
from peakstability import PeakStability
from multimodelselection import MultimodelSelection

from diffpy.srmise.version import __version__
20 changes: 11 additions & 9 deletions diffpy/srmise/applications/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
#
##############################################################################

from optparse import OptionParser, OptionGroup
import numpy as np
from optparse import OptionGroup, OptionParser

import matplotlib.pyplot as plt
import numpy as np


def main():
"""Default SrMise entry-point."""
Expand Down Expand Up @@ -78,7 +80,7 @@ def main():
version=version,
formatter=IndentedHelpFormatterWithNL())

parser.set_defaults(plot=False, liveplot=False, wait=False,
parser.set_defaults(plot=False, liveplot=False, wait=False,
performextraction=True, verbosity="warning")
dg_defaults = {'absolute':None, 'data':None, 'max-fraction':.05,
'ptp-fraction':.05, 'dG-fraction':1.}
Expand Down Expand Up @@ -203,7 +205,7 @@ def main():
"'absolute'=%s\n"
"'max-fraction'=%s\n"
"'ptp-fraction'=%s\n"
"'dG-fraction'=%s" %(dg_defaults['absolute'],
"'dG-fraction'=%s" %(dg_defaults['absolute'],
dg_defaults['max-fraction'],
dg_defaults['ptp-fraction'],
dg_defaults['dG-fraction']))
Expand Down Expand Up @@ -269,8 +271,7 @@ def main():
srmiselog.setlevel(options.verbosity)

from diffpy.srmise.pdfpeakextraction import PDFPeakExtraction
from diffpy.srmise.srmiseerrors import SrMiseDataFormatError, \
SrMiseFileError
from diffpy.srmise.srmiseerrors import SrMiseDataFormatError, SrMiseFileError

if options.peakfunction is not None:
from diffpy.srmise import peaks
Expand Down Expand Up @@ -364,7 +365,7 @@ def main():
elif options.dg_mode == "ptp-fraction":
pdict["effective_dy"] = options.dg*ext.y.ptp()*np.ones(len(ext.y))
elif options.dg_mode == "dG-fraction":
pdict["effective_dy"] = options.dg*ext.dy
pdict["effective_dy"] = options.dg*ext.dy
if options.rng is not None:
pdict["rng"] = list(options.rng)
if options.qmax is not None:
Expand Down Expand Up @@ -403,7 +404,7 @@ def main():
print err
print "Could not save pwa summary to '%s'." %options.pwafile


print ext
if cov is not None:
print cov
Expand Down Expand Up @@ -442,8 +443,9 @@ def parsepars(mp, parseq):
# Borrowed, with minor changes, from
# http://groups.google.com/group/comp.lang.python/browse_frm/thread/6df6e6b541a15bc2/09f28e26af0699b1

from optparse import IndentedHelpFormatter
import textwrap
from optparse import IndentedHelpFormatter


class IndentedHelpFormatterWithNL(IndentedHelpFormatter):
def _format_text(self, text):
Expand Down
11 changes: 5 additions & 6 deletions diffpy/srmise/applications/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@
##############################################################################
"""plot extracted peaks and comparison to ideal distances (if given)"""

import sys
import optparse

from diffpy.srmise import PDFPeakExtraction, PeakStability
from diffpy.srmise.pdfpeakextraction import resample
import sys

import matplotlib.pyplot as plt
import mpl_toolkits.axisartist as AA
import numpy as np

from mpl_toolkits.axes_grid1 import make_axes_locatable
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
import mpl_toolkits.axisartist as AA

from diffpy.srmise import PDFPeakExtraction, PeakStability
from diffpy.srmise.pdfpeakextraction import resample

# For a given figure, returns a label of interest
labeldict = {}
Expand Down
7 changes: 4 additions & 3 deletions diffpy/srmise/basefunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
##############################################################################
"""Defines BaseFunction, the base class for mathematical functions in srmise."""

import sys
import logging
import re
import sys

import numpy as np

from diffpy.srmise.modelparts import ModelPart, ModelParts
from diffpy.srmise.srmiseerrors import *
from diffpy.srmise.modelparts import ModelParts, ModelPart

import logging
logger = logging.getLogger("diffpy.srmise")

class BaseFunction(object):
Expand Down
2 changes: 1 addition & 1 deletion diffpy/srmise/baselines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

__all__ = ["base", "arbitrary", "fromsequence", "nanospherical", "polynomial"]

from base import Baseline
from arbitrary import Arbitrary
from base import Baseline
from fromsequence import FromSequence
from nanospherical import NanoSpherical
from polynomial import Polynomial
8 changes: 5 additions & 3 deletions diffpy/srmise/baselines/arbitrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
#
##############################################################################

import logging

import matplotlib.pyplot as plt
import numpy as np

import diffpy.srmise.srmiselog
from diffpy.srmise.baselines.base import BaselineFunction
from diffpy.srmise.srmiseerrors import SrMiseEstimationError

import matplotlib.pyplot as plt

import logging, diffpy.srmise.srmiselog
logger = logging.getLogger("diffpy.srmise")

class Arbitrary (BaselineFunction):
Expand Down
Loading

0 comments on commit 7382e0e

Please sign in to comment.