Skip to content

Writing Tutorials #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
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
6 changes: 3 additions & 3 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Release Notes
.. current developments

v0.0.1
====================
------

**Changed:**
**Added:**

* Fixed rever GH address
* INSERT SYNOPSIS
2 changes: 1 addition & 1 deletion diffpy/pdfmorph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""

# obtain version information
__version__ = '0.0.1'
from diffpy.pdfmorph.version import __version__

# top-level import
from diffpy.pdfmorph.pdfmorph_api import pdfmorph, morph_default_config, plot_morph
Expand Down
4 changes: 2 additions & 2 deletions diffpy/pdfmorph/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
def set_verbosity(vb):
'''Set verbosity of the pdfmorph logger.

vb -- integer or one of ('debug', 'info', 'warning', 'error') strings
:param vb: integer or one of ('debug', 'info', 'warning', 'error') strings.

No return value.
:return: No return value.
'''
try:
if type(vb) is str:
Expand Down
17 changes: 6 additions & 11 deletions diffpy/pdfmorph/morph_helpers/transformpdftordf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,23 @@
##############################################################################


"""class TransformXtalPDFtoRDF -- Transform crystal PDFs to RDFs.
"""
"""Transform crystal PDFs to RDFs."""


from diffpy.pdfmorph.morphs.morph import *


class TransformXtalPDFtoRDF(Morph):
'''Transform crystal PDFs to RDFs.

Converts both morph data and target data PDFs to RDFs.
"""Converts both morph data and target data PDFs to RDFs.

Configuration variables:

baselineslope -- The slope of the PDF baseline. With the perfect scale,
the baseline slope is equal to -4*pi*rho0, where rho0
is the density of the crystalline sample.
:param baselineslope: The slope of the PDF baseline. With the perfect scale, the baseline slope is equal to
:math:`-4\\pi\\rho_0`, where :math:`\\rho_0` is the density of the crystalline sample.

With s = baselineslope,
R(r) = r * (G(r) - r * s)
With :math:`s` being the baselineslope, :math:`R(r) = r * (G(r) - rs)`.

'''
"""

# Define input output types
summary = 'Turn the PDF into the RDF for both the morph and target'
Expand Down
25 changes: 12 additions & 13 deletions diffpy/pdfmorph/morph_helpers/transformrdftopdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,28 @@
##############################################################################


"""class TransformXtalRDFtoPDF -- Transform crystal RDFs to PDFs.
"""Transform crystal RDFs to PDFs.
"""


from diffpy.pdfmorph.morphs.morph import *
import numpy


class TransformXtalRDFtoPDF(Morph):
'''Transform crystal RDFs to PDFs.

Converts both morph data and target data RDFs to PDFs.
"""Converts both morph data and target data RDFs to PDFs.

Configuration variables:

baselineslope -- The slope of the PDF baseline. With the perfect scale,
the baseline slope is equal to -4*pi*rho0, where rho0
is the density of the crystalline sample.
:param baselineslope: The slope of the PDF baseline. With the perfect scale, the baseline slope is equal to
:math:`-4\\pi\\rho_0`, where :math:`\\rho_0` is the density of the crystalline sample.

With s = baselineslope,
G(r) = R(r) / r + r * s
With :math:`s` as the baselineslope, :math:`G(r) = R(r) / r + rs`.

'''
"""

# Define input output types
summary = 'Turn the PDF into the RDF for both the morph and target'
summary = 'Turn the PDF into the RDF for both the morph and target.'
xinlabel = LABEL_RA
yinlabel = LABEL_RR
xoutlabel = LABEL_RA
Expand All @@ -50,10 +47,12 @@ def morph(self, x_morph, y_morph, x_target, y_target):
Morph.morph(self, x_morph, y_morph, x_target, y_target)
morph_baseline = self.baselineslope * self.x_morph_in
target_baseline = self.baselineslope * self.x_target_in
self.y_target_out = self.y_target_in / self.x_target_in + target_baseline
with numpy.errstate(divide='ignore', invalid='ignore'):
self.y_target_out = self.y_target_in / self.x_target_in + target_baseline
if self.x_target_in[0] == 0:
self.y_target_out[0] = 0
self.y_morph_out = self.y_morph_in / self.x_morph_in + morph_baseline
with numpy.errstate(divide='ignore', invalid='ignore'):
self.y_morph_out = self.y_morph_in / self.x_morph_in + morph_baseline
if self.x_morph_in[0] == 0:
self.y_morph_out[0] = 0
return self.xyallout
Expand Down
44 changes: 27 additions & 17 deletions diffpy/pdfmorph/pdfmorph_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def morph_default_config(**kwargs):

Examples
--------
morph_cfg = morph_default_config(scale=1.01)
.. code-block:: python

morph_cfg = morph_default_config(scale=1.01)
"""
rv = dict(_default_config)
# protect against foreign keys
Expand Down Expand Up @@ -107,7 +109,7 @@ def pdfmorph(
A value to specify rstep of morph operations.
pearson: Bool, optional
Option to include Pearson coefficient as a minimizing target
during morphing. Default to False.
during morphing. Default to False.
add_pearson: Bool, optional
Option to include **both** Pearson coefficient and Rw as
minimizing targets during morphing. Default to False.
Expand Down Expand Up @@ -146,24 +148,32 @@ def pdfmorph(
The agreement factor between morphed data and reference
data
- pcc : float
The pearson correlation coefficient between morphed
data and referenced data
The pearson correlation coefficient between morphed data and
referenced data

Examples
--------
# morphing (x_morph, y_morph) pair to (x_target, y_target) pair with scaling
from diffpy.pdfmorph.pdfmorph_api import pdfmorph, morph_default_config, plot_morph
morphing (x_morph, y_morph) pair to (x_target, y_target) pair with scaling
.. code-block:: python

from diffpy.pdfmorph.pdfmorph_api import pdfmorph, morph_default_config, plot_morph
morph_cfg = morph_default_config(scale=1.01)
morph_rv_dict = pdfmorph(x_morph, y_morph, x_target, y_target, **morph_cfg)


plot morphing result
.. code-block:: python

plot_morph(morph_rv_dict['morph_chain'])


morph_cfg = morph_default_config(scale=1.01)
morph_rv_dict = pdfmorph(x_morph, y_morph, x_target, y_target, **morph_cfg)
print morphing parameters, pearson correlation coefficient, Rw
.. code-block:: python

# plot morhing result
plot_morph(morph_rv_dict['morph_chain'])
print(morph_rv_dict['morphed_cfg'])
print(morph_rv_dict['pcc'])
print(morph_rv_dict['rw'])

# print morphing parameters, pearson correlation coefficient, Rw
print(morph_rv_dict['morphed_cfg'])
print(morph_rv_dict['pcc'])
print(morph_rv_dict['rw'])
"""
operation_dict = {}
refpars = []
Expand Down Expand Up @@ -253,16 +263,16 @@ def plot_morph(chain, ax=None, **kwargs):
ax: matplotlib.axes.Axes, optinal
An instance of Axes class to plot the morphing result.
If ax is None, instances of new Figure and Axes will
be created. Default to None.
be created. Default to None.
kwargs:
Additional keyword arguements will be passed
to ``ax.plot(...**kwargs)``
to ``ax.plot(...**kwargs)``

Returns
-------
l_list: list
A list of ``matplotlib.lines.Line2D`` objects representing
the plotted data.
the plotted data.
"""
if ax is None:
fig, ax = plt.subplots()
Expand Down
Loading