Skip to content

Commit

Permalink
Added checking of OS to try and mitigate problems with matplotlib on OSX
Browse files Browse the repository at this point in the history
  • Loading branch information
mccikdt3 committed Jan 15, 2019
1 parent 563eaf9 commit 32a170c
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 34 deletions.
6 changes: 5 additions & 1 deletion Aerosol/Size_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@

from scipy.stats import lognorm
from scipy import stats # Import the scipy.stats module
import matplotlib.pyplot as plt
import matplotlib
import platform
if platform.system() == 'Darwin': # Found some issues with Matplotlib in recent OSx versions
matplotlib.use("TkAgg")
from matplotlib import pyplot as plt
import numpy as np

def lognormal(num_bins,total_conc,meansize,std,lowersize,uppersize):
Expand Down
6 changes: 5 additions & 1 deletion Aerosol/f2py/Fixed_yield/ODE_solver_fixedyield.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
##########################################################################################

import numpy
import pylab as P
import matplotlib
import platform
if platform.system() == 'Darwin': # Found some issues with Matplotlib in recent OSx versions
matplotlib.use("TkAgg")
from matplotlib import pyplot as plt
import pdb
import pickle
import Plotting
Expand Down
28 changes: 18 additions & 10 deletions Aerosol/f2py/Fixed_yield/Plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@

from scipy.stats import lognorm
from scipy import stats # Import the scipy.stats module
import matplotlib.pyplot as plt
import matplotlib
import platform
if platform.system() == 'Darwin': # Found some issues with Matplotlib in recent OSx versions
matplotlib.use("TkAgg")
from matplotlib import pyplot as plt
import numpy as np
from matplotlib.pyplot import cm
from matplotlib.animation import FuncAnimation
#from matplotlib.pyplot import cm
#from matplotlib.animation import FuncAnimation
import pdb
import time as time_func

Expand All @@ -44,7 +48,7 @@ def stacked_bar(time,y_matrix,num_species, num_bins,molw_asnumpy,NA):
for time_step in range(len(time)):

#Define a range of colours to represent every compound
color_array=iter(cm.rainbow(np.linspace(0,1,num_species-1)))
color_array=plt.cm.rainbow(np.linspace(0,1,num_species-1))

time_stamp=time[time_step]
y_asnumpy=np.array(y_matrix[time_step,:])
Expand All @@ -66,22 +70,26 @@ def stacked_bar(time,y_matrix,num_species, num_bins,molw_asnumpy,NA):
y_norm_matrix[:,size-1]=np.transpose(y_mass_array[0:num_species-1]/(np.sum(y_mass_array[0:num_species-1])))

#Now plot the results
fig, ax = plt.subplots()
#pdb.set_trace()
step=0
#fig, ax = plt.subplots()
bar_locations = np.arange(num_bins)
for org in range(num_species-1):
c=next(color_array)
#pdb.set_trace()
c=color_array[step]
if org == 0:
ax.bar(bar_locations, y_norm_matrix[org,:],color=c)
plt.bar(bar_locations, y_norm_matrix[org,:],color=c)
else:
y_cummulative[0,:]=y_cummulative[0,:]+y_norm_matrix[org-1,:]
ax.bar(bar_locations, y_norm_matrix[org,:],bottom=np.array(y_cummulative[0,:]),color=c)
plt.bar(bar_locations, y_norm_matrix[org,:],bottom=np.array(y_cummulative[0,:]),color=c)
step+=1

plt.title('SOA mass = {:.2f}'.format(np.sum(np.sum(y_abs_matrix))))
plt.ylabel('Normalised SOA contribution')
plt.xlabel('Size bin')
plt.show()
#time_func.sleep(3)
pdb.set_trace()
plt.close(fig)
#pdb.set_trace()
plt.close()


16 changes: 10 additions & 6 deletions Aerosol/f2py/ODE_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
##########################################################################################

import numpy
import pylab as P
import matplotlib
import platform
if platform.system() == 'Darwin': # Found some issues with Matplotlib in recent OSx versions
matplotlib.use("TkAgg")
from matplotlib import pyplot as plt
import pdb
import pickle

Expand Down Expand Up @@ -316,11 +320,11 @@ def dydt_func(t,y):
#In a future release I will add this as a seperate module
if plot_mass is True:
try:
P.plot(t_array,SOA_matrix[:,0], marker='o')
P.title(exp_mod.name)
P.ylabel("SOA mass [micrograms/m3]")
P.xlabel("Time [seconds] since start of simulation")
P.show()
plt.plot(t_array,SOA_matrix[:,0], marker='o')
plt.title(exp_mod.name)
plt.ylabel("SOA mass [micrograms/m3]")
plt.xlabel("Time [seconds] since start of simulation")
plt.show()
except:
print("There is a problem using Matplotlib in your environment. If using this within a docker container, you will need to transfer the data to the host or configure your container to enable graphical displays. More information can be found at http://wiki.ros.org/docker/Tutorials/GUI ")

Expand Down
20 changes: 12 additions & 8 deletions ODE_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
##########################################################################################

import numpy
import pylab as P
import matplotlib
import platform
if platform.system() == 'Darwin': # Found some issues with Matplotlib in recent OSx versions
matplotlib.use("TkAgg")
from matplotlib import pyplot as plt
import pdb
from scipy.sparse import csr_matrix
from timeit import default_timer as timer
Expand Down Expand Up @@ -290,13 +294,13 @@ def jac(t,y):
#In a future release I will add this as a seperate module
if with_plots:
try:
P.plot(t_array,numpy.log10(y_matrix[:,species_dict2array['APINENE']]), marker='o',label="APINENE")
P.plot(t_array,numpy.log10(y_matrix[:,species_dict2array['PINONIC']]), marker='o',label="PINONIC")
P.title(exp_mod.name)
P.legend(loc='upper left')
P.ylabel("Concetration log10[molecules/cc]")
P.xlabel("Time [seconds] since start of simulation")
P.show()
plt.plot(t_array,numpy.log10(y_matrix[:,species_dict2array['APINENE']]), marker='o',label="APINENE")
plt.plot(t_array,numpy.log10(y_matrix[:,species_dict2array['PINONIC']]), marker='o',label="PINONIC")
plt.title(exp_mod.name)
plt.legend(loc='upper left')
plt.ylabel("Concetration log10[molecules/cc]")
plt.xlabel("Time [seconds] since start of simulation")
plt.show()
except:
print("There is a problem using Matplotlib in your environment. If using this within a docker container, you will need to transfer the data to the host or configure your container to enable graphical displays. More information can be found at http://wiki.ros.org/docker/Tutorials/GUI ")

Expand Down
20 changes: 12 additions & 8 deletions f2py/ODE_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
##########################################################################################

import numpy
import pylab as P
import matplotlib
import platform
if platform.system() == 'Darwin': # Found some issues with Matplotlib in recent OSx versions
matplotlib.use("TkAgg")
from matplotlib import pyplot as plt
import pdb
import csv
import pandas as pd
Expand Down Expand Up @@ -234,13 +238,13 @@ def jacobian(t,y):
if with_plots:

try:
P.plot(t_array,numpy.log10(y_matrix[:,species_dict2array['APINENE']]), marker='o',label="APINENE")
P.plot(t_array,numpy.log10(y_matrix[:,species_dict2array['PINONIC']]), marker='o',label="PINONIC")
P.title(exp_mod.name)
P.legend(loc='upper left')
P.ylabel("Concetration log10[molecules/cc]")
P.xlabel("Time [seconds] since start of simulation")
P.show()
plt.plot(t_array,numpy.log10(y_matrix[:,species_dict2array['APINENE']]), marker='o',label="APINENE")
plt.plot(t_array,numpy.log10(y_matrix[:,species_dict2array['PINONIC']]), marker='o',label="PINONIC")
plt.title(exp_mod.name)
plt.legend(loc='upper left')
plt.ylabel("Concetration log10[molecules/cc]")
plt.xlabel("Time [seconds] since start of simulation")
plt.show()
except:
print("There is a problem using Matplotlib in your environment. If using this within a docker container, you will need to transfer the data to the host or configure your container to enable graphical displays. More information can be found at http://wiki.ros.org/docker/Tutorials/GUI ")

Expand Down

0 comments on commit 32a170c

Please sign in to comment.