Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read JWD and plot time #44

Open
yogeshkkolte opened this issue Dec 21, 2016 · 0 comments
Open

Read JWD and plot time #44

yogeshkkolte opened this issue Dec 21, 2016 · 0 comments

Comments

@yogeshkkolte
Copy link

yogeshkkolte commented Dec 21, 2016

To plot time in file along x-axis i changed
import numpy as np
from DropSizeDistribution import DropSizeDistribution
import datetime
import pandas as pd
UTC_OFFSET_TIMEDELTA = datetime.timedelta(0, 19800) # 5 X 3600 + 30 X 60 Indian time offset used to convert time in IST to UTC.

jwd_read_utc

def read_jwd_utc(filename):
'''
Takes a filename pointing to a Joss-WaldVogel file and returns
a drop size distribution object.

Usage:
dsd = read_jwd(filename)

Returns:
DropSizeDistrometer object

'''

reader = JWDReader_utc(filename)
dsd = DropSizeDistribution(reader.time, reader.Nd, spread=reader.spread,
                           diameter=reader.diameter, rain_rate=reader.rain_rate,
                           bin_edges=reader.bin_edges)
return dsd

class JWDReader_utc(object):

'''
JWDReader class takes takes a filename as it's only argument(for now).
This should be a Joss-Waldvogel datafile.
'''
diameter = np.array([
    0.359, 0.455, 0.551, 0.656, 0.771, 0.913, 1.116, 1.331, 1.506, 1.665,
    1.912, 2.259, 2.584, 2.869, 3.198, 3.544, 3.916, 4.350, 4.859, 5.373])

spread = np.array([
    0.092, 0.100, 0.091, 0.119, 0.112, 0.172, 0.233, 0.197, 0.153, 0.166,
    0.329, 0.364, 0.286, 0.284, 0.374, 0.319, 0.423, 0.446, 0.572, 0.455])

def __init__(self, filename):
    self.filename = filename
    self.rain_rate = []

    self.Nd = []
    self.time = []

    self._read_file()
    self._prep_data()

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



def conv_md_to_nd(self, Nd):
    F = 0.005
    t = 30.0
    v = 9.65 - 10.3 * np.exp(-0.6 * self.diameter)
    return np.divide(Nd, (F * t * np.multiply(v, self.spread)))

def _read_file(self):
    with open(self.filename) as f:
        next(f)
        for i,line in enumerate(f):
            self.time.append(datetime.datetime.strptime((line.split('\t')[0]+line.split('\t')[1]),'%Y-%m-%d%H:%M:%S')-UTC_OFFSET_TIMEDELTA)



def _prep_data(self):
    self.Nd = np.array(self.Nd)
    self.time = pd.Series(np.array(self.time))
    #self.time = self.time - self.time[0]
    self.rain_rate = np.array(self.rain_rate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant