import os import glob import numpy as np import xarray as xr from satpy import Scene…
- User
import os import glob import numpy as np import xarray as xr from satpy import Scene import matplotlib.pyplot as plt from matplotlib.colors import LinearSegmentedColormap import cartopy.feature as cfeature
Paths to your data
path_to_li_data = 'dataf' path_to_seviri_data = 'dataf2'
Find LI and SEVIRI files
li_files = glob.glob(os.path.join(path_to_li_data, '')) seviri_files = glob.glob(os.path.join(path_to_seviri_data, '.nat'))
Create a dictionary of filenames for both readers
filenames = { 'li_l2_nc': li_files, 'seviri_l1b_native': seviri_files }
Create a Scene object with both LI and SEVIRI data
scn = Scene(filenames=filenames)
Load the datasets
Adjust 'flash_accumulation' to 'accumulated_flash_area' or 'accumulated_flash_radiance' if needed
scn.load(['flash_id', 'HRV'])
Resample to a common area
scn1 = scn.resample('eurol', resampler='nearest')
Create a RGB composite
Here we're using IR_108 as a greyscale background and overlaying the flash data
ir_data = scn1['HRV'] flash_data = scn1['flash_id']
Normalize IR data to 0-1 range
ir_norm = (ir_data - np.nanmin(ir_data)) / (np.nanmax(ir_data) - np.nanmin(ir_data))
Normalize flash data to 0-1 range
flash_norm = (flash_data - np.nanmin(flash_data)) / (np.nanmax(flash_data) - np.nanmin(flash_data))
Create YlOrBr colormap
colors = ['#FFFFE5', '#FFF7BC', '#FEE391', '#FEC44F', '#FE9929', '#EC7014', '#CC4C02', '#8C2D04'] n_bins = 100 cmap_YlOrBr = LinearSegmentedColormap.from_list('YlOrBr', colors, N=n_bins)
Plot the composite
fig, ax = plt.subplots(figsize=(15,15))
ax.add_feature(cfeature.COASTLINE) ax.add_feature(cfeature.BORDERS, linestyle=':')
Plot IR data in grayscale
ax.imshow(ir_norm, cmap='gray', alpha=0.85, extent=scn1['HRV'].attrs['area'].area_extent_ll)
Overlay flash data with YlOrBr colormap
im = ax.imshow(flash_norm, cmap=cmap_YlOrBr, alpha=1, extent=scn1['flash_id'].attrs['area'].area_extent_ll)
ax.axis('off')
plt.tight_layout() plt.show()
Can you write a similar code but only for MTG FCI data, so 1 path of data?
- Assistant