<jupyter_start><jupyter_text>OMIThe files of OMI are in he5 format. We are taking monthly averages to make the data compatible to POLDER. Since, POLDER data was in monthly averages for 2006.<jupyter_code>import rasterio 
import numpy as np
import matplotlib.pyplot as plt
import h5py
%matplotlib notebook
%qtconsole
import numpy as np
import h5py
import glob
import geopandas as gpd
import pandas as pd
from shapely.geometry import Polygon
from matplotlib.pylab import plt
import h5py
filename = "DATA/OMId3/omilevel3/OMI-Aura_L3-OMAEROe_2006m0102_v003-2011m1109t085136.he5"

with h5py.File(filename, "r") as f:
    # List all groups
    print("Keys: %s" % f.keys())
    a_group_key = list(f.keys())[0]

    # Get the data
    data = list(f[a_group_key])
f = h5py.File(filename, mode='r')
for name in f:
    print(name)
f.visit(lambda x: print(x))
f = h5py.File(filename, mode='r')

f.visit(lambda x: print(x))

Aerosolmodel = f['HDFEOS/GRIDS/ColumnAmountAerosol/Data Fields/AerosolModelMW']
print(Aerosolmodel.len)
lat = f['HDFEOS/GRIDS/ColumnAmountAerosol/Data Fields/Latitude']
lon = f['HDFEOS/GRIDS/ColumnAmountAerosol/Data Fields/Longitude']
lat
so2 = Aerosolmodel
so2
for a in so2.attrs:
    print(a, so2.attrs[a])
    
# Some of these are floats, others are strings, extracting values is difference depending on which:
nodata = so2.attrs['MissingValue'][0]
units = so2.attrs['Units'].decode()
titlestr = so2.attrs['Title'].decode()
titlestr = so2.attrs['UniqueFieldDefinition'].decode()
FILL_VALUE = -1,2676506e+30

def monthly_no2(files, filter_to_nan = 14.5): 
    '''
    
    Return monthly averaged $NO_2$ matrix from  a list of files
    
    
    
    '''
    
    arr = np.empty(len(files), lat.shape[0], lon.shape[0], dtype = float) 
    p = 'ColumnAmountNO2TropCloudScreened'
    for ix, file in enumerate(files): 
        with h5py.File(file, 'r') as f:
            data = f['HDFEOS']['GRIDS']['ColumnAmountNO2']['Data Fields'][p][:]
            data[(data == FILL_VALUE) | (data <= 0)] = np.nan
            arr[ix] = data 
            
    average_monthly = np.log10(np.nanmean(arr,axis = 0))
    average_monthly[average_monthly < filter_to_nan] = np.nan
    return average_monthly

average_monthly = monthly_no2(files)
# Making the countries map 
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))

world = world[['continent', 'geometry']]

continents = world.dissolve(by='continent')
continents = world.dissolve(by='continent')
continents = continents[~continents.index.isin(['Seven seas (open ocean)', 'Antarctica'])]
continents = continents.geometry.explode().reset_index()
continents


data = so2.value
nodata = so2.attrs['MissingValue']
data[so2.value == nodata] = np.nan
# Import Python packages (tools for working with geospatial data)
import rasterio 
import numpy as np
import matplotlib.pyplot as plt
import h5py
%matplotlib notebook
%qtconsole

plt.figure(figsize=(8,4))
plt.imshow(data)
cb = plt.colorbar()
cb.set_label(units)
plt.title(filename)
import os
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import numpy as np
import h5py
# Open file.
filename = "DATA/OMId3/omilevel3/OMI-Aura_L3-OMAEROe_2006m0102_v003-2011m1109t085136.he5"
DATAFIELD_NAME = '/HDFEOS/GRIDS/OMI Column Amount O3/Data Fields/ColumnAmountO3'
with h5py.File(filename, mode='r') as f:
# List available datasets.
    print f.keys()

# Read dataset.
    dset = f[DATAFIELD_NAME]
    data = dset[:]

# Handle fill value.
    data[data == dset.fillvalue] = np.nan
    data = np.ma.masked_where(np.isnan(data), data)

# Get attributes needed for the plot.
# String attributes actually come in as the bytes type and should
# be decoded to UTF-8 (python3).
    title = dset.attrs['Title'].decode()
    units = dset.attrs['Units'].decode()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12043795620437957, 'fraction_numerical': 0.03023983315954119, 'mean_word_length': 4.389044943820225, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '577833', 'license': 'MIT', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1360, 'n_words': 343, 'path': 'OMI_PLotting.ipynb', 'repo_name': 'sniggy93/Machinelearning_Aerosol', 'size': '3836'}