aperezhortal / SkewTplus

Atmospheric Profile Plotting and Diagnostics
Other
9 stars 8 forks source link

Change plot color #11

Open kenpryor67 opened 3 years ago

kenpryor67 commented 3 years ago

How can I change the dew point line plot color to green?

aperezhortal commented 3 years ago

Hi @kenpryor67, the latest version of the master branch (just merged) allows control some of the line colors with additional keywords to the add profile function.

# Add a profile to the Skew-T diagram
mySkewT_Axes2.addProfile(
    pressure,
    temperature,
    dewPointTemperature,
    hPa=True,
    celsius=True,
    method=0,
    diagnostics=False,
    tdColor="g",  # Dry temperature color
    tpColor="k", # Parcel temperature color
    twColor="b"  # Dew point temperature color
)

Let me know if this helps.

kenpryor67 commented 3 years ago

Andres, thanks very much for the quick response! Would these line color keywords work with the pip install version? I'm currently using version 1.1.2 (via pip install) and receiving a TypeError: There is no Line2D property "twcolor." Do I need to do a source install? Thanks again, Ken

aperezhortal commented 3 years ago

I haven't released a new version yet. You can try to install it directly from git with: pip install -U git+https://github.com/aperezhortal/SkewTplus.git

If that does not work, you can try installing it from the source: https://github.com/aperezhortal/SkewTplus/#install-from-source

kenpryor67 commented 3 years ago

Andres, I was able to successfully install SkewTplus from source on my Unix server (@ https://www.pythonanywhere.com/user/KenPryor67/files/home/KenPryor67/skewtplus/SkewTplus-master), however, I'm now receiving a number of import errors upon execution of an IPython notebook from the "SkewTplus-master" directory (e.g. ImportError: No module named _thermodynamics, etc.). I'm sure this is a path issue. Any work around for this? Thanks again very much for all your help!

aperezhortal commented 3 years ago

Hi @kenpryor67, I'm happy to help. That seems a path issue. _thermodynamics is a compiled extension that is built during the installation. You can try building the extension in place with python setup.py build_ext --inplace

That will compile the cython sources and place the .so library in the SkewTplus module.

Note that with this, you won't be using the installed version. Instead, you will be using the sources that you have in the SkewTplus-master folder.

Another solution is running the notebook from a different folder than the SkewTplus-master one. In this way, it will use the installed version.

kenpryor67 commented 3 years ago

Ok, the "setup.py build_ext --inplace" command worked, and no longer receiving any import errors. However, now I'm receiving a "fatalError: Input Data not supported Details: type(inputData)=<type 'str'>", upon attempting to read the "exampleSounding.txt" file, with the following code:

`# For python2.7 compatibility from future import print_function, division

Load the sounding class from the package

from SkewTplus.sounding import sounding

Load the sounding datas

mySounding = sounding("./exampleSounding.txt")

Show the SkewT diagram of the Sounding

mySounding.quickPlot()`

Should the file header be removed? Again, thanks for all your time and guidance with this.

aperezhortal commented 3 years ago

That is an unusual error. That exception shouldn't be raised if the input type is a string. Are you using python2.7 or python 3?

kenpryor67 commented 3 years ago

Yes- I am using python2.7. This error occurs even when I add the "#!/usr/bin/env python2.7" statement at the beginning of the script.

aperezhortal commented 3 years ago

My bad, there was a bug in the string-type checking that was only compatible with py3. Commit da16197b8aa2cb36d3f093404f5c18b2784109b3 should fix this issue.

kenpryor67 commented 3 years ago

Great! How do I proceed? Do I need to do a complete re-installation of the module?

aperezhortal commented 3 years ago

Yes, you can pull the changes to your local repo, and reinstall the package using pip. There is no need to do run the build_ext again to build the .so libraries in place since nothing changed on those extensions.

kenpryor67 commented 3 years ago

Andres- sorry to bother you again. I decided to do a complete re-install from source with the latest commit. Unfortunately now I'm receiving yet another odd error:

17:40 ~/skewtplus/SkewTplus-master $ python2.7 setup.py install --prefix=/home/KenPryor67/skewtplus/SkewTplus-master No local packages or working download links found for matplotlib>=3.1 Traceback (most recent call last): File "setup.py", line 69, in install_requires=build_requires, File "/usr/lib/python2.7/distutils/core.py", line 111, in setup _setup_distribution = dist = klass(attrs) File "/usr/local/lib/python2.7/dist-packages/setuptools/dist.py", line 317, in init self.fetch_build_eggs(attrs['setup_requires']) File "/usr/local/lib/python2.7/dist-packages/setuptools/dist.py", line 372, in fetch_build_eggs replace_conflicting=True, File "/usr/local/lib/python2.7/dist-packages/pkg_resources/init.py", line 851, in resolve dist = best[req.key] = env.best_match(req, ws, installer) File "/usr/local/lib/python2.7/dist-packages/pkg_resources/init.py", line 1123, in best_match return self.obtain(req, installer) File "/usr/local/lib/python2.7/dist-packages/pkg_resources/init.py", line 1135, in obtain return installer(requirement) File "/usr/local/lib/python2.7/dist-packages/setuptools/dist.py", line 440, in fetch_build_egg return cmd.easy_install(req) File "/usr/local/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 668, in easy_install raise DistutilsError(msg) distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('matplotlib>=3.1')

I set both PYTHONPATH and PATH to the directory "/home/KenPryor67/skewtplus/SkewTplus-master"

The latest release of Matplotlib for Python 2 is v2.2.5.

I should still be using python2.7 to run setup.py, correct? Thanks again,

aperezhortal commented 3 years ago

Yes, if you want to install the package for python2.7, you should use python2.7 setup.py to make sure that the extensions are compiled for the right python version.

Recently I merged a PR with updates for matplotlib>=3.1 versions (see #10). This introduced a compatibility problem with python2.7. Hence, the solution to this issue is not straightforward since I can't easily support Matplotlib <=2.2.5 for Python2 and Matplotlib>=3.1 for python3.

If migrating to python3 is not possible for you, the only solution I can think off is branching the repo from the 004f04585ecb776a7c2214d9f2fc9fcc30eef44a commit (python 2 compliant), and apply the changes made by commits 2b70409cabc4635c3eec7517d5008d9afc0f2249 and da16197b8aa2cb36d3f093404f5c18b2784109b3.

kenpryor67 commented 3 years ago

Great, thanks. This worked. The python2.7 version is now installed. However, now I'm receiving the following import error:

ImportError Traceback (most recent call last)

in () 5 from __future__ import print_function, division 6 ----> 7 from SkewTplus.skewT import figure 8 from SkewTplus.sounding import sounding 9 /home/KenPryor67/skewtplus/SkewTplus/SkewTplus/skewT.py in () 20 import matplotlib.transforms as transforms 21 import numpy ---> 22 from contextlib import ExitStack 23 from matplotlib import pyplot 24 from matplotlib.axes import Axes ImportError: cannot import name ExitStack
aperezhortal commented 3 years ago

You will also need to use contextlib2 instead of contextlib. https://contextlib2.readthedocs.io/en/stable/

You can try install it with pip install contextlib2 and then, replace line from contextlib import ExitStack for from contextlib2 import ExitStack in the file skewT.py

Hopefully this will fix the error :crossed_fingers:

kenpryor67 commented 3 years ago

Andres- yes. Installed contextlib2. Now I'm receiving an IOError. It appears that sounding.pyc is trying to open exampleSounding.txt as a netCDF file. How can this be changed? We're getting there one step at a time!

IOError Traceback (most recent call last)

in () 10 11 # Load the sounding datas ---> 12 mySounding = sounding("exampleSounding.txt") 13 14 # Show the SkewT diagram of the Sounding /home/KenPryor67/skewtplus/SkewTplus/SkewTplus/sounding.pyc in __init__(self, inputData, fileFormat, stationId) 239 # Try automatic detection of file format 240 try: --> 241 self.fetchFromARMFile(inputData) 242 except OSError: 243 # If it is not a NETCDF , try TXT /home/KenPryor67/skewtplus/SkewTplus/SkewTplus/sounding.pyc in fetchFromARMFile(self, filePath) 492 """ 493 --> 494 armNetcdfFile = Dataset(filePath, mode="r") 495 self.setMissingValue(-9999.0) 496 netCDF4/_netCDF4.pyx in netCDF4._netCDF4.Dataset.__init__ (netCDF4/_netCDF4.c:13222)() IOError: NetCDF: Unknown file format
aperezhortal commented 3 years ago

The old version of the Netcdf library raised a different type of exception than the expected one: In the sounding.py file (~ line 238), try replacing the OSError exception for IOError:

  if fileFormat is None:
      # Try automatic detection of file format
      try:
          self.fetchFromARMFile(inputData)
      except OSError: # Here replace OSError for IOError          
          # If it is not a NETCDF , try TXT
          self.fetchFromTxtFile(inputData)
kenpryor67 commented 3 years ago

Sorry, that didn't work. Could I just completely comment out the code block for reading NETCDF files? I no plan to read NETCDF files with this module.

aperezhortal commented 3 years ago

Or maybe call the function with fileFormat="txt" since it is the automatic detection that is causing problems.

kenpryor67 commented 3 years ago

Ok! That fixed the IO error. Now encountering an issue with the mySounding.quickPlot() command:

TypeError Traceback (most recent call last)

in () 15 16 # Show the SkewT diagram of the Sounding ---> 17 mySounding.quickPlot() /home/KenPryor67/skewtplus/SkewTplus/SkewTplus/sounding.py in quickPlot(self, output_file, **kwargs) 619 620 # Add an Skew-T axes to the Figure --> 621 my_skew_t_axes = my_skew_t_figure.add_subplot(111, projection="skewx", **kwargs) 622 623 pressure, temperature, dew_point_temperature = self.getCleanSounding() /usr/local/lib/python2.7/dist-packages/matplotlib/figure.pyc in add_subplot(self, *args, **kwargs) 1003 self._axstack.remove(ax) 1004 -> 1005 a = subplot_class_factory(projection_class)(self, *args, **kwargs) 1006 1007 self._axstack.add(key, a) /usr/local/lib/python2.7/dist-packages/matplotlib/axes/_subplots.pyc in __init__(self, fig, *args, **kwargs) 71 72 # _axes_class is set in the subplot_class_factory ---> 73 self._axes_class.__init__(self, fig, self.figbox, **kwargs) 74 75 def __reduce__(self): /home/KenPryor67/skewtplus/SkewTplus/SkewTplus/skewT.py in __init__(self, *args, **kwargs) 221 _ = kwargs.pop("xscale", None) 222 --> 223 super().__init__(yscale="log", xscale="linear", *args, **kwargs) 224 225 self.setLimits(tmin=tmin, tmax=tmax, pmin=pmin, pmax=pmax) TypeError: super() takes at least 1 argument (0 given)
aperezhortal commented 3 years ago

You need to add from builtins import super to skewT.py (and other files if you see a similar exceptions coming from them).

kenpryor67 commented 3 years ago

Good morning Andres, the "super" import worked, but now a new type error appears associated with the init function. Again, I really appreciate all your time and help. I hope we're getting closer to the resolution!

TypeError Traceback (most recent call last)

in () 13 14 # Show the SkewT diagram of the Sounding ---> 15 mySounding.quickPlot() /home/KenPryor67/skewtplus/SkewTplus2.7/SkewTplus/sounding.py in quickPlot(self, output_file, **kwargs) 619 620 # Add an Skew-T axes to the Figure --> 621 my_skew_t_axes = my_skew_t_figure.add_subplot(111, projection="skewx", **kwargs) 622 623 pressure, temperature, dew_point_temperature = self.getCleanSounding() /usr/local/lib/python2.7/dist-packages/matplotlib/figure.pyc in add_subplot(self, *args, **kwargs) 1003 self._axstack.remove(ax) 1004 -> 1005 a = subplot_class_factory(projection_class)(self, *args, **kwargs) 1006 1007 self._axstack.add(key, a) /usr/local/lib/python2.7/dist-packages/matplotlib/axes/_subplots.pyc in __init__(self, fig, *args, **kwargs) 71 72 # _axes_class is set in the subplot_class_factory ---> 73 self._axes_class.__init__(self, fig, self.figbox, **kwargs) 74 75 def __reduce__(self): /home/KenPryor67/skewtplus/SkewTplus2.7/SkewTplus/skewT.py in __init__(self, *args, **kwargs) 221 _ = kwargs.pop("xscale", None) 222 --> 223 super().__init__(yscale="log", xscale="linear", *args, **kwargs) 224 225 self.setLimits(tmin=tmin, tmax=tmax, pmin=pmin, pmax=pmax) /usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.pyc in __init__(self, fig, rect, axisbg, frameon, sharex, sharey, label, xscale, yscale, **kwargs) 506 507 # this call may differ for non-sep axes, e.g., polar --> 508 self._init_axis() 509 510 if axisbg is None: /home/KenPryor67/skewtplus/SkewTplus2.7/SkewTplus/skewT.py in _init_axis(self) 154 def _init_axis(self): 155 # Taken from Axes and modified to use our modified X-axis --> 156 self.xaxis = SkewXAxis(self) 157 self.spines["top"].register_axis(self.xaxis) 158 self.spines["bottom"].register_axis(self.xaxis) /usr/local/lib/python2.7/dist-packages/matplotlib/axis.pyc in __init__(self, axes, pickradius) 656 self._minor_tick_kw = dict() 657 --> 658 self.cla() 659 self._set_scale('linear') 660 /usr/local/lib/python2.7/dist-packages/matplotlib/axis.pyc in cla(self) 740 self._set_artist_props(self.label) 741 --> 742 self.reset_ticks() 743 744 self.converter = None /usr/local/lib/python2.7/dist-packages/matplotlib/axis.pyc in reset_ticks(self) 754 cbook.popall(self.minorTicks) 755 --> 756 self.majorTicks.extend([self._get_tick(major=True)]) 757 self.minorTicks.extend([self._get_tick(major=False)]) 758 self._lastNumMajorTicks = 1 /home/KenPryor67/skewtplus/SkewTplus2.7/SkewTplus/skewT.py in _get_tick(self, major) 89 class SkewXAxis(maxis.XAxis): 90 def _get_tick(self, major): ---> 91 return SkewXTick(self.axes, None, major=major) 92 93 def get_view_interval(self): TypeError: __init__() takes at least 4 arguments (4 given)
aperezhortal commented 3 years ago

This seems trickier than I expected. I'll try to replicate the error locally to see if I can fix the package for py2.7.

kenpryor67 commented 3 years ago

Andres, thanks so much! It's been great working with you on this. I really appreciate your timely responses. I'll look forward to working with a new version of the py2.7 package when it's available. Cheers, Ken

aperezhortal commented 3 years ago

Hi Ken, I've created a branch with the py2.7 version (https://github.com/aperezhortal/SkewTplus/tree/py27) with the latest changes.

You can download the snapshot here and try installing it from the source.

You will need the following dependencies installed: https://github.com/aperezhortal/SkewTplus/blob/py27/requirements_py2.txt

Let me know if this helps.

kenpryor67 commented 3 years ago

Thanks very much! I'll download and try the program next week.