print("Max Air Density: " + str(air_density_grid[current_level].max()))
    print("Max CLWC: " + str(clwc_grid.max()))
    print("Max LWC: " + str(lwc_grid[current_level].max()))
    print"========================================="
print("Max LWC Sum: " + str(lwc_sum_grid.max()))
################################################
# get working grid dimensions:
grid_width = q_var.shape[2]
grid_height = q_var.shape[3]

################################################
# rendering either a single geopotential level
# or a vertical slice

if show_slice == 0:  # a single geopotential level
    renderer = Renderer(isobaric.lats, isobaric.lons, 0, 0.3)
    renderer.render(grid=lwc_grid[level[0]], title="Converted Liquid Water Content", units="g/m3")

    renderer = Renderer(isobaric.lats, isobaric.lons, 70, 100)
    renderer.render(grid=rh_grid[level[0]], title="Relative Humidity", units="%")
elif show_slice == 1:  # longitude slice
    longitude_index = np.argmin(np.abs(longitude_slice - isobaric.lons))
    print("Showing longitude slice for: " + str(isobaric.lons[longitude_index]))

    render_grid_lwc = np.array(lwc_grid[:, :, longitude_index])
    renderer = Renderer(isobaric.lats, level.astype(float), 0, 0.3)
    renderer.render(grid=render_grid_lwc.transpose(), title="Converted Liquid Water Content", units="g/m3")

    render_grid_rh = np.array(rh_grid[:, :, longitude_index])
    renderer = Renderer(isobaric.lats, level.astype(float), 70, 100)
    renderer.render(grid=render_grid_rh.transpose(), title="Relative Humidity", units="%")
        for (x,y),value in np.ndenumerate(grid):
            for idx, (temp, prob) in weights_histogram:
                if ZERO_K+temp-0.5 <= value <= ZERO_K+temp+0.5:
                    count[x][y][idx] += 1
                    
        totalGrids += 1
        
        print time
        
count /= totalGrids

################################################
# prepare probabilities grid:
weighted_count = np.zeros(shape=(grid_width, grid_height),dtype=float)

# calculate probabilities:
for x in xrange(count.shape[0]):
    for y in xrange(count.shape[1]):
        for idx, (t, prob) in weights_histogram:
            weighted_count[x][y] += count[x][y][idx] * prob

#####################################
# rendering

renderer = Renderer( isobaric.lats, isobaric.lons )

renderer.render( grid=weighted_count, title=title, units="P" )

print "All done."
    
    
Esempio n. 3
0
            #probability_grid[current_level, width_idx, height_idx] = RH_value * temperature_value
            #probability_grid[current_level, width_idx, height_idx] = t_level[width_idx, height_idx]
            #probability_grid[current_level, width_idx, height_idx] = rh_level[width_idx, height_idx]
            probability_grid[current_level, width_idx, height_idx] = rh_level[width_idx, height_idx] * t_level[width_idx, height_idx] * lwc_level[width_idx, height_idx]
    ################################################
    # Debug info:
    print("Current Level: " + str(current_level))
    print("Max Probability: " + str(probability_grid[current_level].max()))
    print"========================================="

################################################
# rendering either a single geopotential level
# or a vertical slice

if show_slice == 0:  # a single geopotential level
    renderer = Renderer(isobaric.lats, isobaric.lons, 0, 1)
    renderer.render(grid=probability_grid[level[0]], title="Icing Probability Map", units="Percents")
elif show_slice == 1:  # longitude slice
    longitude_index = np.argmin(np.abs(longitude_slice - isobaric.lons))
    print("Showing longitude slice for: " + str(isobaric.lons[longitude_index]))

    render_grid_probabilities = np.array(probability_grid[:, :, longitude_index])
    renderer = Renderer(isobaric.lats, level.astype(float), 0, 1)
    renderer.render(grid=render_grid_probabilities.transpose(), title="Converted Liquid Water Content", units="g/m3")
elif show_slice == 2:  # loatitude slice
    latitude_index = np.argmin(np.abs(latitude_slice - isobaric.lats))
    print("Showing latitude slice for: " + str(isobaric.lats[latitude_index]))

    render_grid_probabilities = np.array(probability_grid[:, latitude_index, :])
    renderer = Renderer(level.astype(float), isobaric.lons, 0, 1)
    renderer.render(grid=render_grid_probabilities, title="Converted Liquid Water Content", units="g/m3")
    print("Units: " + str(var.units))
    title = "Relative humidity at %smb (00Z), %s" % (level_name, time)

else:
    print "Failed to open sample grid"
    sys.exit()

totalGrids = 0

################################################
# calculating physical value distribution histogram
   
# iterate over the archive:


# getting 3D slice:
slice3D = var[time];

# getting 2D slice:
slice2D = slice3D[level]

#####################################
# rendering

renderer = Renderer( isobaric.lats, isobaric.lons, 0, 100 )

renderer.render( grid=slice2D, title=title, units="P" )

print "All done."
    
    
Esempio n. 5
0
from archive.structure import MDataset

import numpy as np
from util.renderer import Renderer

################################################
# simple read example:

isobaric = MDataset("isobaric")

renderer = Renderer(isobaric.lats, isobaric.lons)

time = isobaric.times[0]
level = 15  # 850mb
#level = 8 # 500mb

t_var = isobaric["t"]

if t_var is not None:
    t_grid = t_var[time][level]

    ################################################
    # debug
    print("Grid size: " + str(t_grid.shape[0]) + "x" + str(t_grid.shape[1]))
    print("Level: " + str(isobaric.levels[level]))
    print("Units: " + str(t_var.units))
else:
    print "Failed to open sample grid"
    sys.exit()

####################################
from archive.structure import MDataset
from util.renderer import Renderer

import numpy as np

################################################
# simple read example:

isobaric = MDataset("isobaric")

renderer = Renderer(isobaric.lats, isobaric.lons)

time = isobaric.times[0]
level = 6

t_var = isobaric['t']

t_grid = t_var[time][level]

print("Grid size: ", t_grid.shape)
print("Level: ", isobaric.levels[level])
print("Units: ", t_var.units)

####################################
# iteration example

print("Calculating test grid...")
# get sum grid dimensions:
grid_width = t_grid.shape[0]
grid_height = t_grid.shape[1]
import numpy as np
from util.renderer import Renderer

archive_folder_root = 'E:/Development/workspaces/meteo/ecmwf-api-client/download/era-interim'
nc_file = archive_folder_root + '/2016-05/30/' + '2016-05-30_00Z_T_isobaric.nc'

fh = Dataset(nc_file, mode='r')


time = 0
level = 7

lons = fh.variables['longitude'][:]
lats = fh.variables['latitude'][:]

renderer = Renderer( lats, lons )

print(lons.shape)
print(lats.shape)
temperature = fh.variables['t'][time][level][:]
print(temperature.shape)
print(fh.variables['t'].shape)

temperature_units = fh.variables['t'].units

# Get some parameters for the Stereographic Projection

renderer.render( temperature, 'ERA-interim test', temperature_units)