Home > Blockchain >  Mask lots of missing Data in tricontourf
Mask lots of missing Data in tricontourf

Time:10-03

enter image description here I have a relatively large dataset which contains data for a whole year. I did so by concatenating all the dataframes for each doy to come up with this huge dataset however on some of the days there is no data available so there are large gaps in the data. I only want to plot the real data and mask or white out the missing data. I tried to resample the data to hourly but when i do this i get an "Error in qhull Delaunay triangulation calculation: input inconsistency (exitcode=1)" So at first i tried to drop the NAN the problem is tricontourf ended up filling the missing data instead of ignoring it or masking it. So i came up with the solution below but it is only masking part of the points and filling the other half with artifacts.

import matplotlib.pyplot as mp
import numpy as np
import matplotlib.tri as tri
fig,ax=plt.subplots()
dy=devstns[0]
dy=dy.resample("H",base=1).mean()
dy["date"]=dy.index
dy["doy"] = dy["date"].apply(lambda x: x.timetuple().tm_yday)
dy =dy.fillna(0)
x=dy.doy.values
y=dy.UT.values[![enter image description here][1]][1]
z=dy.TEC.values
bad = np.ma.masked_invalid(z)
isbad=np.equal(z,0)
triang = tri.Triangulation(x, y)
mask = np.any(np.where(isbad[triang.triangles], True, False), axis=1)
triang.set_mask(mask)
colplt = ax.tricontourf(triang, z)

Here is a data sample

|pctDev | doy | deltaTEC | QTEC | year | TEC | UT date
2018-08-01 00:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-01 01:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-01 02:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-01 03:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-01 04:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-01 05:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-01 06:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-01 07:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-01 08:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-01 09:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-01 10:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-01 11:00:00 NaN NaN NaN NaN NaN NaN NaN

2018-08-01 21:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-01 22:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-01 23:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-02 00:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-02 01:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-02 02:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-02 03:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-02 04:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-02 05:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-02 06:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-02 07:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-02 08:00:00 NaN NaN NaN NaN NaN NaN NaN

2018-08-05 14:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-05 15:00:00 NaN NaN NaN NaN NaN NaN NaN 2018-08-05 16:00:00 NaN NaN NaN NaN NaN NaN NaN

2018-08-15 00:00:00 -33.568720 227.0 -2.578583 7.558583 2018.0 4.980000 0.491667 2018-08-15 01:00:00 -21.027371 227.0 -1.216333 5.755833 2018.0 4.539500 1.491667 2018-08-15 02:00:00 -11.645713 227.0 -0.593917 5.052917 2018.0 4.459000 2.491667 2018-08-15 03:00:00 -11.743647 227.0 -0.461083 3.936250 2018.0 3.475167 3.491667 2018-08-15 04:00:00 -5.666851 227.0 -0.184583 3.155417 2018.0 2.970833 4.491667 2018-08-15 05:00:00 -5.690906 227.0 -0.154583 2.702417 2018.0 2.547833 5.491667 2018-08-15 06:00:00 -16.918020 227.0 -0.469583 2.766583 2018.0 2.297000 6.491667 2018-08-15 07:00:00 -2.511416 227.0 -0.061917 2.550750 2018.0 2.488833 7.491667

CodePudding user response:

The tricontourf apparently does not accept NAN for the x and y arrays so I filled in the missing x values just as i did for the Julian day which is probably why it was masking only halfway. In my case I used the timetuple to fill in missing julian day and time. I think this allows the triangulation to find the indices where z in Nan(set to zero) so as to mask.

import matplotlib.pyplot as mp
import numpy as np
import matplotlib.tri as tri
fig,ax=plt.subplots()
dy=devstns[0]
dy=dy.resample("H",base=1).mean()
dy["date"]=dy.index
dy["doy"] = dy["date"].apply(lambda x: x.timetuple().tm_yday)
dy["HH"] = dy["date"].apply(lambda x: x.timetuple().tm_hour)

dy =dy.fillna(0)
x=dy.doy.values
y=dy.UT.values
z=dy.TEC.values

isbad=np.equal(z,0)
triang = tri.Triangulation(x, y)
mask = np.any(np.where(isbad[triang.triangles], True, False), axis=1)
triang.set_mask(mask)
colplt = ax.tricontourf(triang, z)
  • Related