text_plain_output_1.png
from netCDF4 import Dataset

import netCDF4

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

def geo_idx(dd, dd_array):
    """
     search for nearest decimal degree in an array of decimal degrees and return the index.
     np.argmin returns the indices of minium value along an axis.
     so subtract dd from all values in dd_array, take absolute value and find index of minium.
    """
    geo_idx = np.abs(dd_array - dd).argmin()
    return geo_idx

rootdir = '/kaggle/input/models/wrf-chem/'
curr_date = 20220218
cycle = '12'
ncfile = Dataset(rootdir + str(curr_date) + cycle + '_NOA-WRF-CHEM.nc')

times = ncfile.variables['time']
times_convert = np.array(netCDF4.num2date(times[:], times.long_name), dtype='datetime64[s]')
nTimes = len(times)
d = pd.to_datetime(np.datetime_as_string(times_convert, timezone='UTC', unit='s'))
sconc_dust = ncfile.variables['SCONC_DUST'][:]
lats = ncfile.variables['latitude'][:]
lons = ncfile.variables['longitude'][:]

pois = pd.read_csv(rootdir + 'GREECE_POIS_NEW.csv', sep='\t')
pois = pois.dropna(how='all', axis='columns')
poi_name = pois['NAME']
poi_lat = pois['LATITUDE']
poi_lon = pois['LONGITUDE']
poi_alt = pois['ELEVATION']
npois = poi_name.count()
poi_lat_int = poi_lat.astype(int)
poi_lat_dec = (poi_lat - poi_lat_int) * (100.0 / 60.0)
poi_lat_final = poi_lat_int + poi_lat_dec
poi_lon_int = poi_lon.astype(int)
poi_lon_dec = (poi_lon - poi_lon_int) * (100.0 / 60.0)
poi_lon_final = poi_lon_int + poi_lon_dec
pois.head()