To whom it may concern,


I am currently trying to run some code in python(x,y). It was working perfectly 
a couple of weeks ago but recently it hasn't been. Every time it runs, the 
program crashes and becomes unresponsive resulting in me having to exit. 
It has happened on multiple computers, all using windows, and I was wondering 
if you could help me with my problem.
I have attached a copy of my code.


Thank you
Ashleigh Deal
                                                                                
  
# importing libraries
# this code loads the processed city data and does some comparison of the London and other city time series


from netCDF4 import Dataset
from netcdftime import utime
import numpy as np
import matplotlib.pyplot as plt
import pylab
from matplotlib.dates import DateFormatter, MonthLocator
import datetime

import sys

# get command line arguments
city_name=str(sys.argv[1])
city_name=city_name.replace(" ","_")
fname='proc_data/'+city_name+'_max.nc'

# read in data
nc=Dataset(fname,'r')
london=nc.variables['London'][:]
city=nc.variables[city_name][:]

london_clim=nc.variables['London Climatology'][:]
city_clim=nc.variables[city_name+' Climatology'][:]


# time information
time=nc.variables['time']
cdftime = utime(time.units,'standard')
time=cdftime.num2date(nc.variables['time'][:])
day=np.fromiter((time[x].day for x in range(0,len(time))),np.int)
month=np.fromiter((time[x].month for x in range(0,len(time))),np.int)
year=np.fromiter((time[x].year for x in range(0,len(time))),np.int)

nc.close()


# difference in max temperature (positive values mean London T higher)
diff=london-city

# four different example plots

##################################################
# plot 1 - for all time percentage of London exceedence per month

# count number of positive days (and total number of days) per month
prop=np.empty([12])
for m in range(1,13):
 ind=np.where(month == m)
 prop[m-1]=sum(diff[ind] > 0)/float(len(ind[0]))

fig1, ax1 = plt.subplots(figsize=(7,7))

month_names=['J','F','M','A','M','J','J','A','S','O','N','D']
pos=np.arange(len(month_names))+0.5

p1 = ax1.bar(pos,prop,color='r', align='center')

ax1.set_title('Days with temperature in London greater than '+city_name)
ax1.set_ylabel('Percentage of days 1880-2010')
pylab.xticks(pos,month_names)
fig1.savefig('plots/'+city_name+'_months.png')


##################################################

# plot 2 - has number of exceedences changed over the dataset time period

# count number of positive days (and total number of days) per month
prop_ann=np.empty(13)
for y in range(0,13):
 ind=np.where((year >= 1880+(y*10)) & (year < 1889+(y*10)))
 prop_ann[y-1]=sum(diff[ind] > 0)/float(len(ind[0]))

fig2, ax2 = plt.subplots(figsize=(10,5))

dec_names=['1880s','1890s','1900s','1910s','1920s','1930s',
           '1940s','1950s','1960s','1970s','1980s','1990s',
           '2000s']
pos=np.arange(len(dec_names))+0.5

p1 = ax2.bar(pos,prop_ann,color='g', align='center')

ax2.set_title('Days with temperature in London greater than '+city_name)
ax2.set_ylabel('Percentage of days 1880-2010')
pylab.xticks(pos,dec_names)
fig2.savefig('plots/'+city_name+'_decades.png')

##################################################

# plot 3 - scatter plot of exceedence vs. London temperature during April

# where is month equal to April (4)
ind=np.where(month == 4)

fig3, ax3 = plt.subplots(figsize=(7,7))

p1 = ax3.plot(london[ind],diff[ind],'m+')

ax3.set_ylabel('Difference with '+city_name)
ax3.set_xlabel('Temperature in London')
fig3.savefig('plots/'+city_name+'_scatter.png')

##################################################

# plot 4 - daily climatology of two cities

# make datetime array for climatology
clim_time=[datetime.datetime(1993,1,1,12)+datetime.timedelta(x) 
        for x in range(0,365)]

months=MonthLocator(range(1,13),bymonthday=15)
monthFormatter=DateFormatter('%b')

london_std=np.empty([12])
for i in np.arange(1,13):
    ind=np.where(month == i)
london_std[i-1]=np.std(london[ind])

city_std=np.empty([12])
for i in np.arange(1,13):
    ind=np.where(month == i)
city_std[i-1]=np.std(city[ind])

fig4, ax4 = plt.subplots(figsize=(7,7))
p1 = ax4.plot(clim_time,london_std,'b',label='London')
p2 = ax4.plot(clim_time,city_std,'r',label=city_name)

ax4.xaxis.set_major_locator(months)
ax4.xaxis.set_major_formatter(monthFormatter)
ax4.xaxis_date()
ax4.set_ylabel('Climatological maximum temperature / $^\circ$C')

ax4.legend()
fig4.savefig('plots/'+city_name+'_clim.png')

# show all figures can be commented out
plt.show()

############################

per_above_thresh=np.empty([31])
for temp in np.arange(0,31):
    ind=np.where(london > temp)
    diff=london[ind] - city[ind]
pos=np.sum(diff > 0)
prop=float(pos)/float(len(diff))
per_above_thresh[temp] = prop

fig5, ax5 = plt.subplots(figsize=(7,7))

ax5.plot((np.arange(0,31)),per_above_thresh)

ax5.set_ylabel('percentage of days 1880 - 2010')
ax5.set_xlabel('Temperature Difference')

plt.show()


-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to