0

just can't overcome this issue

here is a small data sample to run the code: https://www.dropbox.com/s/jbba3ckwojb8gpq/BOZ_LfU_CAPdef5_sample.nc?dl=0 https://www.dropbox.com/s/57gqf5znsmc37i1/im_sample.csv?dl=0

i have the following code:

import numpy as np
import xarray as xa
import matplotlib.pyplot as plt
import pandas as pd
from matplotlib.colors import ListedColormap

local_path = '/dir'
im = pd.read_csv(local_path + 'im_sample.csv')
im['time'] = pd.to_datetime(im['time'].astype(str), format='%Y-%m-%d %H:%M:%S', errors='coerce')
im = im.set_index('time')

cap = xa.open_dataset(local_path + 'BOZ_LfU_CAPdef5_sample.nc')


#separate inversion data into different groups and attach them to a pandas series

cap1 = cap.where(cap.number == 1, drop=True)
capB = cap1.where(cap1.kind == 'B', drop=True).time

capA = cap.where(cap.kind.sel(layer=0) == 'A', drop=True).time

capplus = cap.where(cap.number >1, drop=True)
capmix = capplus.where(capplus.kind.sel(layer=0) == 'B', drop=True).time

capN = cap.where(cap.kind.sel(layer=0) == 'nan', drop=True).time

s = pd.Series([1]*len(cap.time.values), cap.time.values)

for i in cap.time.values:
    if i in capN.values:
        s[i] = 0 
    elif i in capB.values:
        s[i] = .25
    elif i in capA.values:
        s[i] = .5
    else:
        s[i] = .75

#get two different plots.. one timeseries for the immission data and one for the additional inversion data

cmap = ListedColormap(['black', 'red', 'green', 'yellow', 'white'])
colors = ['#7678ed', '#ee4266', '#ffd23f', '#808080']
im_dict = {'imtype': ['NO2','NOx', 'PM10'], 'imlabel': ['NO$_2$', 'NO$_x$', 'PM$_{10}$']}
imnames = pd.DataFrame(data=im_dict)

s = s.reindex(im['Cla_'+imnames.imtype[0]].index)

fig, (ax0, ax1) = plt.subplots(2, 1, figsize=(20,12), sharex=True, gridspec_kw={'height_ratios': [1,4], 'hspace':0})
fig.suptitle('Time Series for NO2 data', y=0.92, fontsize=15)

p = ax0.pcolor([np.arange(len(s)), s.values], cmap=cmap,vmin = 0, vmax = 1)
ax0.set_ylim(1,2)
ax0.set_yticks([])

ax1.plot(im['Cla_'+imnames.imtype[0]], linewidth=1.5, label='Claudia street', color=colors[0])
ax1.plot(im['Had_'+imnames.imtype[0]], linewidth=1.5, label='Hadrach street', color=colors[1])
ax1.plot(im['Lei_'+imnames.imtype[0]], linewidth=1.5, label='Leim Street', color=colors[2])
    
ax1.set_ylabel(imnames.imlabel[0] +' ($\mu$g/m$^3$)')
ax1.tick_params(axis='both', which='major', labelsize=13)

so there are a few problems. first the result gives me a plot beginning from 1970 to 2016 which doesn't make any sense at all. so immission graph is completely squeezed on the right and inversion data squeezed on the left side of their axes. i haven't figured out how to successfully implement a daterange data for the xaxis of the inversion plot (if that is the actually problem as i suppose right now).

if you have any additional improvement tips or ideas how to graphically represent the inversion type data .. i would be very happy to hear about them (:

the main goal is to illustrate the coherence between different types of inversions and the amount of pollutants in the surface-near air. so to every immission data point (every 30 minutes) i have information about whether there is inversion and which one. inversion data points are actually every 10 minutes but i thought about fitting them to the immission dataframe so both have the same size.

joeseph
  • 1
  • 1
  • ps: i have created two samples.. don't know how to provide them properly. so if they are needed pls tell me how i should upload them. – joeseph Nov 13 '22 at 16:28
  • Please see if [this](https://stackoverflow.com/a/37738851/7789963) helps. Please consider posting [a minimum reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – medium-dimensional Nov 13 '22 at 19:09
  • 1
    when at all possible, don't provide sample data files; instead, generate the objects you need from code. also, to get our help, please limit your post to a single question. the time axis starting from 1970 seems like a good place to start. (hint: 1970 is the value 0 in datetimes, so you may just have small/zero values in your time dim). please include as little code as possible to *fully reproduce* the issue, then show us the error message or upload the plot you get as a result. pasting the result of `print(ds)` would also be really helpful for showing us the structure of your data. thanks! – Michael Delgado Nov 13 '22 at 21:08
  • i updated with sample data files. since the objects are rather complex (i would suggest) i don't really know how to generate them from code. but i will attach some pictures of the figure and the data structure as well. (got some complaints last time i did) EDIT: it seems like i am not allowed to do so (great) – joeseph Nov 13 '22 at 22:11

0 Answers0