Beispiel #1
0
 def test_Bearing(self):
     """Test conversion from bearing to theta and back again"""
     for th in self.theta:
         bearing = maputils.theta2bearing(th)
         result = maputils.bearing2theta(bearing)
         if th < 0.0:
             self.assertAlmostEqual(th + 2. * pi, result)
         else:
             self.assertAlmostEqual(th, result)
Beispiel #2
0
 def test_Bearing(self):
     """Test conversion from bearing to theta and back again"""
     for th in self.theta:
         bearing = maputils.theta2bearing(th)
         result = maputils.bearing2theta(bearing)
         if th < 0.0:
             self.assertAlmostEqual(th + 2.0 * pi, result)
         else:
             self.assertAlmostEqual(th, result)
Beispiel #3
0
    def localWindField(self, i):
        """
        Calculate the local wind field at time `i` around the
        tropical cyclone.

        :type  i: int
        :param i: the time.
        """
        lat = self.track.Latitude[i]
        lon = self.track.Longitude[i]
        beta = self.track.beta[i]
        eP = convert(self.track.EnvPressure[i], 'hPa', 'Pa')
        cP = convert(self.track.CentralPressure[i], 'hPa', 'Pa')
        rMax = self.track.rMax[i]*1000
        vFm = convert(self.track.Speed[i], 'kph', 'mps')
        thetaFm = bearing2theta(self.track.Bearing[i] * np.pi/180.)
        thetaMax = self.thetaMax
        beta = self.track.beta[i]

        #FIXME: temporary way to do this
        cls = windmodels.profile(self.profileType)
        params = windmodels.profileParams(self.profileType)
        values = [getattr(self, p) for p in params if hasattr(self, p)]
        profile = cls(lat, lon, eP, cP, rMax, beta, *values)

        R, theta = self.polarGridAroundEye(i)

        P = self.pressureProfile(i, R)

        #FIXME: temporary way to do this
        cls = windmodels.field(self.windFieldType)
        params = windmodels.fieldParams(self.windFieldType)
        values = [getattr(self, p) for p in params if hasattr(self, p)]
        windfield = cls(profile, *values)

        Ux, Vy = windfield.field(R * 1000, theta, vFm, thetaFm,  thetaMax)

        log.debug("UU: {0}, VV: {1}".format(Ux.max(), Vy.max()))

        return (Ux, Vy, P)
Beispiel #4
0
def calculateWindField(lon, lat, pEnv, pCentre, rMax, vFm, thetaFm, beta,
                       profileType='powell', windFieldType='kepert'):

    pCentre = metutils.convert(pCentre, 'hPa', 'Pa')
    pEnv = metutils.convert(pEnv, 'hPa', 'Pa')
    vFm = metutils.convert(vFm, 'kmh', 'mps')
    thetaFm = bearing2theta(np.pi * thetaFm / 180.)
    thetaMax = 70.
    rmax = metutils.convert(rMax, 'km', 'm')
    cls = windmodels.profile(profileType)
    if profileType=="holland":
        profile = cls(lat, lon, pEnv, pCentre, rmax, beta)
    else:
        profile = cls(lat, lon, pEnv, pCentre, rmax)
    R, theta = polarGridAroundEye(lon, lat, 5.)
    gradV = profile.velocity(R*1000)
    cls = windmodels.field(windFieldType)
    windfield = cls(profile)
    Ux, Vy = windfield.field(R*1000, theta, vFm, thetaFm, thetaMax)

    surfV = np.sqrt(Ux*Ux+Vy*Vy)*1.268 # Gust conversion factor
    return gradV, surfV
log.addHandler(logging.NullHandler())

TRACKFILE_COLS = ('CycloneNumber', 'Datetime', 'TimeElapsed', 'Longitude',
                  'Latitude', 'Speed', 'Bearing', 'CentralPressure',
                  'EnvPressure', 'rMax')

TRACKFILE_UNIT = ('', '%Y-%m-%d %H:%M:%S', 'hr', 'degree', 'degree', 'kph', 'degrees',
                  'hPa', 'hPa', 'km')

TRACKFILE_FMTS = ('i', datetime, 'f', 'f', 'f', 'f', 'f', 'f', 'f', 'f')

TRACKFILE_CNVT = {
    0: lambda s: int(float(s.strip() or 0)),
    1: lambda s: datetime.strptime(s.strip(), TRACKFILE_UNIT[1]),
    5: lambda s: convert(float(s.strip() or 0), TRACKFILE_UNIT[5], 'mps'),
    6: lambda s: bearing2theta(float(s.strip() or 0) * np.pi / 180.),
    7: lambda s: convert(float(s.strip() or 0), TRACKFILE_UNIT[7], 'hPa'),
    8: lambda s: convert(float(s.strip() or 0), TRACKFILE_UNIT[8], 'hPa'),
}

def readTrackData(trackfile):
    """
    Read a track .csv file into a numpy.ndarray.

    The track format and converters are specified with the global variables

        TRACKFILE_COLS -- The column names
        TRACKFILE_FMTS -- The entry formats
        TRACKFILE_CNVT -- The column converters

    :param str trackfile: the track data filename.
Beispiel #6
0
# Define format for TCRM output track files:
ISO_FORMAT = "%Y-%m-%d %H:%M:%S"
TCRM_COLS = ('CycloneNumber', 'Datetime', 'TimeElapsed', 'Longitude',
             'Latitude', 'Speed', 'Bearing', 'CentralPressure', 'EnvPressure',
             'rMax')

TCRM_UNIT = ('', '', 'hr', 'degree', 'degree', 'kph', 'degrees', 'hPa', 'hPa',
             'km')

TCRM_FMTS = ('i', 'object', 'f', 'f8', 'f8', 'f8', 'f8', 'f8', 'f8', 'f8')

TCRM_CNVT = {
    0: lambda s: int(float(s.strip() or 0)),
    1: lambda s: datetime.strptime(s.strip(), ISO_FORMAT),
    5: lambda s: convert(float(s.strip() or 0), TCRM_UNIT[5], 'mps'),
    6: lambda s: bearing2theta(float(s.strip() or 0) * np.pi / 180.),
    7: lambda s: convert(float(s.strip() or 0), TCRM_UNIT[7], 'Pa'),
    8: lambda s: convert(float(s.strip() or 0), TCRM_UNIT[8], 'Pa'),
}

TRACK_DT_ERR = "Track data does not have required \
attributes to convert to datetime object"

TRACK_EMPTY_GROUP = """No track groups in this netcdf file: {0}"""


def ncReadTrackData(trackfile):
    """
    Read a netcdf-format track file into a collection of
    :class:`Track` objects. The returned :class:`Track` objects *must*
    have all attributes accessed by the `__getattr__` method.