In [1]:
"""
Script to test the upsampling.
"""

from floatpy.readers import samrai_reader
import floatpy.upsampling.Lagrange_upsampler
import numpy

%matplotlib inline
from matplotlib import pyplot as plt
plt.rc("savefig", dpi = 150)

In [2]:
"""
Set the path of the data directory for the data reader.
"""

data_reader = samrai_reader.SamraiDataReader('../tests/test_data_samrai_AMR')
data_order = data_reader.data_order

In [3]:
"""
Read the density data from all levels.
"""

steps = data_reader.steps

data_reader.step = steps[-1]

data_rho, = data_reader.readData('density')

In [4]:
"""
Upsample the data.
"""

r = numpy.array([3, 3])

upsampler_constant = floatpy.upsampling.Lagrange_upsampler.LagrangeUpsampler(method='constant', data_order=data_order)
upsampler_second_order = floatpy.upsampling.Lagrange_upsampler.LagrangeUpsampler(method='second_order', data_order=data_order)
upsampler_fourth_order = floatpy.upsampling.Lagrange_upsampler.LagrangeUpsampler(method='fourth_order', data_order=data_order)
upsampler_sixth_order = floatpy.upsampling.Lagrange_upsampler.LagrangeUpsampler(method='sixth_order', data_order=data_order)

data_upsampled_1 = upsampler_constant.upsample(data_rho, r)
data_upsampled_2 = upsampler_second_order.upsample(data_rho, r)
data_upsampled_3 = upsampler_fourth_order.upsample(data_rho, r)
data_upsampled_4 = upsampler_sixth_order.upsample(data_rho, r)

In [5]:
"""
Plot the original data.
"""

data_masked = numpy.ma.masked_where(numpy.isnan(data_rho), data_rho)

plt.pcolormesh(data_masked[:,:].T, vmin=0.0, vmax=10.0)
plt.axes().set_aspect('equal', 'datalim')
plt.xlabel('x')
plt.ylabel('y')
plt.colorbar()
plt.show()


/usr/lib/python2.7/dist-packages/matplotlib/collections.py:571: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if self._edgecolors == str('face'):

In [6]:
"""
Plot the first upsampled data.
"""

data_masked_1 = numpy.ma.masked_where(numpy.isnan(data_upsampled_1), data_upsampled_1)

plt.pcolormesh(data_masked_1[:,:].T, vmin=0.0, vmax=10.0)
plt.axes().set_aspect('equal', 'datalim')
plt.xlabel('x')
plt.ylabel('y')
plt.colorbar()
plt.show()



In [7]:
"""
Plot the second upsampled data.
"""

data_masked_2 = numpy.ma.masked_where(numpy.isnan(data_upsampled_2), data_upsampled_2)

plt.pcolormesh(data_masked_2[:,:].T, vmin=0.0, vmax=10.0)
plt.axes().set_aspect('equal', 'datalim')
plt.xlabel('x')
plt.ylabel('y')
plt.colorbar()
plt.show()



In [8]:
"""
Plot the third upsampled data.
"""

data_masked_3 = numpy.ma.masked_where(numpy.isnan(data_upsampled_3), data_upsampled_3)

plt.pcolormesh(data_masked_3[:,:].T, vmin=0.0, vmax=10.0)
plt.axes().set_aspect('equal', 'datalim')
plt.xlabel('x')
plt.ylabel('y')
plt.colorbar()
plt.show()



In [9]:
"""
Plot the fourth upsampled data.
"""

data_masked_4 = numpy.ma.masked_where(numpy.isnan(data_upsampled_4), data_upsampled_4)

plt.pcolormesh(data_masked_4[:,:].T, vmin=0.0, vmax=10.0)
plt.axes().set_aspect('equal', 'datalim')
plt.xlabel('x')
plt.ylabel('y')
plt.colorbar()
plt.show()



In [ ]: