Esempio n. 1
0
def write_html(lon, lat, directory=None, zoom=None):

    # Set defaults
    if directory is None:
        directory = mkdtemp()

    if zoom is None:
        zoom = cfg.default_zoom

    # Info string
    lonlat_str = '({:.3f}E, {:.3f}N)'.format(abs(lon), abs(lat))
    if lon < 0:
        lonlat_str = lonlat_str.replace('E', 'W')
    if lat < 0:
        lonlat_str = lonlat_str.replace('N', 'S')

    mkdir(directory)

    # Make the plot
    png = os.path.join(directory, 'annual_cycle.png')
    df = get_cru_timeseries(lon, lat)

    #print(df)
    #print(df.grid_point_elevation)
    #print(np.isnan(df.grid_point_elevation))
    #print(np.min(df.lat))
    #print(np.max(df.lat))

    if np.isnan(df.grid_point_elevation) == True:
        raise Exception(
            "Choose location over land and also not over the Antarctic!")

    #print(df.grid_point_elevation)
    #print(np.isnan(df).all())
    #print(np.isnan(np.sum(all(np.isnan(df).all()))))
    #print(np.isnan(np.sum(np.isnan(df).all())))
    #print(all(np.isnan(df)))
    #print(all(np.isnan(df).all()))
    graphics.plot_annual_cycle(df, filepath=png)

    outpath = os.path.join(directory, 'index.html')
    with open(cfg.html_tpl, 'r') as infile:
        lines = infile.readlines()
        out = []
        url = get_googlemap_url(lon, lat, zoom=zoom)
        for txt in lines:
            txt = txt.replace('[LONLAT]', lonlat_str)
            txt = txt.replace('[IMGURL]', url)
            out.append(txt)
        with open(outpath, 'w') as outfile:
            outfile.writelines(out)

    return outpath
Esempio n. 2
0
def write_html(lon, lat, directory=None, zoom=None):

    # Set defaults
    if directory is None:
        directory = mkdtemp()

    if zoom is None:
        zoom = cfg.default_zoom

    # Info string
    lonlat_str = '({:.3f}E, {:.3f}N)'.format(abs(lon), abs(lat))
    if lon < 0:
        lonlat_str = lonlat_str.replace('E', 'W')
    if lat < 0:
        lonlat_str = lonlat_str.replace('N', 'S')

    mkdir(directory)

    # Modified by Raphael:
    # Make the plot
    png1 = os.path.join(directory, 'annual_cycle.png')
    png2 = os.path.join(directory, 'temp_trend.png')
    png3 = os.path.join(directory, 'prec_trend.png')
    df = get_cru_timeseries(lon, lat)

    # Checks if data is available.
    if df['tmp'].isnull().values.all():
        sys.exit('Location in ocean or no data available. ' +
                 'Please type in a valid location.')

    graphics.plot_annual_cycle(df, filepath=png1)
    graphics.plot_trend_temp(df, filepath=png2)
    graphics.plot_trend_prec(df, filepath=png3)

    outpath = os.path.join(directory, 'index.html')
    with open(cfg.html_tpl, 'r') as infile:
        lines = infile.readlines()
        out = []
        url = get_googlemap_url(lon, lat, zoom=zoom)
        for txt in lines:
            txt = txt.replace('[LONLAT]', lonlat_str)
            txt = txt.replace('[IMGURL]', url)
            out.append(txt)
        with open(outpath, 'w') as outfile:
            outfile.writelines(out)

    return outpath
Esempio n. 3
0
def write_html(lon, lat, directory=None, zoom=None):

    # Set defaults
    if directory is None:
        directory = mkdtemp()

    if zoom is None:
        zoom = cfg.default_zoom

    # Info string
    lonlat_str = '({:.3f}E, {:.3f}N)'.format(abs(lon), abs(lat))
    if lon < 0:
        lonlat_str = lonlat_str.replace('E', 'W')
    if lat < 0:
        lonlat_str = lonlat_str.replace('N', 'S')

    mkdir(directory)

    # Make the plot
    png = os.path.join(directory, 'annual_cycle.png')
    df = get_cru_timeseries(lon, lat)

    #check if df has NaNs
    if df.isnull().any().any():
        print(
            "The location you chose is not available. Please choose another location."
        )
        sys.exit()

    graphics.plot_annual_cycle(df, filepath=png)
    print(df)
    outpath = os.path.join(directory, 'index.html')
    with open(cfg.html_tpl, 'r') as infile:
        lines = infile.readlines()
        out = []
        url = get_googlemap_url(lon, lat, zoom=zoom)
        for txt in lines:
            txt = txt.replace('[LONLAT]', lonlat_str)
            txt = txt.replace('[IMGURL]', url)
            out.append(txt)
        with open(outpath, 'w') as outfile:
            outfile.writelines(out)

    return outpath
Esempio n. 4
0
def write_html(lon, lat, directory=None, zoom=None):

    # Set defaults
    if directory is None:
        directory = mkdtemp()

    if zoom is None:
        zoom = cfg.default_zoom

    # Info string
    lonlat_str = '({:.3f}E, {:.3f}N)'.format(abs(lon), abs(lat))
    if lon < 0:
        lonlat_str = lonlat_str.replace('E', 'W')
    if lat < 0:
        lonlat_str = lonlat_str.replace('N', 'S')

    mkdir(directory)

    # Make the plot
    png = os.path.join(directory, 'annual_cycle.png')
    png2 = os.path.join(directory, 'time_line.png')
    df = get_cru_timeseries(lon, lat)

    # Check for NaNs in DataFrame
    if not df.isnull().values.any():
        graphics.plot_annual_cycle(df, filepath=png)
        graphics.plot_time_line(df, filepath=png2)
        outpath = os.path.join(directory, 'index.html')
        with open(cfg.html_tpl, 'r') as infile:
            lines = infile.readlines()
            out = []
            url = get_googlemap_url(lon, lat, zoom=zoom)
            for txt in lines:
                txt = txt.replace('[LONLAT]', lonlat_str)
                txt = txt.replace('[IMGURL]', url)
                out.append(txt)
            with open(outpath, 'w') as outfile:
                outfile.writelines(out)
        return outpath
    else:
        raise ValueError('No data available over the ocean. '
                         'Try for different location!')
Esempio n. 5
0
def test_annual_cycle(tmpdir):

    df_cities = pd.read_csv(cfg.world_cities)
    dfi = df_cities.loc[df_cities.Name.str.contains('innsbruck', case=False,
                                                    na=False)].iloc[0]
    df = core.get_cru_timeseries(dfi.Lon, dfi.Lat)

    fig = graphics.plot_annual_cycle(df)

    # Check that the text is found in figure
    ref = 'Climate diagram at location (11.25°, 47.25°)'
    test = [ref in t.get_text() for t in fig.findobj(mpl.text.Text)]
    assert np.any(test)

    # Check that figure is created
    fpath = str(tmpdir.join('annual_cycle.png'))
    graphics.plot_annual_cycle(df, filepath=fpath)
    assert os.path.exists(fpath)

    plt.close()
Esempio n. 6
0
def write_html(lon, lat, directory=None, zoom=None):

    # Set defaults
    if directory is None:
        # Since WSL is a bit special and no auto ouptput to browser is possible
        # I have to print to a tmp folder. Default is a bit messy to find in
        # WSL so specifying a new one.
        tmp_dir = ('/mnt/c/Users/eahol/Courses/Scientific programming/ClimVis/'
                   'tmp/')
        directory = mkdtemp(dir=tmp_dir)

    if zoom is None:
        zoom = cfg.default_zoom

    # Info string
    lonlat_str = '({:.3f}E, {:.3f}N)'.format(abs(lon), abs(lat))
    if lon < 0:
        lonlat_str = lonlat_str.replace('E', 'W')
    if lat < 0:
        lonlat_str = lonlat_str.replace('N', 'S')

    mkdir(directory)

    # Make the plot
    png = os.path.join(directory, 'annual_cycle.png')
    df = get_cru_timeseries(lon, lat)
    graphics.plot_annual_cycle(df, filepath=png)

    outpath = os.path.join(directory, 'index.html')
    with open(cfg.html_tpl, 'r') as infile:
        lines = infile.readlines()
        out = []
        url = get_googlemap_url(lon, lat, zoom=zoom)
        for txt in lines:
            txt = txt.replace('[LONLAT]', lonlat_str)
            txt = txt.replace('[IMGURL]', url)
            out.append(txt)
        with open(outpath, 'w') as outfile:
            outfile.writelines(out)

    return outpath