<jupyter_start><jupyter_text>1. Import libraries to be used in this notebook<jupyter_code>import numpy as np # for array manipulation and basic scientific calculation
import xarray as xr # To read NetCDF files
import matplotlib.pyplot as plt # Core library for plotting
from functions.SE_analysis import get_site_index # To get<jupyter_output><empty_output><jupyter_text>2. Read files  2.1. Model output<jupyter_code>Filebase_CONUS = '/glade/campaign/acom/acom-climate/tilmes/CO_CONUS/f.e22.FCcotagsNudged.ne0CONUSne30x8.cesm220.2012-01/atm/hist/f.e22.FCcotagsNudged.ne0CONUSne30x8.cesm220.2012-01.cam.h4.2013-08-DD-00000.nc'

# Change "DD" to 01~31 for a month timeseries
Files_CONUS = [] # empty list for a start
# file list with 31 files
for dd in np.arange(31):
    Files_CONUS.append( Filebase_CONUS.replace('DD',str(dd+1).zfill(2)) )
# read 12 files at once using "mf"dataset
ds_CONUS = xr.open_mfdataset( Files_CONUS )<jupyter_output><empty_output><jupyter_text>2.2. SCRIP file SCRIP file has grid information that is needed to find index of city Don't have to read, just locate where the files are<jupyter_code>SCRIP_CONUS = '/glade/p/acom/MUSICA/grids/ne0CONUSne30x8/ne0CONUS_ne30x8_np4_SCRIP.nc'<jupyter_output><empty_output><jupyter_text>3. Find indices of cities on spectral element grid<jupyter_code># Use python dictionary for lon/lat locations of cities
City_lonlat = {}
City_lonlat['Denver'] = [ 255.0097, 39.7393 ] # Front range
City_lonlat['LA'] = [ 241.7563, 34.0522 ] # Heavy anthropogenic sources
City_lonlat['Centreville'] = [ 272.8614, 32.9446 ] # Biogenics dominant

# Get index of each city location
Index_lonlat = {}
for city in City_lonlat.keys():
    Index_lonlat[city] = get_site_index( City_lonlat[city][0], City_lonlat[city][1], 
                                         scrip_file=SCRIP_CONUS )<jupyter_output><empty_output><jupyter_text>4. Get timeseries<jupyter_code>TS = {}
for city in City_lonlat.keys():
    TS[city] = ds_CONUS['O3_SRF'].values[:,Index_lonlat[city]] # dimension -> time,ncol<jupyter_output><empty_output><jupyter_text>5. Draw a simple plot<jupyter_code>fig = plt.figure( figsize=(30,5) )
ax = fig.add_subplot(1,1,1)

# Plot O3 timeseries
ax.plot( ds_CONUS.time.values, TS['Denver']*1e9, 'b-', label='Denver' )
ax.plot( ds_CONUS.time.values, TS['LA']*1e9, 'r-', label='LA' )
ax.plot( ds_CONUS.time.values, TS['Centreville']*1e9, 'g-', label='Centreville' )


# === Polish the plot === 
# Font size
xticklabels = plt.setp( ax.get_xticklabels(), fontsize=15 )
yticklabels = plt.setp( ax.get_yticklabels(), fontsize=15 )
# Add x & y axis titles
xlabel = ax.set_xlabel( 'Date', fontsize=15 )
ylabel = ax.set_ylabel( 'Ozone [ppbv]', fontsize=15 )
# Add plot title
title = ax.set_title( 'Surface ozone timeseries in AUG 2013', fontsize=17, weight='semibold' )
# Add legend
ax.legend( loc=0, handlelength=5, fontsize=15 )<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12875388332758025, 'fraction_numerical': 0.050051777701070076, 'mean_word_length': 5.411504424778761, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '207251', 'license': 'Apache-2.0', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1101, 'n_words': 242, 'path': 'timeseries.ipynb', 'repo_name': 'NCAR/musica-tutorial', 'size': '2897'}