Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add aerosol related updates #161

Merged
merged 13 commits into from
Jan 14, 2025
Empty file.
2 changes: 1 addition & 1 deletion make_grib2_tables/get-ncep-grib2-table.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
if tblin == '4.5':
units = row['Units']
line = "'%s':['%s','%s']," % (value,center,units)
elif tblin == '4.233':
elif tblin == '4.233' or tblin == '4.230':
chemform = row['Chemical Formula']
line = "'%s':['%s','%s']," % (value,center,chemform)
else:
Expand Down
1 change: 1 addition & 0 deletions make_grib2_tables/list_section4_tables.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
4.224
4.227
4.228
4.230
4.233
4.234
4.235
Expand Down
106 changes: 105 additions & 1 deletion src/grib2io/_grib2io.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def __init__(self, filename: str, mode: Literal["r", "w", "x"] = "r", **kwargs):
File access mode where "r" opens the files for reading only; "w"
opens the file for overwriting and "x" for writing to a new file.
"""

# Manage keywords
if "_xarray_backend" not in kwargs:
kwargs["_xarray_backend"] = False
Expand Down Expand Up @@ -209,6 +210,7 @@ def _build_index(self):
self._index['msgNumber'] = []
self._index['msg'] = []
self._index['isSubmessage'] = []
self._index['isAerosol'] = []
self._hasindex = True

# Iterate
Expand Down Expand Up @@ -325,6 +327,11 @@ def _build_index(self):
self._index['msgNumber'].append(self.messages)
self._index['isSubmessage'].append(_isSubmessage)

# Check if message contains aerosol data based on template number
aero_templates = [46, 48] # These are the currently supported aerosol templates
is_aero = section4[1] in aero_templates
self._index['isAerosol'].append(is_aero)

# Create Grib2Message with data.
msg = Grib2Message(section0,section1,section2,section3,section4,section5,bmapflag)
msg._msgnum = self.messages-1
Expand Down Expand Up @@ -729,12 +736,109 @@ def __post_init__(self):
self.bitMapFlag = templates.Grib2Metadata(self.bitMapFlag,table='6.0')
self.bitmap = None


@property
def _isNDFD(self):
"""Check if GRIB2 message is from NWS NDFD"""
return np.all(self.section1[0:2]==[8,65535])

@property
def _isAerosol(self):
"""Check if GRIB2 message contains aerosol data"""
aero_templates = [46, 48] # 47, 49, 80, 81, 82, 83, 84, 85] <- these don't seem to be working
# TODO: Add other aerosol templates that are failing

# Combine parameters from both tables
aero_params = [
# Basic aerosol parameters
'0', # Aerosol Type
'1', # AOD550
'2', # ASYF
'3', # SSA
'4', # AEC
'5', # AAC
'192', # PMTC
'193', # PMTF
'194', # PM2.5
'195', # COLPM2.5
'196', # PM10

# Additional parameters from table_4_2_0_20
EricEngle-NOAA marked this conversation as resolved.
Show resolved Hide resolved
'0', # Mass Density
'1', # Column Mass density
'2', # Mass Mixing Ratio (Mass Fraction in Air)
'3', # Atmosphere Emission Mass Flux
'4', # Atmosphere Net Production Mass Flux
'5', # Atmosphere Gross Production Mass Flux
'6', # Surface Dry Depsotiion Mass Flux
'7', # Surface Wet Deposition Mass Flux
'8', # Atmosphere Resuspension Mass Flux
'9', # Large Scale Wet Dep Mass Flux
'10', # Convective Wet Dep Mass Flux
'11', # Sedimenation Mass Flux
'12', # Dry Dep Mass Flux
'13', # Transfer From Hydrophobic to Hydrophilic
'14', #Transfer From SO2 (Sulphur Dioxide) to SO4 (Sulphate)','kg kg-1s-1','TRSDS'],
'15', # Dry deposition velocity','m s-1','DDVEL'],
'16', # Mass mixing ratio with respect to dry air','kg kg-1','MSSRDRYA'],
'17', # Mass mixing ratio with respect to wet air','kg kg-1','MSSRWETA'],
'18', # Potential of hydrogen (pH)','pH','POTHPH']
'50', # Amount in Atmosphere','mol','AIA'],
'51', # Concentration In Air','mol m-3','CONAIR'],
'52', # Volume Mixing Ratio (Fraction in Air)','mol mol-1','VMXR'],
'53', # Chemical Gross Production Rate of Concentration','mol m-3s-1','CGPRC'],
'54', # Chemical Gross Destruction Rate of Concentration','mol m-3s-1','CGDRC'],
'55', # Surface Flux','mol m-2s-1','SFLUX'],
'56', # Changes Of Amount in Atmosphere','mol s-1','COAIA'],
'57', # Total Yearly Average Burden of The Atmosphere>','mol','TYABA'],
'58', # Total Yearly Average Atmospheric Loss','mol s-1','TYAAL'],
'59', # Aerosol Number Concentration','m-3','ANCON'],
'60', # Aerosol Specific Number Concentration','kg-1','ASNCON'],
'61', # Maximum of Mass Density','kg m-3','MXMASSD'],
'62', # Height of Mass Density','m','HGTMD'],
'63', # Column-Averaged Mass Density in Layer','kg m-3','CAVEMDL'],
'64', # Mole fraction with respect to dry air','mol mol-1','MOLRDRYA'],
'65', # Mole fraction with respect to wet air','mol mol-1','MOLRWETA'],
'66', # Column-integrated in-cloud scavenging rate by precipitation','kg m-2 s-1','CINCLDSP'],
'67', # Column-integrated below-cloud scavenging rate by precipitation','kg m-2 s-1','CBLCLDSP'],
'68', # Column-integrated release rate from evaporating precipitation','kg m-2 s-1','CIRELREP'],
'69', # Column-integrated in-cloud scavenging rate by large-scale precipitation','kg m-2 s-1','CINCSLSP'],
'70', # Column-integrated below-cloud scavenging rate by large-scale precipitation','kg m-2 s-1','CBECSLSP'],
'71', # Column-integrated release rate from evaporating large-scale precipitation','kg m-2 s-1','CRERELSP'],
'72', # Column-integrated in-cloud scavenging rate by convective precipitation','kg m-2 s-1','CINCSRCP'],
'73', # Column-integrated below-cloud scavenging rate by convective precipitation','kg m-2 s-1','CBLCSRCP'],
'74', # Column-integrated release rate from evaporating convective precipitation','kg m-2 s-1','CIRERECP'],
'75', # Wildfire flux','kg m-2 s-1','WFIREFLX'],
'76', # Emission Rate','kg kg-1 s-1','EMISFLX'],
'77', # Surface Emission flux','kg m-2 s-1','SFCEFLX'],
'78', # Column integrated eastward mass flux','kg m-2 s-1','CEMF'],
'79', # Column integrated northward mass flux','kg m-2 s-1','CNMF'],
'80', # Column integrated divergence of mass flux','kg m-2 s-1','CDIVMF'],
'81', # Column integrated net source','kg m-2 s-1','CNETS'],

# Backscatter and optical parameters
'100', # SADEN
'102', # AOTK
'103', # SSALBK
'104', # ASYSFK
'105', # AECOEF
'106', # AACOEF
'107', # ALBSAT
'108', # ALBGRD
'109', # ALESAT
'110', # ALEGRD
'111', # ANGSTEXP
'112', # SCTAOTK
]

is_aero_template = self.productDefinitionTemplateNumber.value in aero_templates
is_aero_param = ((str(self.parameterCategory) == '13') |
(str(self.parameterCategory) == '20')) and str(self.parameterNumber) in aero_params

# Check table 4.205 aerosol presence
is_aero_type = (str(self.parameterCategory) == '205' and
str(self.parameterNumber) == '1')

return is_aero_template or is_aero_param or is_aero_type #or is_aero_param_t_4_2_0_20

@property
def gdtn(self):
Expand Down
127 changes: 127 additions & 0 deletions src/grib2io/tables/section4.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,133 @@
'255':'Missing',
}

table_4_230 = {'0': ['Ozone', 'O3'],
'1': ['Water Vapour', 'H2O'],
'2': ['Methane', 'CH4'],
'3': ['Carbon Dioxide', 'CO2'],
'4': ['Carbon Monoxide', 'CO'],
'5': ['Nitrogen Dioxide', 'NO2'],
'6': ['Nitrous Oxide', 'N2O'],
'7': ['Formaldehyde', 'HCHO'],
'8': ['Sulphur Dioxide', 'SO2'],
'9': ['Ammonia', 'NH3'],
'10': ['Ammonium', 'NH4+'],
'11': ['Nitrogen Monoxide', 'NO'],
'12': ['Atomic Oxygen', 'O'],
'13': ['Nitrate Radical', 'NO3'],
'14': ['Hydroperoxyl Radical', 'HO2'],
'15': ['Dinitrogen Pentoxide', 'H2O5'],
'16': ['Nitrous Acid', 'HONO'],
'17': ['Nitric Acid', 'HNO3'],
'18': ['Peroxynitric Acid', 'HO2NO2'],
'19': ['Hydrogen Peroxide', 'H2O2'],
'20': ['Molecular Hydrogen', 'H'],
'21': ['Atomic Nitrogen', 'N'],
'22': ['Sulphate', 'SO42-'],
'23': ['Radon', 'Rn'],
'24': ['Elemental Mercury', 'Hg(O)'],
'25': ['Divalent Mercury', 'Hg2+'],
'26': ['Atomic Chlorine', 'Cl'],
'27': ['Chlorine Monoxide', 'ClO'],
'28': ['Dichlorine Peroxide', 'Cl2O2'],
'29': ['Hypochlorous Acid', 'HClO'],
'30': ['Chlorine Nitrate', 'ClONO2'],
'31': ['Chlorine Dioxide', 'ClO2'],
'32': ['Atomic Bromide', 'Br'],
'33': ['Bromine Monoxide', 'BrO'],
'34': ['Bromine Chloride', 'BrCl'],
'35': ['Hydrogen Bromide', 'HBr'],
'36': ['Hypobromous Acid', 'HBrO'],
'37': ['Bromine Nitrate', 'BrONO2'],
'38': ['Oxygen', 'O2'],
'39-9999': ['Reserved', 'unknown'],
'10000': ['Hydroxyl Radical', 'OH'],
'10001': ['Methyl Peroxy Radical', 'CH3O2'],
'10002': ['Methyl Hydroperoxide', 'CH3O2H'],
'10003': ['Reserved', 'unknown'],
'10004': ['Methanol', 'CH3OH'],
'10005': ['Formic Acid', 'CH3OOH'],
'10006': ['Hydrogen Cyanide', 'HCN'],
'10007': ['Aceto Nitrile', 'CH3CN'],
'10008': ['Ethane', 'C2H6'],
'10009': ['Ethene (= Ethylene)', 'C2H4'],
'10010': ['Ethyne (= Acetylene)', 'C2H2'],
'10011': ['Ethanol', 'C2H5OH'],
'10012': ['Acetic Acid', 'C2H5OOH'],
'10013': ['Peroxyacetyl Nitrate', 'CH3C(O)OONO2'],
'10014': ['Propane', 'C3H8'],
'10015': ['Propene', 'C3H6'],
'10016': ['Butanes', 'C4H10'],
'10017': ['Isoprene', 'C5H10'],
'10018': ['Alpha Pinene', 'C10H16'],
'10019': ['Beta Pinene', 'C10H16'],
'10020': ['Limonene', 'C10H16'],
'10021': ['Benzene', 'C6H6'],
'10022': ['Toluene', 'C7H8'],
'10023': ['Xylene', 'C8H10'],
'10024-10499': ['Reserved', 'unknown'],
'10500': ['Dimethyl Sulphide', 'CH3SCH3'],
'10501-20000': ['Reserved', 'unknown'],
'20001': ['Hydrogen Chloride', 'HCL'],
'20002': ['CFC-11', 'unknown'],
'20003': ['CFC-12', 'unknown'],
'20004': ['CFC-113', 'unknown'],
'20005': ['CFC-113a', 'unknown'],
'20006': ['CFC-114', 'unknown'],
'20007': ['CFC-115', 'unknown'],
'20008': ['HCFC-22', 'unknown'],
'20009': ['HCFC-141b', 'unknown'],
'20010': ['HCFC-142b', 'unknown'],
'20011': ['Halon-1202', 'unknown'],
'20012': ['Halon-1211', 'unknown'],
'20013': ['Halon-1301', 'unknown'],
'20014': ['Halon-2402', 'unknown'],
'20015': ['Methyl Chloride (HCC-40)', 'unknown'],
'20016': ['Carbon Tetrachloride (HCC-10)', 'unknown'],
'20017': ['HCC-140a', 'CH3CCl3'],
'20018': ['Methyl Bromide (HBC-40B1)', 'unknown'],
'20019': ['Hexachlorocyclohexane (HCH)', 'unknown'],
'20020': ['Alpha Hexachlorocyclohexane', 'unknown'],
'20021': ['Hexachlorobiphenyl (PCB-153)', 'unknown'],
'20022-29999': ['Reserved', 'unknown'],
'30000': ['Radioactive Pollutant (Tracer, defined by originating centre)', 'unknown'],
'30001-50000': ['Reserved', 'unknown'],
'60000': ['HOx Radical (OH+HO2)', 'unknown'],
'60001': ['Total Inorganic and Organic Peroxy Radicals (HO2+RO2)', 'RO2'],
'60002': ['Passive Ozone', 'unknown'],
'60003': ['NOx Expressed As Nitrogen', 'NOx'],
'60004': ['All Nitrogen Oxides (NOy) Expressed As Nitrogen', 'NOy'],
'60005': ['Total Inorganic Chlorine', 'Clx'],
'60006': ['Total Inorganic Bromine', 'Brx'],
'60007': ['Total Inorganic Chlorine Except HCl, ClONO2: ClOx', 'unknown'],
'60008': ['Total Inorganic Bromine Except Hbr, BrONO2:BrOx', 'unknown'],
'60009': ['Lumped Alkanes', 'unknown'],
'60010': ['Lumped Alkenes', 'unknown'],
'60011': ['Lumped Aromatic Coumpounds', 'unknown'],
'60012': ['Lumped Terpenes', 'unknown'],
'60013': ['Non-Methane Volatile Organic Compounds Expressed as Carbon','NMVOC'],
'60014': ['Anthropogenic Non-Methane Volatile Organic Compounds Expressed as Carbon','aNMVOC'],
'60015': ['Biogenic Non-Methane Volatile Organic Compounds Expressed as Carbon','bNMVOC'],
'60016': ['Lumped Oxygenated Hydrocarbons', 'OVOC'],
'60017-61999': ['Reserved', 'unknown'],
'62000': ['Total Aerosol', 'unknown'],
'62001': ['Dust Dry', 'unknown'],
'62002': ['water In Ambient', 'unknown'],
'62003': ['Ammonium Dry', 'unknown'],
'62004': ['Nitrate Dry', 'unknown'],
'62005': ['Nitric Acid Trihydrate', 'unknown'],
'62006': ['Sulphate Dry', 'unknown'],
'62007': ['Mercury Dry', 'unknown'],
'62008': ['Sea Salt Dry', 'unknown'],
'62009': ['Black Carbon Dry', 'unknown'],
'62010': ['Particulate Organic Matter Dry', 'unknown'],
'62011': ['Primary Particulate Organic Matter Dry', 'unknown'],
'62012': ['Secondary Particulate Organic Matter Dry', 'unknown'],
'62034': ['Brown Carbon Dry', 'unknown'],
'62035-65534': ['Reserved', 'unknown'],
'65535': ['Missing', 'unknown']
}
EricEngle-NOAA marked this conversation as resolved.
Show resolved Hide resolved

table_4_233 = {
'0':['Ozone','O3'],
'1':['Water Vapour','H2O'],
Expand Down
Loading
Loading