コード例 #1
0
 def test_cloud_layer_small2(self):
     lwc = LowWaterCloud(1000., 235., 400., 950)
     cl1 = CloudLayer(970, 980, lwc, False)
     cl2 = CloudLayer(980, 990, lwc, False)
     cl3 = CloudLayer(990, 1000, lwc, False)
     self.assertAlmostEqual(cl1.lwc, 4e-5, 5)
     self.assertAlmostEqual(cl2.lwc, 3e-5, 5)
     self.assertAlmostEqual(cl3.lwc, 1e-5, 5)
     self.assertAlmostEqual(lwc.upthres, 49)
     self.assertAlmostEqual(lwc.maxlwc, 8.2e-5, 6)
コード例 #2
0
 def test_cloud_layer(self):
     lwc = LowWaterCloud(2000., 255., 400., 0)
     cl = CloudLayer(0, 100, lwc)
     cl1 = CloudLayer(1945, 1955, lwc)
     cl2 = CloudLayer(1970, 1980, lwc)
     cl3 = CloudLayer(1950, 2050, lwc)
     self.assertAlmostEqual(cl.z, 50., 2)
     self.assertAlmostEqual(cl.temp, -5.47, 2)
     self.assertAlmostEqual(cl.press, 1007.26, 2)
     self.assertAlmostEqual(cl.psv, 4.07, 2)
     self.assertAlmostEqual(cl1.lwc, 0.607, 3)
     self.assertAlmostEqual(cl2.lwc, 0.304, 3)
     self.assertAlmostEqual(cl3.lwc, 0., 3)
コード例 #3
0
 def test_cloud_layer(self):
     lwc = LowWaterCloud(2000., 255., 400., 0)
     cl = CloudLayer(0, 100, lwc)
     cl1 = CloudLayer(1945, 1955, lwc)
     cl2 = CloudLayer(1970, 1980, lwc)
     cl3 = CloudLayer(1950, 2050, lwc)
     self.assertAlmostEqual(round(cl.z, 2), 50.)
     self.assertAlmostEqual(round(cl.temp, 2), -5.47)
     self.assertAlmostEqual(round(cl.press, 2), 1007.26)
     self.assertAlmostEqual(round(cl.psv, 2), 4.07)
     self.assertAlmostEqual(round(cl1.lwc, 3), 0.607)
     self.assertAlmostEqual(round(cl2.lwc, 3), 0.304)
     self.assertAlmostEqual(round(cl3.lwc, 3), 0.)
コード例 #4
0
 def test_cloud_layer_small(self):
     lwc = LowWaterCloud(1000., 235., 400., 950)
     cl = CloudLayer(950, 960, lwc, False)
     cl1 = CloudLayer(960, 970, lwc, False)
     cl2 = CloudLayer(970, 980, lwc, False)
     cl3 = CloudLayer(980, 990, lwc, False)
     cl4 = CloudLayer(990, 1000, lwc, False)
     self.assertAlmostEqual(round(cl.lwc, 5), 8e-5)
     self.assertAlmostEqual(round(cl1.lwc, 5), 6e-05)
     self.assertAlmostEqual(round(cl2.lwc, 5), 4e-05)
     self.assertAlmostEqual(round(cl3.lwc, 5), 3e-05)
     self.assertAlmostEqual(round(cl4.lwc, 5), 1e-05)
     self.assertAlmostEqual(lwc.upthres, 49)
     self.assertAlmostEqual(round(lwc.maxlwc, 6), 8.2e-5)
コード例 #5
0
 def test_get_liquid_water_path(self):
     self.lwc.init_cloud_layers(421., 100)
     self.lwc.get_liquid_water_path()
     lwc = LowWaterCloud(2000., 255., 400., 0)
     CloudLayer(1900, 2000, lwc)
     lwc.get_liquid_water_path()
     self.assertAlmostEqual(len(lwc.layers), 1)
     self.assertAlmostEqual(lwc.lwp, 60.719, 3)
     self.assertAlmostEqual(self.lwc.lwp, 400., 1)
コード例 #6
0
def read_metar(file, params, min=None, max=None, latlim=None, lonlim=None):
    """ Reading bufr files for METAR station data and provide dictionary
    with weather data for cloud base height and visibility.
    The results are subsequently filtered by cloud base height and visibility

    Arguments:
        file    Bufr file with synop reports
        params    List of parameter names that will be extracted
        min    Threshold for minimum value of parameter
        max    Threshold for maximum value of parameter
        latlim Tuple of minimum and maximum latitude values for valid result
        lonlim Tuple of minimum and maximum longitude values for valid result

    Returns list of station dictionaries for given thresholds
    """
    result = {}
    bfr = Bufr("libdwd", os.getenv("BUFR_TABLES"))
    for blob, size, header in load_file.next_bufr(file):
        bfr.decode(blob)
        try:
            for subset in bfr.next_subset():
                stationdict = {}
                for (k, m, v, q) in subset.next_data():
                    if k == 1063:  # Station name
                        stationdict['name'] = v.strip()
                    if k == 5002:  # Latitude
                        stationdict['lat'] = v
                    if k == 6002:  # Longitude
                        stationdict['lon'] = v
                    if k == 7030:  # Altitude
                        stationdict['altitude'] = v
                    elif k == 4001:  # Year
                        stationdict['year'] = v
                    elif k == 4002:  # Month
                        stationdict['month'] = v
                    elif k == 4003:  # Day
                        stationdict['day'] = v
                    elif k == 4004:  # Hour
                        stationdict['hour'] = v
                    elif k == 4005:  # Hour
                        stationdict['minute'] = v
                    elif k == 20003:  # Present weather
                        stationdict['present weather'] = v
                        # Values from 40 to 49 are refering to fog and ice fog
                        # Patchy fog or fog edges value 11 or 12
                    elif k == 20004:  # Past weather
                        stationdict['past weather'] = v
                        # Values from 40 to 49 are refering to fog and ice fog
                        # Patchy fog or fog edges value 11 or 12
                    elif k == 20013:  # Cloud base height
                        if v is not None:
                            if ('cbh' in stationdict.keys()
                                    and stationdict["cbh"] is not None):
                                if stationdict['cbh'] > v:
                                    stationdict['cbh'] = v
                            else:
                                stationdict['cbh'] = v
                        else:
                            stationdict['cbh'] = None
                    elif k == 2001:  # Auto/manual measurement
                        # 1 - 3 : Manual human observations. Manned stations
                        # 0, 4 - 7 : Only automatic observations
                        stationdict['type'] = v
                    elif k == 20060:  # Prevailing visibility
                        stationdict['visibility'] = v
                    elif k == 12023:  # Mean air temperature in °C
                        stationdict['air temperature'] = CL.check_temp(
                            v, 'kelvin')
                    elif k == 12024:  # Dew point temperature in °C
                        stationdict['dew point'] = CL.check_temp(v, 'kelvin')
                    elif k == 20010:  # Cloud cover in %
                        stationdict['cloudcover'] = v
                    elif k == 13003:  # Relative humidity in %
                        stationdict['relative humidity'] = v
                    elif k == 11001:  # Wind direction in degree
                        stationdict['wind direction'] = v
                    elif k == 11002:  # Wind speed in m s-1
                        stationdict['wind speed'] = v
                    elif k == 1002:  # WMO station number
                        stationdict['wmo'] = v
                    elif k == 1024:  # WMO station number
                        stationdict['coords'] = v
                # Apply thresholds
                stationtime = datetime(
                    stationdict['year'],
                    stationdict['month'],
                    stationdict['day'],
                    stationdict['hour'],
                    stationdict['minute'],
                ).strftime("%Y%m%d%H%M%S")
                paralist = []
                if not isinstance(params, list):
                    params = [params]
                for param in params:
                    if param not in stationdict:
                        res = None
                    elif min is not None and stationdict[param] < min:
                        res = None
                    elif max is not None and stationdict[param] >= max:
                        res = None
                    elif stationdict[param] is None:
                        res = None
                    else:
                        res = stationdict[param]
                    paralist.append(res)
                if all([i is None for i in paralist]):
                    continue
                # Test for limited coordinates
                if latlim is not None:
                    if stationdict['lat'] < latlim[0]:
                        continue
                    elif stationdict['lat'] > latlim[1]:
                        continue
                if lonlim is not None:
                    if stationdict['lon'] < lonlim[0]:
                        continue
                    elif stationdict['lon'] > lonlim[1]:
                        continue
                # Add station data to result list
                if stationtime in result.keys():
                    result[stationtime].append([
                        stationdict['name'], stationdict['altitude'],
                        stationdict['lat'], stationdict['lon']
                    ] + paralist)
                else:
                    result[stationtime] = [[
                        stationdict['name'], stationdict['altitude'],
                        stationdict['lat'], stationdict['lon']
                    ] + paralist]
        except DummyException as e:
            "ERROR: Unresolved station request: {}".format(e)
    return (result)