Google Air Quality Data

Google Air Quality API
NumPy, Mathematics
Author

Zeel B Patel

Published

August 31, 2023

import requests
import numpy as np
import pandas as pd
import xarray as xr
from tqdm import tqdm
import matplotlib.pyplot as plt
import dask
from dask.distributed import Client, LocalCluster

if "key" in locals():
    pass
else:
    key = input("Enter your key: ")

url = f"https://airquality.googleapis.com/v1/history:lookup?key={key}"
url
'https://airquality.googleapis.com/v1/history:lookup?key=AIzaSyA9ytSec31of_INkpuB3TZ6vLR1nzme9iQ'
if "client" in locals():
    print(client)
else:
    cluster = LocalCluster(n_workers=54, threads_per_worker=1)
    client = Client(cluster)
    print(client)
<Client: 'tcp://127.0.0.1:36239' processes=54 threads=54, memory=503.73 GiB>
payload = {
    "hours": 24 * 30,
    "pageSize": 168,
    "pageToken": "",
    "location": {"latitude": 28.636429, "longitude": 77.201067},
    "extraComputations": ["POLLUTANT_CONCENTRATION", "LOCAL_AQI"],
}

headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

res = response.json()
24 * 30
720
len(res["hoursInfo"])
168
ts = []
codes = []
pm25 = []
df = pd.DataFrame(columns=["timestamp", "value", "code"])

for each in res["hoursInfo"]:
    ts.append(each["dateTime"])
    codes.append(each["pollutants"][4]["code"])
    pm25.append(each["pollutants"][4]["concentration"]["value"])

df["timestamp"] = ts
df["value"] = pm25
df["code"] = codes
df["timestamp"] = pd.to_datetime(df["timestamp"])
df.head(20)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[5], line 9
      7     ts.append(each["dateTime"])
      8     codes.append(each["pollutants"][4]["code"])
----> 9     pm25.append(each["pollutants"][4]["concentration"]["value"])
     11 df["timestamp"] = ts
     12 df["value"] = pm25

KeyError: 'concentration'
sensor_data = pd.read_excel(
    "/home/patel_zeel/blog/posts/site_12220230831125207.xlsx", skiprows=16
)
sensor_data["From Date"] = pd.to_datetime(
    sensor_data["From Date"], format="%d-%m-%Y %H:%M"
)
sensor_data["To Date"] = pd.to_datetime(sensor_data["To Date"], format="%d-%m-%Y %H:%M")
sensor_data["mean_time"] = sensor_data[["From Date", "To Date"]].mean(axis=1)
sensor_data["utc_time"] = sensor_data["mean_time"] - pd.Timedelta(hours=5, minutes=30)

fig, ax = plt.subplots(figsize=(15, 4))
sensor_data.plot(x="utc_time", y="PM2.5", ax=ax, label="sensor")
df.plot(x="timestamp", y="value", ax=ax, label="google")

Request at a grid.

from aqmsp_data.data import load_camx

camx = load_camx(years=2022, months=1, days=1, variables="P25")
camx
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/xarray/core/indexing.py:1443: PerformanceWarning: Slicing is producing a large chunk. To accept the large
chunk and silence this warning, set the option
    >>> with dask.config.set(**{'array.slicing.split_large_chunks': False}):
    ...     array[indexer]

To avoid creating the large chunks, set the option
    >>> with dask.config.set(**{'array.slicing.split_large_chunks': True}):
    ...     array[indexer]
  return self.array[key]
<xarray.Dataset>
Dimensions:    (time: 24, latitude: 80, longitude: 80)
Coordinates:
  * longitude  (longitude) float64 76.85 76.86 76.87 76.88 ... 77.62 77.63 77.64
  * latitude   (latitude) float64 28.2 28.21 28.22 28.23 ... 28.97 28.98 28.99
  * time       (time) datetime64[ns] 2022-01-01T00:30:00 ... 2022-01-01T23:30:00
Data variables:
    P25        (time, latitude, longitude) float32 dask.array<chunksize=(24, 80, 80), meta=np.ndarray>
Attributes: (12/34)
    CDATE:          2023126
    CTIME:          95909
    EXEC_ID:        ????????????????                                         ...
    FILEDESC:       I/O API formatted CAMx AVRG output                       ...
    FTYPE:          1
    GDNAM:          ????????????????
    ...             ...
    XCELL:          0.009999999776482582
    XCENT:          0.0
    XORIG:          76.8499984741211
    YCELL:          0.009999999776482582
    YCENT:          0.0
    YORIG:          28.200000762939453
lat_grid, lon_grid = np.meshgrid(camx.latitude, camx.longitude)
lat_lon_grid = np.vstack([lat_grid.ravel(), lon_grid.ravel()]).T
print(lat_lon_grid.shape)

session = requests.Session()
delayed_fn = dask.delayed(session.post)
responses = []
for lat, lon in tqdm(lat_lon_grid):
    payload = {
        "hours": 1,
        "pageSize": 200,
        "pageToken": "",
        "location": {"latitude": lat, "longitude": lon},
        "extraComputations": ["POLLUTANT_CONCENTRATION"],
    }

    headers = {"Content-Type": "application/json"}

    response = delayed_fn(url, json=payload, headers=headers)
    responses.append(response)

all_res = dask.compute(*responses)
(6400, 2)
100%|██████████| 6400/6400 [00:01<00:00, 5981.06it/s]
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
Cell In[7], line 22
     19     response = delayed_fn(url, json=payload, headers=headers)
     20     responses.append(response)
---> 22 all_res = dask.compute(*responses)

File ~/miniconda3/lib/python3.9/site-packages/dask/base.py:666, in compute(traverse, optimize_graph, scheduler, get, *args, **kwargs)
    663     keys.append(x.__dask_keys__())
    664     postcomputes.append(x.__dask_postcompute__())
--> 666 results = schedule(dsk, keys, **kwargs)
    667 return repack([f(r, *a) for r, (f, a) in zip(results, postcomputes)])

File ~/miniconda3/lib/python3.9/site-packages/dask/threaded.py:89, in get(dsk, keys, cache, num_workers, pool, **kwargs)
     86     elif isinstance(pool, multiprocessing.pool.Pool):
     87         pool = MultiprocessingPoolExecutor(pool)
---> 89 results = get_async(
     90     pool.submit,
     91     pool._max_workers,
     92     dsk,
     93     keys,
     94     cache=cache,
     95     get_id=_thread_get_id,
     96     pack_exception=pack_exception,
     97     **kwargs,
     98 )
    100 # Cleanup pools associated to dead threads
    101 with pools_lock:

File ~/miniconda3/lib/python3.9/site-packages/dask/local.py:500, in get_async(submit, num_workers, dsk, result, cache, get_id, rerun_exceptions_locally, pack_exception, raise_exception, callbacks, dumps, loads, chunksize, **kwargs)
    498 while state["waiting"] or state["ready"] or state["running"]:
    499     fire_tasks(chunksize)
--> 500     for key, res_info, failed in queue_get(queue).result():
    501         if failed:
    502             exc, tb = loads(res_info)

File ~/miniconda3/lib/python3.9/site-packages/dask/local.py:137, in queue_get(q)
    136 def queue_get(q):
--> 137     return q.get()

File ~/miniconda3/lib/python3.9/queue.py:171, in Queue.get(self, block, timeout)
    169 elif timeout is None:
    170     while not self._qsize():
--> 171         self.not_empty.wait()
    172 elif timeout < 0:
    173     raise ValueError("'timeout' must be a non-negative number")

File ~/miniconda3/lib/python3.9/threading.py:312, in Condition.wait(self, timeout)
    310 try:    # restore state no matter what (e.g., KeyboardInterrupt)
    311     if timeout is None:
--> 312         waiter.acquire()
    313         gotit = True
    314     else:

KeyboardInterrupt: 
dfs = []
for res, (lat, lon) in tqdm(zip(all_res, lat_lon_grid)):
    res = res.json()
    df = pd.DataFrame(columns=["timestamp", "value", "code"])
    ts = []
    codes = []
    pm25 = []
    for each in res["hoursInfo"]:
        ts.append(each["dateTime"])
        codes.append(each["pollutants"][4]["code"])
        try:
            pm25.append(each["pollutants"][4]["concentration"]["value"])
        except KeyError:
            pm25.append(np.nan)

    df["timestamp"] = ts
    df["value"] = pm25
    df["code"] = codes
    df["lat"] = lat
    df["lon"] = lon
    df["timestamp"] = pd.to_datetime(df["timestamp"])
    dfs.append(df)
master_df = pd.concat(dfs)
assert master_df["code"].nunique() == 1 and master_df["code"].unique()[0] == "pm25"

ds = master_df.set_index(["lat", "lon", "timestamp"]).to_xarray()
ds.isel(timestamp=0)["value"].plot(x="lon", y="lat", cmap="RdYlGn_r")
0it [00:00, ?it/s]6400it [00:12, 497.91it/s]

Appendix

import xarray as xr
global_date = "2023-07-26"
ds_met = xr.open_dataset(
    f'../../sarath_auto_download/data/camxmet2d.delhi.{global_date.replace("-","")}.96hours.nc'
)
ds_aq = xr.open_dataset(
    f'../../sarath_auto_download/data/camx120hr_merged_{global_date.replace("-","")}.nc'
)
ds_met
<xarray.Dataset>
Dimensions:     (TSTEP: 96, VAR: 14, DATE-TIME: 2, LAY: 1, ROW: 80, COL: 80)
Dimensions without coordinates: TSTEP, VAR, DATE-TIME, LAY, ROW, COL
Data variables: (12/15)
    TFLAG       (TSTEP, VAR, DATE-TIME) int32 ...
    TSURF_K     (TSTEP, LAY, ROW, COL) float32 ...
    SNOWEW_M    (TSTEP, LAY, ROW, COL) float32 ...
    SNOWAGE_HR  (TSTEP, LAY, ROW, COL) float32 ...
    PRATE_MMpH  (TSTEP, LAY, ROW, COL) float32 ...
    CLOUD_OD    (TSTEP, LAY, ROW, COL) float32 ...
    ...          ...
    SWSFC_WpM2  (TSTEP, LAY, ROW, COL) float32 ...
    SOLM_M3pM3  (TSTEP, LAY, ROW, COL) float32 ...
    CLDTOP_KM   (TSTEP, LAY, ROW, COL) float32 ...
    CAPE        (TSTEP, LAY, ROW, COL) float32 ...
    PBL_WRF_M   (TSTEP, LAY, ROW, COL) float32 ...
    PBL_YSU_M   (TSTEP, LAY, ROW, COL) float32 ...
Attributes: (12/33)
    IOAPI_VERSION:  $Id: @(#) ioapi library version 3.0 $                    ...
    EXEC_ID:        ????????????????                                         ...
    FTYPE:          1
    CDATE:          2023207
    CTIME:          72116
    WDATE:          2023207
    ...             ...
    VGLVLS:         [0. 0.]
    GDNAM:          ????????????????
    UPNAM:          CAMx2IOAPI      
    VAR-LIST:       TSURF_K         SNOWEW_M        SNOWAGE_HR      PRATE_MMp...
    FILEDESC:       I/O API formatted CAMx AVRG output                       ...
    HISTORY:        
plt.figure(figsize=(15, 3))
ds_met["PBL_WRF_M"].isel(LAY=0).mean(dim=["ROW", "COL"]).plot()
twin_x = plt.gca().twinx()
ds_aq["P25"].isel(LAY=0, TSTEP=range(24, 120)).mean(dim=["ROW", "COL"]).plot(
    ax=twin_x, color="r"
)
# set ylabel color as red
twin_x.set_ylabel("PM2.5", color="r")
# set yticks color as red
twin_x.tick_params(axis="y", colors="r")
twin_x.set_xlabel("Time")
Text(0.5, 0, 'Time')

ds_met
<xarray.Dataset>
Dimensions:     (TSTEP: 96, VAR: 14, DATE-TIME: 2, LAY: 1, ROW: 80, COL: 80)
Dimensions without coordinates: TSTEP, VAR, DATE-TIME, LAY, ROW, COL
Data variables: (12/15)
    TFLAG       (TSTEP, VAR, DATE-TIME) int32 ...
    TSURF_K     (TSTEP, LAY, ROW, COL) float32 ...
    SNOWEW_M    (TSTEP, LAY, ROW, COL) float32 ...
    SNOWAGE_HR  (TSTEP, LAY, ROW, COL) float32 ...
    PRATE_MMpH  (TSTEP, LAY, ROW, COL) float32 ...
    CLOUD_OD    (TSTEP, LAY, ROW, COL) float32 ...
    ...          ...
    SWSFC_WpM2  (TSTEP, LAY, ROW, COL) float32 ...
    SOLM_M3pM3  (TSTEP, LAY, ROW, COL) float32 ...
    CLDTOP_KM   (TSTEP, LAY, ROW, COL) float32 ...
    CAPE        (TSTEP, LAY, ROW, COL) float32 ...
    PBL_WRF_M   (TSTEP, LAY, ROW, COL) float32 ...
    PBL_YSU_M   (TSTEP, LAY, ROW, COL) float32 ...
Attributes: (12/33)
    IOAPI_VERSION:  $Id: @(#) ioapi library version 3.0 $                    ...
    EXEC_ID:        ????????????????                                         ...
    FTYPE:          1
    CDATE:          2023207
    CTIME:          72116
    WDATE:          2023207
    ...             ...
    VGLVLS:         [0. 0.]
    GDNAM:          ????????????????
    UPNAM:          CAMx2IOAPI      
    VAR-LIST:       TSURF_K         SNOWEW_M        SNOWAGE_HR      PRATE_MMp...
    FILEDESC:       I/O API formatted CAMx AVRG output                       ...
    HISTORY:        
np.array([1, 2, 3])[:]
array([1, 2, 3])
import numpy as np
import pandas as pd

df = pd.DataFrame(columns=["lag"], index=list(ds_met.data_vars)[1:])

for lag in range(-24, 24):
    for var in list(ds_met.data_vars)[1:]:
        if lag == 0:
            met_series = ds_met[var].isel(LAY=0).mean(dim=["ROW", "COL"]).values
            aq_series = (
                ds_aq["P25"]
                .isel(LAY=0, TSTEP=range(24, 120))
                .mean(dim=["ROW", "COL"])
                .values
            )
        elif lag > 0:
            met_series = ds_met[var].isel(LAY=0).mean(dim=["ROW", "COL"]).values[lag:]
            aq_series = (
                ds_aq["P25"]
                .isel(LAY=0, TSTEP=range(24, 120))
                .mean(dim=["ROW", "COL"])
                .values[:-lag]
            )
        else:
            met_series = ds_met[var].isel(LAY=0).mean(dim=["ROW", "COL"]).values[:lag]
            aq_series = (
                ds_aq["P25"]
                .isel(LAY=0, TSTEP=range(24, 120))
                .mean(dim=["ROW", "COL"])
                .values[-lag:]
            )
        # print(f"{var}: {np.corrcoef(met_series, aq_series)[0, 1]}")
        df.loc[var, lag] = np.corrcoef(met_series, aq_series)[0, 1]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide
  c /= stddev[:, None]
/home/patel_zeel/miniconda3/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide
  c /= stddev[None, :]
df.index.values
array(['TSURF_K', 'SNOWEW_M', 'SNOWAGE_HR', 'PRATE_MMpH', 'CLOUD_OD',
       'U10_MpS', 'V10_MpS', 'T2_K', 'SWSFC_WpM2', 'SOLM_M3pM3',
       'CLDTOP_KM', 'CAPE', 'PBL_WRF_M', 'PBL_YSU_M'], dtype=object)
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

plt.figure(figsize=(6, 3))
for var in ["TSURF_K", "T2_K", "SWSFC_WpM2", "PBL_WRF_M", "PBL_YSU_M"]:
    df.loc[var].plot(label=var)
for var in ["CLOUD_OD", "V10_MpS"]:
    df.loc[var].plot(label=var, linestyle="--")

plt.legend(bbox_to_anchor=(1, 1))
plt.ylabel("Correlation with P25 from CAMx")
plt.tight_layout()
plt.savefig("lag.pdf")

plt.rcParams["animation.html"] = "jshtml"
fig, ax = plt.subplots(figsize=(15, 4))
mappable = (
    ds_met["PBL_WRF_M"]
    .isel(TSTEP=1, LAY=0)
    .plot(
        x="COL", y="ROW", cmap="RdYlGn_r", ax=ax, vmin=0, vmax=2000, add_colorbar=False
    )
)
fig.colorbar(mappable)


def plot_it(t):
    ax.cla()
    tmp = ds_met["PBL_WRF_M"].isel(TSTEP=t, LAY=0)
    tmp.plot(
        x="COL", y="ROW", cmap="RdYlGn_r", ax=ax, vmin=0, vmax=2000, add_colorbar=False
    )
    ax.set_xlabel("Longitude")
    ax.set_ylabel("Latitude")
    ax.set_title(f"Mean PBLH: {tmp.mean().values:.2f} m")


anim = FuncAnimation(fig, plot_it, frames=range(1, 13), interval=500)
plt.close()
anim
from aqmsp_data.data import load_caaqm

caaqm = load_caaqm(years=2022, months=1, days=1, variables="PM2.5")
import pandas as pd
from glob import glob

files = glob("/home/patel_zeel/aqmsp/aqmsp_data/data/caaqm/raw_2023/*.xlsx")

df = pd.read_excel(
    files[-3],
    header=None,
)
# print(df.head(7))
station = df.iloc[6, 1]
lat = caaqm.sel(station=station).latitude.values.item()
lon = caaqm.sel(station=station).longitude.values.item()
df = df.iloc[16:, :]
# assign first row as column names
df.columns = df.iloc[0].values
# drop first row
df = df.iloc[1:, :]
print(station)
df["time"] = pd.to_datetime(df["From Date"], format="%d-%m-%Y %H:%M") + pd.Timedelta(
    minutes=30
)
df
Vivek Vihar, Delhi - DPCC
From Date To Date PM2.5 PM10 AT BP RH time
17 01-01-2023 00:00 01-01-2023 01:00 141 211 11.95 997.83 78.9 2023-01-01 00:30:00
18 01-01-2023 01:00 01-01-2023 02:00 149 210 11.85 997.47 79.1 2023-01-01 01:30:00
19 01-01-2023 02:00 01-01-2023 03:00 141 186 11.3 997.03 80.25 2023-01-01 02:30:00
20 01-01-2023 03:00 01-01-2023 04:00 138 174 10.3 996.5 83.33 2023-01-01 03:30:00
21 01-01-2023 04:00 01-01-2023 05:00 122 161 10.05 996.38 84.08 2023-01-01 04:30:00
... ... ... ... ... ... ... ... ...
5077 30-07-2023 20:00 30-07-2023 21:00 14 95.75 30.87 972.4 66.17 2023-07-30 20:30:00
5078 30-07-2023 21:00 30-07-2023 22:00 18.25 114.75 30.6 972.42 69.22 2023-07-30 21:30:00
5079 30-07-2023 22:00 30-07-2023 23:00 20.5 100.5 30.48 972.43 72 2023-07-30 22:30:00
5080 30-07-2023 23:00 31-07-2023 00:00 17.75 103 30.42 972.35 71.92 2023-07-30 23:30:00
5081 31-07-2023 00:00 31-07-2023 00:00 23 124 30.4 972.3 71.8 2023-07-31 00:30:00

5065 rows × 8 columns

def process_it(ds, date):
    if ds.TSTEP.size == 120:
        print("120")
        ds = ds.isel(LAY=0, TSTEP=range(24, 48))
    else:
        print("96")
        ds = ds.isel(LAY=0, TSTEP=range(24))
    ds1 = ds.assign(time=("TSTEP", pd.date_range(date, periods=24, freq="H")))
    lats = np.arange(80) * ds1.YCELL + ds1.YORIG
    lons = np.arange(80) * ds1.XCELL + ds1.XORIG
    ds2 = ds1.assign_coords(lat=("ROW", lats), lon=("COL", lons))
    ds3 = ds2.swap_dims({"TSTEP": "time", "ROW": "lat", "COL": "lon"})
    ds3["time"] = ds3["time"] + pd.Timedelta(hours=5, minutes=30)
    return ds3


ds_met_processed = process_it(ds_met, global_date)
ds_met_processed
96
<xarray.Dataset>
Dimensions:     (time: 24, VAR: 14, DATE-TIME: 2, lat: 80, lon: 80)
Coordinates:
  * time        (time) datetime64[ns] 2023-07-26T05:30:00 ... 2023-07-27T04:3...
  * lat         (lat) float64 28.2 28.21 28.22 28.23 ... 28.96 28.97 28.98 28.99
  * lon         (lon) float64 76.85 76.86 76.87 76.88 ... 77.62 77.63 77.64
Dimensions without coordinates: VAR, DATE-TIME
Data variables: (12/15)
    TFLAG       (time, VAR, DATE-TIME) int32 ...
    TSURF_K     (time, lat, lon) float32 ...
    SNOWEW_M    (time, lat, lon) float32 ...
    SNOWAGE_HR  (time, lat, lon) float32 ...
    PRATE_MMpH  (time, lat, lon) float32 ...
    CLOUD_OD    (time, lat, lon) float32 ...
    ...          ...
    SWSFC_WpM2  (time, lat, lon) float32 ...
    SOLM_M3pM3  (time, lat, lon) float32 ...
    CLDTOP_KM   (time, lat, lon) float32 ...
    CAPE        (time, lat, lon) float32 ...
    PBL_WRF_M   (time, lat, lon) float32 ...
    PBL_YSU_M   (time, lat, lon) float32 ...
Attributes: (12/33)
    IOAPI_VERSION:  $Id: @(#) ioapi library version 3.0 $                    ...
    EXEC_ID:        ????????????????                                         ...
    FTYPE:          1
    CDATE:          2023207
    CTIME:          72116
    WDATE:          2023207
    ...             ...
    VGLVLS:         [0. 0.]
    GDNAM:          ????????????????
    UPNAM:          CAMx2IOAPI      
    VAR-LIST:       TSURF_K         SNOWEW_M        SNOWAGE_HR      PRATE_MMp...
    FILEDESC:       I/O API formatted CAMx AVRG output                       ...
    HISTORY:        
closest_ds = ds_met_processed.sel(lat=lat, lon=lon, method="nearest")
fig, ax = plt.subplots(figsize=(15, 4))

print(lat, lon)
closest_ds["TSURF_K"].plot(ax=ax, label="TSURF_K")
closest_ds["T2_K"].plot(ax=ax, label="T2_K")
tmp_df = df.set_index("time")
# select data from global_data
tmp_df = tmp_df.loc[closest_ds["time"].values[0] : closest_ds["time"].values[-1]]
tmp_df["AT_K"] = tmp_df["AT"] + 273.15
tmp_df.plot(ax=ax, y="AT_K")
plt.legend()
# tmp_df
28.672342 77.31526