diff --git a/CHANGELOG b/CHANGELOG index 68e0de1a..0b8ab764 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +1.1.1 + - Fix plotting error with LaTeX (thanks @toubol) (#179) + - Update documentation 1.1.0 - BREAKING CHANGE: Move to Python3 (thanks @toubol) (#173) - GUI: diff --git a/docs/sec_contribute.rst b/docs/sec_contribute.rst index c4601478..73e4457a 100644 --- a/docs/sec_contribute.rst +++ b/docs/sec_contribute.rst @@ -33,46 +33,86 @@ the PyCorrFit issue page on GitHub such that we may coordinate a pull request. +For documentation writers +========================= +To build this documentation, fork PyCorrFit, navigate +to the `docs` (not `doc`) directory and run. + +- ``pip install -r requirements.txt`` followed by +- ``sphinx-build . _build``. + +This will create the html documentation on your computer. Syntax warnings and errors +will be displayed during the build (there should be none). After making your +changes to your forked branch, create a pull request on GitHub. + +If you only found a typo or wish to make text-only changes, you can also +use the GitHub interface to edit the files (without testing the build +step on your computer). + + For developers ============== -If you would like to know how a contribution to PyCorrFit should look -like, please create an issue on GitHub and I will update this part -of the documentation. - Running from source ------------------- -The easiest way to run PyCorrFit from source is to use -`Anaconda `_. PyCorrFit requires wxPython which is not -available at the Python package index. Make sure you install a unicode version of wxPython. -Detailed installation instructions are `here `_. - - -Contributing ------------- -The main branch for developing PyCorrFit is *develop*. Small changes that do not -break anything can be submitted to this branch. -If you want to do big changes, please (fork ShapeOut and) create a separate branch, -e.g. ``my_new_feature_dev``, and create a pull-request to *develop* once you are done making -your changes. -Please make sure to also update the -`changelog `_. - -Tests ------ +It is recommended to work with +`virtual environments `_. + +Windows +~~~~~~~ +The easiest way to run PyCorrFit from source on Windows is +`Anaconda `_. + +- ``conda install matplotlib numpy pip scipy wxpython`` +- ``pip install cython wheel simplejson sympy lmfit`` +- ``pip install -e . # in the root directory of the repository`` + +Ubuntu 17.10 +~~~~~~~~~~~~ +PyCorrFit requires wxPython >= 4.0.1 which is not available as a binary +wheel on PyPI and thus must be built from the .tar.gz. +Install all dependencies (https://github.com/wxWidgets/Phoenix/blob/master/README.rst): + +- ``pip install cython matplotlib lmfit numpy scipy sympy`` +- ``sudo apt-get install -qq libgtk2.0 libgtk2.0-dev libwebkitgtk-dev dpkg-dev build-essential python3.6-dev libjpeg-dev libtiff-dev libsdl1.2-dev libnotify-dev freeglut3 freeglut3-dev libsm-dev libgtk-3-dev libwebkit2gtk-4.0-dev libxtst-dev libgstreamer-plugins-base1.0-dev`` +- ``pip install wxPython # this will take some time`` +- ``pip install -e . # in the root directory of the repository`` + +Testing +------- PyCorrFit is tested using pytest. If you have the time, please write test methods for your code and put them in the ``tests`` directory. You may -run the tests manually by issuing: +run all tests by issuing: :: python setup.py test +Pull request guidelines +----------------------- +Please fork PyCorrFit and create a pull request (PR) introducing your changes. + +- A new PR should always be made into the `develop` branch. +- If a PR introduces a new functionality or fixes a bug, it should provide + a test case, i.e. a new file or function in the `tests` directory + (see `here `_ + for examples). + Note that currently there is no recipe for testing the graphical user + interface code. +- New code should follow the + `style guide for Python `_. + Please use `flake8 `_ + to check the files you changed or created. +- New code should be documented well. +- Make sure to update the `changelog `_. + + Windows test binaries --------------------- After each commit to the PyCorrFit repository, a binary installer is created by `Appveyor `_. Click on a build and navigate to ``ARTIFACTS`` (upper right corner right under -the running time of the build). From there you can download the Windows installer of the commit. +the running time of the build). From there you can download the Windows +installer for the commit. diff --git a/pycorrfit/gui/misc.py b/pycorrfit/gui/misc.py index d4191804..53402466 100644 --- a/pycorrfit/gui/misc.py +++ b/pycorrfit/gui/misc.py @@ -108,6 +108,6 @@ def getMainIcon(pxlength=32): image = wx.Bitmap.ConvertToImage(iconBMP) image = image.Scale(pxlength, pxlength, wx.IMAGE_QUALITY_HIGH) iconBMP = wx.Bitmap(image) - iconICO = wx.Icon(iconBMP) # wx.Bitmap.ConvertToImage(iconBMP) + iconICO = wx.Icon(iconBMP) return iconICO diff --git a/pycorrfit/gui/plotting.py b/pycorrfit/gui/plotting.py index 52951bce..22b095be 100644 --- a/pycorrfit/gui/plotting.py +++ b/pycorrfit/gui/plotting.py @@ -7,6 +7,7 @@ import matplotlib import numpy as np +import re # We do catch warnings about performing this before matplotlib.backends stuff with warnings.catch_warnings(): @@ -70,6 +71,7 @@ def latexmath(string): unicodechars["³"] = r"^3" unicodechars["₁"] = r"_1" unicodechars["₂"] = r"_2" + unicodechars["₃"] = r"_3" unicodechars["₀"] = r"_0" #unicodechars["α"] = r"\alpha" # We need lambda in here, because unicode names it lamda sometimes. @@ -107,6 +109,26 @@ def latexmath(string): return anew + r" \hspace{0.3em} \mathrm{"+b+r"}" +def genLatexText(parm, labels): + """Generate the LaTeX text for the plot with handling multiple underscores + in the labels. + """ + text = r'' + for i in np.arange(len(parm)): + line = r' {} &= {:.3g} \\'.format(latexmath(labels[i]), parm[i]) + match = re.search(r'\\text\{(.*?)\}', line) + if match: + if '_' in match.groups()[0]: + tmpstr = match.groups()[0].split('_') + if ''.join(tmpstr).isnumeric(): + line = line.replace(match.groups()[0], ''.join(tmpstr)) + elif len(tmpstr) == 2: + tmpstr = '$_'.join(tmpstr) + '$' + line = line.replace(match.groups()[0], tmpstr) + text += line + return text + + def savePlotCorrelation(parent, dirname, Page, uselatex=False, verbose=False, show_weights=True): """ Save plot from Page into file @@ -215,11 +237,9 @@ def savePlotCorrelation(parent, dirname, Page, uselatex=False, # Add some nice text: if uselatex == True and len(parms) != 0: text = r"" - text += r'\[' #every line is a separate raw string... - text += r'\begin{split}' # ...but they are all concatenated - # by the interpreter :-) - for i in np.arange(len(parms)): - text += r' {} &= {:.3g} \\'.format(latexmath(labels[i]), parms[i]) + text += r'\[' + text += r'\begin{split}' + text += genLatexText(parms, labels) ## According to issue #54, we remove fitting errors from plots #if errparms is not None: # keys = errparms.keys() @@ -422,4 +442,4 @@ def savePlotTrace(parent, dirname, Page, uselatex=False, verbose=False): pass # set dpi to 300 -matplotlib.rcParams['savefig.dpi'] = 300 \ No newline at end of file +matplotlib.rcParams['savefig.dpi'] = 300