<jupyter_start><jupyter_text>This notebook calculates gridded maps with mass fractional contribution by sector to total NMVOC for MOZART VOCs species.<jupyter_code>import xarray as xr
import numpy as np
import os
import pandas as pd
#data dir paths.
voc_dir='/geos/d21/s1878599/edgarv5_process/monthly_nmvocs4.3.2_mass_MOZART/'
save_dir='/geos/d21/s1878599/edgarv5_process/monthly_nmvocs4.3.2_fractional_MOZART/'
#create save directory if missing.
if not os.path.isdir(save_dir):
    !mkdir -p $save_dir<jupyter_output><empty_output><jupyter_text>Read VOCs<jupyter_code>#get all vocs files as ordered dictionary of xarray datasets.
def get_vocs_arr(voc_dir):
    '''
    put all vocs files as ordered dictionary of xarray datasets.
    voc_dir: path to where vocs files are.
    output: lsit of dataset with individual vocs.
    '''
    vocs={}
    for f in os.listdir(voc_dir):
        vname=f.split('_')[3]
        vocs.update({vname:xr.open_dataset(voc_dir+f)})  
    return vocs
vocs=get_vocs_arr(voc_dir)
# get total nmvoc summing all vocs contributions.
tot_nmvoc=sum(vocs.values())
tot_nmvoc<jupyter_output><empty_output><jupyter_text>Create fractional maps<jupyter_code>for k in list(vocs.keys()):
    print(k)
    ds=(vocs[k]/tot_nmvoc).fillna(0.0)  # divide eac voc mass by total NMVOC mass.
    ds.attrs['title']='Monthly fractional contribution of ' + k
    ds.to_netcdf(save_dir+'monthly_v432_2010_fraction_'+ k + '_.0.1x0.1.nc',format='NETCDF3_64BIT') #save new file.<jupyter_output>HCOOH
MEK
CH3COOH
BIGALK
C3H6
CH3COCH3
CH3CHO
C2H2
C2H5OH
BENZENE
XYLENES
BIGENE
CH2O
C2H6
TOLUENE
C2H4
C3H8
CH3OH<jupyter_text>Check total vocs<jupyter_code>#get all vocs files as ordered dictionary of xarray datasets.
def get_vocs_arr_frac(voc_dir):
    vocs={}
    for f in os.listdir(voc_dir):
        vname=f.split('_')[4]
        vocs.update({vname:xr.open_dataset(voc_dir+f)})  
    return vocs
vocs_frac=get_vocs_arr_frac(save_dir)
# get total nmvoc summing all vocs contributions.
for k,v in vocs_frac.items():
    vocs_frac[k]=v*tot_nmvoc
tot_nmvoc_calc=sum(vocs_frac.values())
tot_nmvoc_calc
#test
xr.testing.assert_allclose(tot_nmvoc_calc, tot_nmvoc)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10232983097304706, 'fraction_numerical': 0.02832343535861124, 'mean_word_length': 5.221590909090909, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '495942', 'license': 'MIT', 'n_tokens_mistral': 951, 'n_tokens_neox': 900, 'n_words': 185, 'path': 'code/nmvoc4.3.2_map_mozart_fractions.ipynb', 'repo_name': 'catemgn/EDGARv5_MOZART', 'size': '2189'}