from svrimg.utils.get_tables import get_index_table, get_svrgis_table
df_svrgis = get_svrgis_table(data_dir="../data/csvs/")
df_svrgis.head()
from imageio import imread
import numpy as np
vals = []
for fname in ['test_img1', 'test_img2', 'test_img3', 'test_img4', 'test_img5']:
vals.append(imread(fname + ".png", pilmode='P'))
np.save("test_imgs.npy", np.array(vals))
This utility takes unique ids and saves the images from svrimg to the given folder. It only downloads a file once, but always returns the file location even if the file was already downloaded.
from svrimg.utils.get_images import request_images
df_subset = df_svrgis[(df_svrgis.yr==2011) & (df_svrgis.mo==4) & (df_svrgis.dy.isin([4, 5]))].copy()
df_subset
loc = request_images(df_subset.index.values, "../data/tor")
loc
from svrimg.utils.get_images import read_image
import numpy as np
images = []
for unid, file in loc.items():
if file != None:
images.append(read_image(file))
images = np.array(images)
images.shape
import matplotlib.pyplot as plt
from utils.map_helper import draw_box_plot
%matplotlib inline
plt.rcParams['figure.figsize'] = 25, 25
plt.rcParams['xtick.labelsize'] = 20
plt.rcParams['ytick.labelsize'] = 20
plt.rcParams['axes.labelsize'] = 20
ax = plt.subplot(2,3,1)
ax = draw_box_plot(ax, images[0])
from svrimg.utils.pmmean import _run_pmm_one_variable
img_mean = np.mean(images, axis=0)
img_median = np.median(images, axis=0)
img_pmm = _run_pmm_one_variable(images)
plt.rcParams['figure.figsize'] = 25, 25
plt.rcParams['xtick.labelsize'] = 20
plt.rcParams['ytick.labelsize'] = 20
plt.rcParams['axes.labelsize'] = 20
ax = plt.subplot(2,3,1)
ax.set_title("Mean", fontsize=20)
ax = draw_box_plot(ax, img_mean)
ax = plt.subplot(2,3,2)
ax.set_title("Median", fontsize=20)
ax = draw_box_plot(ax, img_median)
ax = plt.subplot(2,3,3)
ax.set_title("PMM", fontsize=20)
ax = draw_box_plot(ax, img_pmm)
from svrimg.utils.get_images import get_img_list
feb = df_svrgis[df_svrgis.mo==2].copy()
feb_imgs = get_img_list(feb.index.values, data_dir="../data/tor/")
feb_mean = np.mean(feb_imgs, axis=0)
feb_median = np.median(feb_imgs, axis=0)
feb_pmm = _run_pmm_one_variable(feb_imgs)
aug = df_svrgis[df_svrgis.mo==8].copy()
aug_imgs = get_img_list(aug.index.values, data_dir="../data/tor/")
aug_mean = np.mean(aug_imgs, axis=0)
aug_median = np.median(aug_imgs, axis=0)
aug_pmm = _run_pmm_one_variable(aug_imgs)
plt.rcParams['figure.figsize'] = 25, 25
plt.rcParams['xtick.labelsize'] = 20
plt.rcParams['ytick.labelsize'] = 20
plt.rcParams['axes.labelsize'] = 20
ax = plt.subplot(2,3,1)
ax.set_title("February Mean", fontsize=20)
ax = draw_box_plot(ax, feb_mean)
ax = plt.subplot(2,3,2)
ax.set_title("February Median", fontsize=20)
ax = draw_box_plot(ax, feb_median)
ax = plt.subplot(2,3,3)
ax.set_title("February PMM", fontsize=20)
ax = draw_box_plot(ax, feb_pmm)
ax = plt.subplot(2,3,4)
ax.set_title("August Mean", fontsize=20)
ax = draw_box_plot(ax, aug_mean)
ax = plt.subplot(2,3,5)
ax.set_title("August Median", fontsize=20)
ax = draw_box_plot(ax, aug_median)
ax = plt.subplot(2,3,6)
ax.set_title("August PMM", fontsize=20)
ax = draw_box_plot(ax, aug_pmm)
plt.tight_layout()
from svrimg.utils.get_images import get_img_list
djf = df_svrgis[df_svrgis.mo.isin([12, 1, 2])].copy()
djf_imgs = get_img_list(djf.index.values, data_dir="../data/tor/")
djf_mean = np.mean(djf_imgs, axis=0)
djf_median = np.median(djf_imgs, axis=0)
djf_pmm = _run_pmm_one_variable(djf_imgs)
mam = df_svrgis[df_svrgis.mo.isin([3, 4, 5])].copy()
mam_imgs = get_img_list(mam.index.values, data_dir="../data/tor/")
mam_mean = np.mean(mam_imgs, axis=0)
mam_median = np.median(mam_imgs, axis=0)
mam_pmm = _run_pmm_one_variable(mam_imgs)
jja = df_svrgis[df_svrgis.mo.isin([6, 7, 8])].copy()
jja_imgs = get_img_list(jja.index.values, data_dir="../data/tor/")
jja_mean = np.mean(jja_imgs, axis=0)
jja_median = np.median(jja_imgs, axis=0)
jja_pmm = _run_pmm_one_variable(jja_imgs)
son = df_svrgis[df_svrgis.mo.isin([9, 10, 11])].copy()
son_imgs = get_img_list(son.index.values, data_dir="../data/tor/")
son_mean = np.mean(son_imgs, axis=0)
son_median = np.median(son_imgs, axis=0)
son_pmm = _run_pmm_one_variable(son_imgs)
ax = plt.subplot(2,2,1)
ax.set_title("DJF PMean", fontsize=20)
ax = draw_box_plot(ax, djf_pmm)
ax = plt.subplot(2,2,2)
ax.set_title("MAM PMean", fontsize=20)
ax = draw_box_plot(ax, mam_pmm)
ax = plt.subplot(2,2,3)
ax.set_title("JJA PMean", fontsize=20)
ax = draw_box_plot(ax, jja_pmm)
ax = plt.subplot(2,2,4)
ax.set_title("SON PMean", fontsize=20)
ax = draw_box_plot(ax, son_pmm)