Example #1
0
def plot_sat_temp(projection, temp_sparse, temp,
                     lons, lats, date, plot_filename):
    import matplotlib.pyplot as plt
    '''Plot temperature on the map'''
    fig = plt.figure(1, figsize=(12, 12))

    if projection == 'italy':
        ax = utils.get_projection(plt, projection, regions=True,
                                  sat=True, background=False,
                                  coastlines=True)
    else:
        ax = utils.get_projection(plt, projection, regions=False,
                                  sat=True, background=False,
                                  coastlines=True)

    utils.add_vals_on_map(ax=ax, projection=projection,
                          var=temp_sparse, lons=lons, lats=lats)

    plt.title('Temperature live | Ultimo aggiornamento %s' % date[0])

    utils.add_logo_on_map(
        ax=ax, logo='meteoindiretta_logo.png', zoom=0.15, pos=(0.92, 0.1))
    utils.add_logo_on_map(
        ax=ax, logo='meteonetwork_logo.png', zoom=0.3, pos=(0.15, 0.05))

    if projection == 'italy':
        utils.add_hist_on_map(ax=ax, var=temp, label='Temperatura [C]')
    else:
        utils.add_hist_on_map(ax=ax, var=temp, label='Temperatura [C]', loc=2, width="25%")

    plt.savefig(plot_filename, dpi=100, bbox_inches='tight')
    plt.clf()
Example #2
0
def _compute_distance_scores(obs1, obs2, segments1, segments2):
    scores = [[] for _ in range(len(segments1))]
    base_dist = utils.euclidean_dist(obs1, obs2)
    for i, segment1 in enumerate(segments1):
        projection1 = utils.get_projection(segment1['endpoints'], obs1)
        for segment2 in segments2:
            projection2 = utils.get_projection(segment2['endpoints'], obs2)
            dist = utils.euclidean_dist(projection1, projection2)
            dist_diff = abs(dist - base_dist)
            scores[i].append(1.0 / (1.0 + dist_diff))
    return scores
def _compute_distance_scores(obs1, obs2, segments1, segments2):
    scores = [[] for _ in range(len(segments1))]
    base_dist = utils.euclidean_dist(obs1, obs2)
    for i, segment1 in enumerate(segments1):
        projection1 = utils.get_projection(segment1['endpoints'], obs1)
        for segment2 in segments2:
            projection2 = utils.get_projection(segment2['endpoints'], obs2)
            dist = utils.euclidean_dist(projection1, projection2)
            dist_diff = abs(dist - base_dist)
            scores[i].append(1.0/(1.0+dist_diff))
    return scores
Example #4
0
def plot_temperature_max(projection,
                         plot_type,
                         temp_sparse,
                         temp,
                         lons,
                         lats,
                         date,
                         plot_filename='output.png'):
    import matplotlib.pyplot as plt
    '''Plot temperature on the map'''
    fig = plt.figure(1, figsize=(10, 10))
    ax = utils.get_projection(plt, projection, regions=False)

    utils.add_vals_on_map(ax=ax,
                          var=temp_sparse,
                          projection=projection,
                          lons=lons,
                          lats=lats)

    plt.title('Temperature massime %s' % date)

    utils.add_logo_on_map(ax=plt.gca(),
                          logo='meteoindiretta_logo.png',
                          zoom=0.15,
                          pos=(0.92, 0.1))
    utils.add_logo_on_map(ax=plt.gca(),
                          logo='meteonetwork_logo.png',
                          zoom=0.3,
                          pos=(0.15, 0.05))
    utils.add_hist_on_map(plt.gca(), temp, label='Temperatura [C]')

    plt.savefig(plot_filename, dpi=100, bbox_inches='tight')
    plt.clf()
Example #5
0
def plot_gust(projection,
              gust_sparse,
              gust,
              lons,
              lats,
              date,
              plot_filename='output.png'):
    import matplotlib.pyplot as plt
    fig = plt.figure(1, figsize=(10, 10))
    ax = utils.get_projection(plt, projection, regions=False)

    utils.add_vals_on_map(ax=ax,
                          var=gust_sparse,
                          projection=projection,
                          lons=lons,
                          lats=lats,
                          minval=0,
                          maxval=150,
                          cmap='gist_stern_r')

    plt.title('Raffica massima giornaliera %s' % date)

    utils.add_logo_on_map(ax=plt.gca(),
                          logo='meteoindiretta_logo.png',
                          zoom=0.15,
                          pos=(0.92, 0.1))
    utils.add_logo_on_map(ax=plt.gca(),
                          logo='meteonetwork_logo.png',
                          zoom=0.3,
                          pos=(0.15, 0.05))
    utils.add_hist_on_map(plt.gca(), gust, label='Raffica [kmh/h]')

    plt.savefig(plot_filename, dpi=100, bbox_inches='tight')
    plt.clf()
def plot_rain(projection,
              rain_sparse,
              rain,
              lons,
              lats,
              date,
              plot_filename='output.png'):
    import matplotlib.pyplot as plt

    fig = plt.figure(1, figsize=(10, 10))
    ax = utils.get_projection(plt, projection, regions=False)

    utils.add_vals_on_map(ax=ax,
                          var=rain_sparse,
                          projection=projection,
                          lons=lons,
                          lats=lats,
                          minval=0,
                          maxval=150,
                          cmap='gist_stern_r')

    plt.title('Precipitazioni live | Ultimo aggiornamento %s' % date[0])

    utils.add_logo_on_map(ax=ax,
                          logo='meteoindiretta_logo.png',
                          zoom=0.15,
                          pos=(0.92, 0.1))
    utils.add_logo_on_map(ax=ax,
                          logo='meteonetwork_logo.png',
                          zoom=0.3,
                          pos=(0.15, 0.05))
    utils.add_hist_on_map(ax=ax, var=rain, label='Pioggia giornaliera [mm]')

    plt.savefig(plot_filename, dpi=100, bbox_inches='tight')
    plt.clf()
Example #7
0
    def __init__(self, system, code):

        # Get the zone constants.
        self.const = get_projection(system, code)
        if self.const['TYPE'] != 'TM':
            raise TypeError('Expected Transverse Mercator, found \'{0}\''.format(self.const['TYPE']))

        # Coordinate system constants
        a = 6378137.0                       # semi-major radius of ellipsoid, meters (WGS84)
        # f = 1.0 / 298.257223563           # flattening (WGS84)
        f = 1.0 / 298.25722210088           # flattening (GRS80)
        e2 = 2.0*f - f*f                    # first eccentricity squared
        e12 = e2 / (1.0 - e2)               # second eccentricity squared
        n = f / (2.0 - f)
        n2 = n  * n
        n3 = n2 * n
        n4 = n3 * n
        r = a * (1.0 - n) * (1.0 - n2) * (1.0 + 9.0 * n2 / 4.0 + 225.0 * n4 / 64.0)

        # Defining coordinate system constants for the zone
        P0 = dms_radians(self.const['P0'])      # Latitude of origin, radians (Bb)
        M0 = dms_radians(self.const['M0'])      # Central meridian, radians (Lo)
        X0 = float(self.const['X0'])            # False northing of latitude of origin, meters (No)
        Y0 = float(self.const['Y0'])            # False easting of central meridian, meters (Eo)
        K0 = 1.0 - 1.0/float(self.const['SF'])  # Grid scale factor assigned to central meridian

        # Calculate the derived coordinate system constants.
        u2 = -3.0 * n / 2.0 + 9.0 * n3 / 16.0
        u4 = 15.0 * n2 / 16.0 - 15.0 * n4 / 32.0
        u6 = -35.0 * n3 / 48.0
        u8 = 315.0 * n4 / 512.0

        u0 = 2.0 * (u2 - 2.0 * u4 + 3.0 * u6 - 4.0 * u8)
        u2 = 8.0 * (u4 - 4.0 * u6 + 10.0 * u8)
        u4 = 32.0 * (u6 - 6.0 * u8)
        u6 = 128.0 * u8

        v2 = 3.0 * n / 2.0 - 27.0 * n3 / 32.0
        v4 = 21.0 * n2 / 16.0 - 55.0 * n4 / 32.0
        v6 = 151.0 * n3 / 96.0
        v8 = 1097.0 * n4 / 512.0

        v0 = 2.0 * (v2 - 2.0 * v4 + 3.0 * v6 - 4.0 * v8)
        v2 = 8.0 * (v4 - 4.0 * v6 + 10.0 * v8)
        v4 = 32.0 * (v6 - 6.0 * v8)
        v6 = 128.0 * v8

        sinp = math.sin(P0)
        cosp = math.cos(P0)
        cosp2 = cosp * cosp
        S0 = K0 * (P0 + sinp * cosp * (u0 + cosp2 * (u2 + cosp2 * (u4 + u6 * cosp2)))) * r

        # Save off the locals.
        self._locals = [P0, M0, X0, Y0, K0, a, e2, e12, r, u0, u2, u4, u6, v0, v2, v4, v6, S0]
def plot_synoptic(projection,
                  u,
                  v,
                  mslp,
                  lons,
                  lats,
                  date,
                  plot_filename='output.png'):
    import matplotlib.pyplot as plt

    fig = plt.figure(1, figsize=(10, 10))
    ax = utils.get_projection(plt, projection, regions=False)

    utils.add_vals_on_map(ax=ax,
                          var=mslp,
                          projection=projection,
                          lons=lons,
                          lats=lats,
                          minval=960,
                          maxval=1050,
                          colors=False,
                          fontsize=8)

    utils.add_barbs_on_map(ax=ax,
                           projection=projection,
                           u=u,
                           v=v,
                           lons=lons,
                           lats=lats,
                           magnitude=True)

    plt.title('Pressione e venti  | Ultimo aggiornamento %s' % date[0])

    utils.add_logo_on_map(ax=ax,
                          logo='meteoindiretta_logo.png',
                          zoom=0.15,
                          pos=(0.92, 0.1))
    utils.add_logo_on_map(ax=ax,
                          logo='meteonetwork_logo.png',
                          zoom=0.3,
                          pos=(0.15, 0.05))

    plt.savefig(plot_filename, dpi=100, bbox_inches='tight')
    plt.clf()
Example #9
0
def plot_humidity(projection, hum_sparse, hum,
                  lons, lats, date, plot_filename):
    import matplotlib.pyplot as plt

    fig = plt.figure(1, figsize=(12, 12))
    ax = utils.get_projection(plt, projection, regions=False)

    utils.add_vals_on_map(ax=ax, var=hum_sparse, projection=projection,
                          lons=lons, lats=lats, minval=0, maxval=100, cmap='jet_r')

    plt.title('Umidita live | Ultimo aggiornamento %s' % date[0])

    utils.add_logo_on_map(
        ax=ax, logo='meteoindiretta_logo.png', zoom=0.15, pos=(0.92, 0.1))
    utils.add_logo_on_map(
        ax=ax, logo='meteonetwork_logo.png', zoom=0.3, pos=(0.15, 0.05))
    utils.add_hist_on_map(ax=ax, var=hum, label='Umidita [%]')

    plt.savefig(plot_filename, dpi=100, bbox_inches='tight')
    plt.clf()
Example #10
0
    def __init__(self, system, code):

        # Get the zone constants.
        self.const = get_projection(system, code)
        if self.const['TYPE'] != 'LC':
            raise TypeError('Expected Lambert, found \'{0}\''.format(self.const['TYPE']))

        # Coordinate system constants
        # A = 6378206.4                 # major radius of ellipsoid, meters (NAD27)
        # E = 0.08227185422             # eccentricity of ellipsoid (NAD27)
        A = 6378137.0                   # major radius of ellipsoid, meters (NAD83)
        E = 0.08181922146               # eccentricity of ellipsoid (NAD83)
        PI4 = math.pi / 4.0
        PI2 = math.pi / 2.0

        # Defining coordinate system constants for the zone
        P0 = dms_radians(self.const['P0'])     # latitude of origin, radians (Bb)
        M0 = dms_radians(self.const['M0'])     # central meridian, radians (Lo)
        X0 = float(self.const['X0'])           # False northing of latitude of origin, meters (Nb)
        Y0 = float(self.const['Y0'])           # False easting of central meridian, meters (Eo)
        P1 = dms_radians(self.const['P1'])     # latitude of first standard parallel, radians (Bs)
        P2 = dms_radians(self.const['P2'])     # latitude of second standard parallel, radians (Bn)

        # Calculate the derived coordinate system constants.
        m1 = math.cos(P1) / math.sqrt(1.0 - math.pow(E * math.sin(P1), 2.0))
        m2 = math.cos(P2) / math.sqrt(1.0 - math.pow(E * math.sin(P2), 2.0))
        t1 = (math.tan(PI4 - P1 / 2.0)
                / math.pow((1.0 - E * math.sin(P1)) / (1.0 + E * math.sin(P1)), E / 2.0))
        t2 = (math.tan(PI4 - P2 / 2.0)
                / math.pow( (1.0 - E * math.sin(P2)) / (1.0 + E * math.sin(P2)), E / 2.0))
        t0 = (math.tan(PI4 - P0 / 2.0)
                / math.pow((1.0 - E * math.sin(P0)) / (1.0 + E * math.sin(P0)), E / 2.0))
        n = math.log(m1 / m2) / math.log(t1 / t2)
        F = m1 / (n * math.pow(t1, n))
        rho0 = A * F * math.pow(t0, n)

        # Save off the locals.
        self._locals = [A, E, PI4, PI2, P0, M0, X0, Y0, P1, P2, m1, m2, t1, t2, t0, n, F, rho0]
Example #11
0
def plot_gust(projection, gust_sparse, gust, u, v,
              lons, lats, date, plot_filename):
    import matplotlib.pyplot as plt

    fig = plt.figure(1, figsize=(12, 12))
    ax = utils.get_projection(plt, projection, regions=False)

    utils.add_vals_on_map(ax=ax, var=gust_sparse, projection=projection,
                          lons=lons, lats=lats, minval=0, maxval=150, cmap='gist_stern_r', fontsize=10)

    utils.add_barbs_on_map(ax=ax, projection=projection, u=u, v=v,
                           lons=lons, lats=lats)

    plt.title('Raffiche live | Ultimo aggiornamento %s' % date[0])

    utils.add_logo_on_map(
        ax=ax, logo='meteoindiretta_logo.png', zoom=0.15, pos=(0.92, 0.1))
    utils.add_logo_on_map(
        ax=ax, logo='meteonetwork_logo.png', zoom=0.3, pos=(0.15, 0.05))
    utils.add_hist_on_map(ax=ax, var=gust, label='Raffica [km/h]')

    plt.savefig(plot_filename, dpi=100, bbox_inches='tight')
    plt.clf()