In [2]:
from pylab import matplotlib
from datetime import date
from os import path

import urllib.request
import urllib.request, json 
import pprint
import os
import pandas as pd
import glob
import netCDF4
import random
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.cm as cm
import numpy as np
import numpy.ma as ma
import warnings

from matplotlib.pyplot import figure

warnings.filterwarnings('ignore')

You can download the file used in this tutorial by clicking on the provided link:

https://drive.google.com/file/d/1hp5vdonRXYNJ2AEgk-RS_rtij0GSSzy6/view?usp=sharing

In [3]:
file_name = "/Volumes/HD2/Datasets/Research//NASA/Suomi-NPP/VIIRS/VNP14IMG/2019/2019_08_03/VNP14IMG.A2019215.2106.001.2019216045602.nc"
In [4]:
f = netCDF4.Dataset(file_name)

print(f)
<class 'netCDF4._netCDF4.Dataset'>
root group (NETCDF4 data model, file format HDF5):
    VIAES: NPP_VIAES_L1.A2019215.2106.001.2019216025724.hdfNPP_IMFTS_L1.A2019215.2106.001.2019216024225.hdf
    IMFTS: NPP_IMFTS_L1.A2019215.2106.001.2019216024225.hdf
    VMAES: NPP_VMAES_L1.A2019215.2106.001.2019216025724.hdfidentifier_product_doi_authority
    VCDGIPS: NPP_VCDGIPS_L1.A2019215.2106.001.2019216025724.hdf�
    QSLWMIP: VNP_QSLWMIP_L2.A2019215.2106.001.2019216030929.hdf�
    ProcessVersionNumber: 2.5.4
    ExecutableCreationDate: Feb  5 2018
    ExecutableCreationTime: 13:56:23s
    Satellite: NPP
    SystemID: Linux minion7124 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64
    Unagg_GRingLatitude: TS 0: 47.4731, 44.8937, 42.4381, 41.1989, 37.0747, 39.3319, 41.6791, 46.1439; TS 1: 52.3716, 49.7973, 47.3465, 46.1451, 41.5646, 43.7661, 46.0473, 51.0633; TS 2: 57.2554, 54.6892, 52.2452, 51.0643, 45.9342, 48.0652, 50.2589, 55.9459; TS 3: 62.1178, 59.5633, 57.1292, 55.9468, 50.1499, 52.1849, 54.2606, 60.7756; TS 4: 63.2272, 62.6138, 61.9919, 60.7763, 54.1575, 54.6544, 55.1396, 61.8718�
    Unagg_GRingLongitude: TS 0: -104.554, -104.518, -104.416, -122.893, -139.895, -141.308, -142.896, -124.705; TS 1: -104.49, -104.573, -104.568, -124.713, -142.831, -144.486, -146.361, -126.812; TS 2: -104.13, -104.382, -104.516, -126.821, -146.285, -148.243, -150.487, -129.333; TS 3: -103.336, -103.839, -104.167, -129.342, -150.392, -152.748, -155.47, -132.474; TS 4: -103.072, -103.234, -103.387, -132.483, -155.349, -156.048, -156.757, -133.314
    NorthBoundingCoordinate: 63.502495
    SouthBoundingCoordinate: 37.074688
    EastBoundingCoordinate: -103.07199
    WestBoundingCoordinate: -156.75723
    Day/Night/Both: Day
    FirePix: 116
    DayPix: 41574400
    LandPix: 33803672
    NightPix: 0
    SatelliteInstrument: NPP_OPS
    WaterPix: 7770728
    MissingPix: 1
    GlintPix: 963315
    CloudPix: 12186802
    ShortName: VNP14IMG
    RangeBeginningTime: 21:06:00.00000
    publisher_name: LAADS
    creator_email: modis-ops@lists.nasa.gov
    identifier_product_doi_authority: http://dx.doi.org
    GRingPointLongitude: [-104.416 -139.895 -156.757 -103.072]
    AlgorithmVersion: NPP_PR14IMG 2.5.3
    processing_level: Level 2
    ProductionTime: 2019-08-04 04:56:02.000
    PGEVersion: 1.0.7
    publisher_url: http://ladsweb.nascom.nasa.gov
    institution: NASA Goddard Space Flight Center
    identifier_product_doi: 10.5067/VIIRS/VNP14IMG.001
    creator_url: http://ladsweb.nascom.nasa.gov
    VersionID: 001
    PGE_EndTime: 2019-08-03 21:12:00.000
    PGE_Name: PGE530
    keywords_vocabulary: NASA Global Change Master Directory (GCMD) Science Keywords
    DayNightFlag: Day
    InputPointer: /MODAPSops6/archive/f7124/running/VNP_L1bm7/15243081/NPP_VIAES_L1.A2019215.2106.001.2019216025724.hdf, /MODAPSops6/archive/f7124/running/VNP_L1bm7/15243081/NPP_IMFTS_L1.A2019215.2106.001.2019216024225.hdf, /MODAPSops6/archive/f7124/running/VNP_L1bm7/15243081/NPP_VMAES_L1.A2019215.2106.001.2019216025724.hdf, /MODAPSops6/archive/f7124/running/VNP_L1bm7/15243081/NPP_VCDGIPS_L1.A2019215.2106.001.2019216025724.hdf, /MODAPSops6/archive/f7124/running/VNP_L1bm7/15243081/VNP_QSLWMIP_L2.A2019215.2106.001.2019216030929.hdf
    publisher_email: modis-ops@lists.nasa.gov
    project: VIIRS Land SIPS Snow Cover Project
    StartTime: 2019-08-03 21:06:00.000
    license: http://science.nasa.gov/earth-science/earth-science-data/data-information-policy/
    naming_authority: gov.nasa.gsfc.VIIRSland
    LocalGranuleID: VNP14IMG.A2019215.2106.001.2019216045602.nc
    title: VIIRS 375m Active Fire Data
    AlgorithmType: OPS
    creator_name: VIIRS Land SIPS Processing Group
    cdm_data_type: swath
    LongName: VIIRS/NPP Active Fires 6-Min L2 Swath 375m
    RangeBeginningDate: 2019-08-03
    Conventions: CF-1.6
    RangeEndingDate: 2019-08-03
    GRingPointLatitude: [42.4381 37.0747 55.1396 63.2272]
    ProcessingEnvironment: Linux minion7124 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
    ProcessingCenter: MODAPS-NASA
    EndTime: 2019-08-03 21:12:00.000
    stdname_vocabulary: NetCDF Climate and Forecast (CF) Metadata Convention
    RangeEndingTime: 21:12:00.00000
    PGE_StartTime: 2019-08-03 21:06:00.000
    dimensions(sizes): phony_dim_0(116), phony_dim_1(6496), phony_dim_2(6400)
    variables(dimensions): uint16 FP_AdjCloud(phony_dim_0), uint16 FP_AdjWater(phony_dim_0), float32 FP_MAD_DT(phony_dim_0), float32 FP_MAD_T4(phony_dim_0), float32 FP_MAD_T5(phony_dim_0), float32 FP_MeanDT(phony_dim_0), float32 FP_MeanRad13(phony_dim_0), float32 FP_MeanT4(phony_dim_0), float32 FP_MeanT5(phony_dim_0), float32 FP_Rad13(phony_dim_0), float32 FP_SolAzAng(phony_dim_0), float32 FP_SolZenAng(phony_dim_0), float32 FP_T4(phony_dim_0), float32 FP_T5(phony_dim_0), float32 FP_ViewAzAng(phony_dim_0), float32 FP_ViewZenAng(phony_dim_0), uint16 FP_WinSize(phony_dim_0), uint8 FP_confidence(phony_dim_0), uint8 FP_day(phony_dim_0), float32 FP_latitude(phony_dim_0), uint16 FP_line(phony_dim_0), float32 FP_longitude(phony_dim_0), float32 FP_power(phony_dim_0), uint16 FP_sample(phony_dim_0), uint32 algorithm QA(phony_dim_1, phony_dim_2), uint8 fire mask(phony_dim_1, phony_dim_2)
    groups: 
In [5]:
for key in f.__dict__.keys(): print(key)
VIAES
IMFTS
VMAES
VCDGIPS
QSLWMIP
ProcessVersionNumber
ExecutableCreationDate
ExecutableCreationTime
Satellite
SystemID
Unagg_GRingLatitude
Unagg_GRingLongitude
NorthBoundingCoordinate
SouthBoundingCoordinate
EastBoundingCoordinate
WestBoundingCoordinate
Day/Night/Both
FirePix
DayPix
LandPix
NightPix
SatelliteInstrument
WaterPix
MissingPix
GlintPix
CloudPix
ShortName
RangeBeginningTime
publisher_name
creator_email
identifier_product_doi_authority
GRingPointLongitude
AlgorithmVersion
processing_level
ProductionTime
PGEVersion
publisher_url
institution
identifier_product_doi
creator_url
VersionID
PGE_EndTime
PGE_Name
keywords_vocabulary
DayNightFlag
InputPointer
publisher_email
project
StartTime
license
naming_authority
LocalGranuleID
title
AlgorithmType
creator_name
cdm_data_type
LongName
RangeBeginningDate
Conventions
RangeEndingDate
GRingPointLatitude
ProcessingEnvironment
ProcessingCenter
EndTime
stdname_vocabulary
RangeEndingTime
PGE_StartTime
In [6]:
f.StartTime
Out[6]:
'2019-08-03 21:06:00.000'
In [7]:
f.EndTime
Out[7]:
'2019-08-03 21:12:00.000'
In [8]:
print( f.NorthBoundingCoordinate )
print( f.SouthBoundingCoordinate )
print( f.EastBoundingCoordinate )
print( f.WestBoundingCoordinate )
63.502495
37.074688
-103.07199
-156.75723
In [9]:
for key in f.variables.keys():
    print(key)
FP_AdjCloud
FP_AdjWater
FP_MAD_DT
FP_MAD_T4
FP_MAD_T5
FP_MeanDT
FP_MeanRad13
FP_MeanT4
FP_MeanT5
FP_Rad13
FP_SolAzAng
FP_SolZenAng
FP_T4
FP_T5
FP_ViewAzAng
FP_ViewZenAng
FP_WinSize
FP_confidence
FP_day
FP_latitude
FP_line
FP_longitude
FP_power
FP_sample
algorithm QA
fire mask
In [10]:
for key, variable in f.variables.items():
    print(key)
    print(variable)
    print()
FP_AdjCloud
<class 'netCDF4._netCDF4.Variable'>
uint16 FP_AdjCloud(phony_dim_0)
    long_name: number of adjacent cloud pixels
unlimited dimensions: 
current shape = (116,)
filling off

FP_AdjWater
<class 'netCDF4._netCDF4.Variable'>
uint16 FP_AdjWater(phony_dim_0)
    long_name: number of adjacent water pixels
unlimited dimensions: 
current shape = (116,)
filling off

FP_MAD_DT
<class 'netCDF4._netCDF4.Variable'>
float32 FP_MAD_DT(phony_dim_0)
    long_name: background brightness temperature difference mean absolute deviation
    units: kelvins
unlimited dimensions: 
current shape = (116,)
filling off

FP_MAD_T4
<class 'netCDF4._netCDF4.Variable'>
float32 FP_MAD_T4(phony_dim_0)
    long_name: background I04 brightness temperature mean absolute deviation
    units: kelvins
unlimited dimensions: 
current shape = (116,)
filling off

FP_MAD_T5
<class 'netCDF4._netCDF4.Variable'>
float32 FP_MAD_T5(phony_dim_0)
    long_name: background I05 brightness temperature mean absolute deviation
    units: kelvins
unlimited dimensions: 
current shape = (116,)
filling off

FP_MeanDT
<class 'netCDF4._netCDF4.Variable'>
float32 FP_MeanDT(phony_dim_0)
    long_name: mean background brightness temperature difference��
    units: kelvins
unlimited dimensions: 
current shape = (116,)
filling off

FP_MeanRad13
<class 'netCDF4._netCDF4.Variable'>
float32 FP_MeanRad13(phony_dim_0)
    long_name: M13 background radiance of background`
    units: W/(m^2*sr*μm)
unlimited dimensions: 
current shape = (116,)
filling off

FP_MeanT4
<class 'netCDF4._netCDF4.Variable'>
float32 FP_MeanT4(phony_dim_0)
    long_name: I04 brightness temperature of background@��
    units: kelvins
unlimited dimensions: 
current shape = (116,)
filling off

FP_MeanT5
<class 'netCDF4._netCDF4.Variable'>
float32 FP_MeanT5(phony_dim_0)
    long_name: I05 brightness temperature of background���
    units: kelvins
unlimited dimensions: 
current shape = (116,)
filling off

FP_Rad13
<class 'netCDF4._netCDF4.Variable'>
float32 FP_Rad13(phony_dim_0)
    long_name: M13 radiance of fire pixel
    units: W/(m^2*sr*μm)
unlimited dimensions: 
current shape = (116,)
filling off

FP_SolAzAng
<class 'netCDF4._netCDF4.Variable'>
float32 FP_SolAzAng(phony_dim_0)
    long_name: solar azimuth angle of fire pixel��
    units: degrees
unlimited dimensions: 
current shape = (116,)
filling off

FP_SolZenAng
<class 'netCDF4._netCDF4.Variable'>
float32 FP_SolZenAng(phony_dim_0)
    long_name: solar zenith angle of fire pixel
    units: degrees
unlimited dimensions: 
current shape = (116,)
filling off

FP_T4
<class 'netCDF4._netCDF4.Variable'>
float32 FP_T4(phony_dim_0)
    long_name: I04 brightness temperature of fire pixel���
    units: kelvins
unlimited dimensions: 
current shape = (116,)
filling off

FP_T5
<class 'netCDF4._netCDF4.Variable'>
float32 FP_T5(phony_dim_0)
    long_name: I05 brightness temperature of fire pixel
    units: kelvins
unlimited dimensions: 
current shape = (116,)
filling off

FP_ViewAzAng
<class 'netCDF4._netCDF4.Variable'>
float32 FP_ViewAzAng(phony_dim_0)
    long_name: granule line of fire pixel
    units: degrees
unlimited dimensions: 
current shape = (116,)
filling off

FP_ViewZenAng
<class 'netCDF4._netCDF4.Variable'>
float32 FP_ViewZenAng(phony_dim_0)
    long_name: view zenith angle of fire pixel
    units: degrees
unlimited dimensions: 
current shape = (116,)
filling off

FP_WinSize
<class 'netCDF4._netCDF4.Variable'>
uint16 FP_WinSize(phony_dim_0)
    long_name: background window size
unlimited dimensions: 
current shape = (116,)
filling off

FP_confidence
<class 'netCDF4._netCDF4.Variable'>
uint8 FP_confidence(phony_dim_0)
    long_name: detection confidence
unlimited dimensions: 
current shape = (116,)
filling off

FP_day
<class 'netCDF4._netCDF4.Variable'>
uint8 FP_day(phony_dim_0)
    long_name: day flag for fire pixel
unlimited dimensions: 
current shape = (116,)
filling off

FP_latitude
<class 'netCDF4._netCDF4.Variable'>
float32 FP_latitude(phony_dim_0)
    long_name: latitude of fire pixel
unlimited dimensions: 
current shape = (116,)
filling off

FP_line
<class 'netCDF4._netCDF4.Variable'>
uint16 FP_line(phony_dim_0)
    long_name: granule line of fire pixel
unlimited dimensions: 
current shape = (116,)
filling off

FP_longitude
<class 'netCDF4._netCDF4.Variable'>
float32 FP_longitude(phony_dim_0)
    long_name: longitude of fire pixel
unlimited dimensions: 
current shape = (116,)
filling off

FP_power
<class 'netCDF4._netCDF4.Variable'>
float32 FP_power(phony_dim_0)
    long_name: fire radiative power
    units: MW
unlimited dimensions: 
current shape = (116,)
filling off

FP_sample
<class 'netCDF4._netCDF4.Variable'>
uint16 FP_sample(phony_dim_0)
    long_name: granule sample of fire pixel
unlimited dimensions: 
current shape = (116,)
filling off

algorithm QA
<class 'netCDF4._netCDF4.Variable'>
uint32 algorithm QA(phony_dim_1, phony_dim_2)
    units: bit field
unlimited dimensions: 
current shape = (6496, 6400)
filling off

fire mask
<class 'netCDF4._netCDF4.Variable'>
uint8 fire mask(phony_dim_1, phony_dim_2)
    legend: 
0 not-processed (non-zero QF)
1 bowtie
2 glint
3 water
4 clouds
5 clear land
6 unclassified fire pixel
7 low confidence fire pixel
8 nominal confidence fire pixel
9 high confidence fire pixel

unlimited dimensions: 
current shape = (6496, 6400)
filling off

In [11]:
f.variables['fire mask']
Out[11]:
<class 'netCDF4._netCDF4.Variable'>
uint8 fire mask(phony_dim_1, phony_dim_2)
    legend: 
0 not-processed (non-zero QF)
1 bowtie
2 glint
3 water
4 clouds
5 clear land
6 unclassified fire pixel
7 low confidence fire pixel
8 nominal confidence fire pixel
9 high confidence fire pixel

unlimited dimensions: 
current shape = (6496, 6400)
filling off
In [12]:
masked_data = f.variables['fire mask']
data =  ma.getdata(masked_data)

data
Out[12]:
masked_array(
  data=[[1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        ...,
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1]],
  mask=False,
  fill_value=999999,
  dtype=uint8)
In [13]:
def plot_fire_mask(data,filename,show_plot):
    
    cmap = cm.get_cmap('RdBu_r', 11)    # PiYG

    color_list = ['#808080']

    for i in range(cmap.N):
        rgba = cmap(i)
        color_list.append(matplotlib.colors.rgb2hex(rgba))
    
    fig = figure(num=None, figsize=(12, 10), dpi=200, facecolor='w', edgecolor='k')

    ax = fig.add_subplot(111)

    cmap = color_list
    cmap = mpl.colors.ListedColormap(cmap)

    bounds = [i for i in range(11)]

    norm = mpl.colors.BoundaryNorm(bounds, cmap.N)

    img = plt.imshow(data, cmap=cmap, norm=norm, interpolation='none')

    cbar_bounds = bounds
    cbar_ticks =  [(cbar_bounds[i+1]-cbar_bounds[i])/2.0+cbar_bounds[i] for i in range( len(cbar_bounds) - 1 )] #  [0.5, 1.5, 155.0, 254.0, 255.0]  
    cbar_labels = [i for i in range(10)]

    cbar = plt.colorbar(img, cmap=cmap, norm=norm, boundaries=cbar_bounds, ticks=cbar_ticks)
    cbar.ax.set_yticklabels(cbar_labels, fontsize=10)

    plt.title('FRP MASK')

    plt.grid(c='black',ls='--')

    plt.xticks(np.linspace(0, data.shape[1], 10))
    plt.yticks(np.linspace(0, data.shape[0], 10))

    ax.spines['bottom'].set_color('black')
    ax.spines['top'].set_color('black')
    ax.spines['left'].set_color('black')
    ax.spines['right'].set_color('black')

    #plt.savefig('./outputs/L2/FRP/{}_mask.png'.format(filename.split('.')[0]), dpi=100, bbox_inches='tight')
    
    if show_plot:
        plt.show()
    
    plt.close()
    
    return None

filename = 'test'

plot_fire_mask(data,filename,show_plot=True)
In [ ]:
 
In [ ]:
 
In [14]:
df_mask = pd.DataFrame(data.ravel(),columns=['fire_mask'])

df_mask.columns
Out[14]:
Index(['fire_mask'], dtype='object')
In [15]:
df_mask
Out[15]:
fire_mask
0 1
1 1
2 1
3 1
4 1
... ...
41574395 1
41574396 1
41574397 1
41574398 1
41574399 1

41574400 rows × 1 columns

In [16]:
df_mask['fire_mask'].value_counts()
Out[16]:
5    12286120
4    12186802
3    11748658
1     5352704
8          84
9          20
7          12
Name: fire_mask, dtype: int64
In [17]:
x_axis_size = data.shape[1]
y_axis_size = data.shape[0] 

xv, yv = np.meshgrid(np.arange(0,x_axis_size), np.arange(0,y_axis_size))

df_mask['sample'] = xv.flatten() 
df_mask['line'] = yv.flatten() 

df_mask
Out[17]:
fire_mask sample line
0 1 0 0
1 1 1 0
2 1 2 0
3 1 3 0
4 1 4 0
... ... ... ...
41574395 1 6395 6495
41574396 1 6396 6495
41574397 1 6397 6495
41574398 1 6398 6495
41574399 1 6399 6495

41574400 rows × 3 columns

In [18]:
df = pd.DataFrame()

for variable in ['FP_sample','FP_line','FP_latitude','FP_longitude','FP_power']:
    masked_data =  f.variables[variable]
    data =  ma.getdata(masked_data)
    df[variable] = data.ravel()

df
Out[18]:
FP_sample FP_line FP_latitude FP_longitude FP_power
0 1099 105 42.684219 -111.590736 6.482446
1 3121 421 42.613194 -123.000809 3.368681
2 1638 651 44.262783 -115.163139 21.067020
3 703 685 44.651917 -109.927498 59.521900
4 704 685 44.651749 -109.933182 21.303026
... ... ... ... ... ...
111 2667 1859 47.569641 -122.366379 3.180221
112 877 2197 49.545467 -111.505089 8.626394
113 876 2197 49.545631 -111.499504 8.626394
114 2614 2328 49.126022 -122.608711 5.530323
115 2616 2328 49.124580 -122.620186 2.524116

116 rows × 5 columns

In [20]:
df.rename(columns={'FP_sample': 'sample'}, inplace=True)
df.rename(columns={'FP_line': 'line'}, inplace=True)

df
Out[20]:
sample line FP_latitude FP_longitude FP_power
0 1099 105 42.684219 -111.590736 6.482446
1 3121 421 42.613194 -123.000809 3.368681
2 1638 651 44.262783 -115.163139 21.067020
3 703 685 44.651917 -109.927498 59.521900
4 704 685 44.651749 -109.933182 21.303026
... ... ... ... ... ...
111 2667 1859 47.569641 -122.366379 3.180221
112 877 2197 49.545467 -111.505089 8.626394
113 876 2197 49.545631 -111.499504 8.626394
114 2614 2328 49.126022 -122.608711 5.530323
115 2616 2328 49.124580 -122.620186 2.524116

116 rows × 5 columns

In [21]:
df_merged = pd.merge(df,df_mask, on=['sample','line'], how='inner')

df_merged
Out[21]:
sample line FP_latitude FP_longitude FP_power fire_mask
0 1099 105 42.684219 -111.590736 6.482446 8
1 3121 421 42.613194 -123.000809 3.368681 7
2 1638 651 44.262783 -115.163139 21.067020 8
3 703 685 44.651917 -109.927498 59.521900 9
4 704 685 44.651749 -109.933182 21.303026 8
... ... ... ... ... ... ...
111 2667 1859 47.569641 -122.366379 3.180221 7
112 877 2197 49.545467 -111.505089 8.626394 8
113 876 2197 49.545631 -111.499504 8.626394 7
114 2614 2328 49.126022 -122.608711 5.530323 8
115 2616 2328 49.124580 -122.620186 2.524116 8

116 rows × 6 columns

In [23]:
idx_min = df_merged['sample'].min()
idx_max = df_merged['sample'].max()

jdx_min = df_merged['line'].min()
jdx_max = df_merged['line'].max()
In [ ]:
 
In [29]:
masked_data = f.variables['fire mask']

data =  ma.getdata(masked_data)

#data = data[idx_min:idx_max,jdx_min:jdx_max]
In [62]:
cmap = cm.get_cmap('RdBu_r', 11)    # PiYG

color_list = ['#808080']

for i in range(cmap.N):
    rgba = cmap(i)
    color_list.append(matplotlib.colors.rgb2hex(rgba))

fig = figure(num=None, figsize=(12, 10), dpi=200, facecolor='w', edgecolor='k')

ax = fig.add_subplot(111)

cmap = color_list
cmap = mpl.colors.ListedColormap(cmap)

bounds = [i for i in range(11)]

norm = mpl.colors.BoundaryNorm(bounds, cmap.N)

img = plt.imshow(data, cmap=cmap, norm=norm, interpolation='none')

cbar_bounds = bounds
cbar_ticks =  [(cbar_bounds[i+1]-cbar_bounds[i])/2.0+cbar_bounds[i] for i in range( len(cbar_bounds) - 1 )] #  [0.5, 1.5, 155.0, 254.0, 255.0]  
cbar_labels = [i for i in range(10)]

cbar = plt.colorbar(img, cmap=cmap, norm=norm, boundaries=cbar_bounds, ticks=cbar_ticks)
cbar.ax.set_yticklabels(cbar_labels, fontsize=10)

plt.title('FRP MASK')

plt.grid(c='black',ls='--')

plt.xticks(np.linspace(0, data.shape[1], 10))
plt.yticks(np.linspace(0, data.shape[0], 10))

ax.spines['bottom'].set_color('black')
ax.spines['top'].set_color('black')
ax.spines['left'].set_color('black')
ax.spines['right'].set_color('black')

for index,row in df_merged.iterrows():
    #print(row,type(row),row[1])
    #print(row['sample'])
    plt.scatter(row['sample'],row['line'],s=14,color='red')
    #print('----')

#plt.savefig('./outputs/L2/FRP/{}_mask.png'.format(filename.split('.')[0]), dpi=100, bbox_inches='tight')

plt.show()

plt.close()
In [282]:
f.close()