Skip to content

Commit

Permalink
Conforming Code to PEP8
Browse files Browse the repository at this point in the history
  • Loading branch information
josephhardinee committed Apr 8, 2014
1 parent 75bb59b commit 6b37be7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ coverage.xml
# Sphinx documentation
docs/_build/

# Vim
*.swp
12 changes: 7 additions & 5 deletions pydisdrometer/DropSizeDistribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@


class DropSizeDistribution(object):

'''
DropSizeDistribution class to hold DSD's and calculate parameters
and relationships. Should be returned from the disdrometer*reader objects.
'''

def __init__(self, time, Nd, spread, rain_rate=None, velocity=None, Z=None,
num_particles=None, bin_edges=None, diameter=None):
num_particles=None, bin_edges=None, diameter=None):
self.time = time
self.Nd = Nd
self.spread = spread
Expand All @@ -24,7 +25,7 @@ def __init__(self, time, Nd, spread, rain_rate=None, velocity=None, Z=None,
self.Z = Z
self.num_particles = num_particles
self.bin_edges = bin_edges
self.diameter=diameter
self.diameter = diameter

lt = len(time)
self.Zh = np.zeros(lt)
Expand Down Expand Up @@ -57,9 +58,10 @@ def calc_radar_parameters(self, wavelength=tmatrix_aux.wl_X):

def _setup_scattering(self, wavelength):
self.scatterer = Scatterer(wavelength=wavelength,
m=refractive.m_w_10C[wavelength])
m=refractive.m_w_10C[wavelength])
self.scatterer.psd_integrator = PSDIntegrator()
self.scatterer.psd_integrator.axis_ratio_func = lambda D: 1.0 / DSR.bc(D)
self.scatterer.psd_integrator.axis_ratio_func = lambda D: 1.0 / \
DSR.bc(D)
self.scatterer.psd_integrator.D_max = 10.0
self.scatterer.psd_integrator.geometries = (
tmatrix_aux.geom_horiz_back, tmatrix_aux.geom_horiz_forw)
Expand Down Expand Up @@ -89,6 +91,6 @@ def calc_R_Zh_relationship(self):
gives the covariance matrix of the fit.
'''

popt, pcov = expfit(np.power(10, 0.1*self.Zh[self.rain_rate > 0]),
popt, pcov = expfit(np.power(10, 0.1 * self.Zh[self.rain_rate > 0]),
self.rain_rate[self.rain_rate > 0])
return popt, pcov
65 changes: 35 additions & 30 deletions pydisdrometer/ParsivelNasaGVReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import csv
import datetime


def read_parsivel_nasa_gv(filename, campaign='ifloods'):
'''
Takes a filename pointing to a parsivel NASA Field Campaign file and returns
Expand All @@ -34,24 +35,24 @@ def read_parsivel_nasa_gv(filename, campaign='ifloods'):

if reader:
dsd = DropSizeDistribution(reader.time, reader.Nd, reader.spread,
velocity=reader.velocity, diameter=reader.diameter,
bin_edges=reader.bin_edges)
velocity=reader.velocity, diameter=reader.diameter,
bin_edges=reader.bin_edges)
return dsd

else:
return None



class NASA_APU_reader(object):

'''
This class reads and parses parsivel disdrometer data from nasa ground campaigns. These conform to document
Use the read_parsivel_nasa_gv() function to interface with this.
'''

time = [] #Time in minutes from start of recording
Nd = []
time = [] # Time in minutes from start of recording
Nd = []
# Nt = []
# T = []
# W = []
Expand All @@ -60,7 +61,6 @@ class NASA_APU_reader(object):
# mu = []
# rho_w = 1


def __init__(self, filename, campaign):
'''
Handles setting up a NASA APU Reader
Expand All @@ -70,12 +70,14 @@ def __init__(self, filename, campaign):
print('Campaign type not supported')
return

self.f = open(filename,'r')
self.f = open(filename, 'r')
reader = csv.reader(self.f)

if campaign in ['ifloods']:
self.diameter = np.array([float(x) for x in reader.next()[0].split()[1:]])
self.velocity = np.array([float(x) for x in reader.next()[0].split()[1:]])
if campaign in ['ifloods']:
self.diameter = np.array([float(x)
for x in reader.next()[0].split()[1:]])
self.velocity = np.array([float(x)
for x in reader.next()[0].split()[1:]])

for row in reader:
self.time.append(float(row[0].split()[0]))
Expand All @@ -88,7 +90,8 @@ def __init__(self, filename, campaign):

self.time = np.array(self.time)
self.Nd = np.array(self.Nd)
self.bin_edges=np.hstack((0,self.diameter+np.array(self.spread)/2))
self.bin_edges = np.hstack(
(0, self.diameter + np.array(self.spread) / 2))

def _regenerate_rainfall(self):
'''
Expand All @@ -100,22 +103,24 @@ def _regenerate_rainfall(self):
pass

def _parse_time(self, time_vector):
#For now we just drop the day stuff, Eventually we'll make this a proper time
return float(time_vector[2])*60.0+float(time_vector[3])



spread = [0.129, 0.129, 0.129, 0.129,0.129,0.129,0.129,0.129,0.129,0.129,0.257,
0.257,0.257,0.257,0.257,0.515,0.515,0.515,0.515,0.515,1.030,1.030,
1.030,1.030,1.030,2.060,2.060,2.060,2.060,2.060,3.090, 3.090]

supported_campaigns= ['ifloods','mc3e_dsd','mc3e_raw']

diameter = np.array([ 0.06, 0.19, 0.32, 0.45, 0.58, 0.71, 0.84, 0.96, 1.09, 1.22,
1.42, 1.67, 1.93, 2.19, 2.45, 2.83, 3.35, 3.86, 4.38, 4.89,
5.66, 6.70, 7.72, 8.76, 9.78, 11.33, 13.39, 15.45, 17.51,
19.57, 22.15, 25.24])

velocity = np.array([ 0.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85, 0.96, 1.13,
1.35, 1.59, 1.83, 2.08, 2.40, 2.78, 3.15, 3.50, 3.84, 4.40, 5.20,
6.00, 6.80, 7.60, 8.80, 10.40, 12.00, 13.60, 15.20, 17.60, 20.80])
# For now we just drop the day stuff, Eventually we'll make this a
# proper time
return float(time_vector[2]) * 60.0 + float(time_vector[3])

spread = [
0.129, 0.129, 0.129, 0.129, 0.129, 0.129, 0.129, 0.129, 0.129, 0.129, 0.257,
0.257, 0.257, 0.257, 0.257, 0.515, 0.515, 0.515, 0.515, 0.515, 1.030, 1.030,
1.030, 1.030, 1.030, 2.060, 2.060, 2.060, 2.060, 2.060, 3.090, 3.090]

supported_campaigns = ['ifloods', 'mc3e_dsd', 'mc3e_raw']

diameter = np.array(
[0.06, 0.19, 0.32, 0.45, 0.58, 0.71, 0.84, 0.96, 1.09, 1.22,
1.42, 1.67, 1.93, 2.19, 2.45, 2.83, 3.35, 3.86, 4.38, 4.89,
5.66, 6.70, 7.72, 8.76, 9.78, 11.33, 13.39, 15.45, 17.51,
19.57, 22.15, 25.24])

velocity = np.array(
[0.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85, 0.96, 1.13,
1.35, 1.59, 1.83, 2.08, 2.40, 2.78, 3.15, 3.50, 3.84, 4.40, 5.20,
6.00, 6.80, 7.60, 8.80, 10.40, 12.00, 13.60, 15.20, 17.60, 20.80])
5 changes: 3 additions & 2 deletions pydisdrometer/ParsivelReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ def _read_file(self):

def _apply_pcm_matrix(self):
self.filtered_raw_matrix = np.ndarray(shape=(len(self.raw),
32, 32), dtype=float)
32, 32), dtype=float)
for i in range(len(self.raw)):
self.filtered_raw_matrix[i] = np.multiply(self.pcm, np.reshape(self.raw[i],(32,32)))
self.filtered_raw_matrix[i] = np.multiply(
self.pcm, np.reshape(self.raw[i], (32, 32)))

def _prep_data(self):
self.rain_rate = np.array(self.rain_rate)
Expand Down

0 comments on commit 6b37be7

Please sign in to comment.