AeroViz 0.1.3__py3-none-any.whl → 0.1.3b0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of AeroViz might be problematic. Click here for more details.

Files changed (107) hide show
  1. AeroViz/__init__.py +4 -4
  2. AeroViz/dataProcess/Chemistry/__init__.py +38 -38
  3. AeroViz/dataProcess/Chemistry/_calculate.py +15 -15
  4. AeroViz/dataProcess/Chemistry/_isoropia.py +69 -68
  5. AeroViz/dataProcess/Chemistry/_mass_volume.py +158 -158
  6. AeroViz/dataProcess/Chemistry/_ocec.py +109 -109
  7. AeroViz/dataProcess/Chemistry/_partition.py +19 -18
  8. AeroViz/dataProcess/Chemistry/_teom.py +8 -11
  9. AeroViz/dataProcess/Optical/_IMPROVE.py +40 -39
  10. AeroViz/dataProcess/Optical/__init__.py +35 -35
  11. AeroViz/dataProcess/Optical/_absorption.py +35 -35
  12. AeroViz/dataProcess/Optical/_extinction.py +25 -24
  13. AeroViz/dataProcess/Optical/_mie.py +5 -6
  14. AeroViz/dataProcess/Optical/_mie_sd.py +89 -90
  15. AeroViz/dataProcess/Optical/_scattering.py +16 -16
  16. AeroViz/dataProcess/SizeDistr/__init__.py +37 -37
  17. AeroViz/dataProcess/SizeDistr/__merge.py +159 -158
  18. AeroViz/dataProcess/SizeDistr/_merge.py +155 -154
  19. AeroViz/dataProcess/SizeDistr/_merge_v1.py +162 -161
  20. AeroViz/dataProcess/SizeDistr/_merge_v2.py +153 -152
  21. AeroViz/dataProcess/SizeDistr/_merge_v3.py +326 -326
  22. AeroViz/dataProcess/SizeDistr/_merge_v4.py +272 -274
  23. AeroViz/dataProcess/SizeDistr/_size_distr.py +51 -51
  24. AeroViz/dataProcess/VOC/__init__.py +7 -7
  25. AeroViz/dataProcess/VOC/_potential_par.py +53 -55
  26. AeroViz/dataProcess/__init__.py +4 -4
  27. AeroViz/dataProcess/core/__init__.py +59 -58
  28. AeroViz/plot/__init__.py +6 -1
  29. AeroViz/plot/bar.py +126 -0
  30. AeroViz/plot/box.py +68 -0
  31. AeroViz/plot/distribution/distribution.py +421 -427
  32. AeroViz/plot/meteorology/meteorology.py +240 -292
  33. AeroViz/plot/optical/__init__.py +0 -1
  34. AeroViz/plot/optical/optical.py +230 -230
  35. AeroViz/plot/pie.py +198 -0
  36. AeroViz/plot/regression.py +210 -0
  37. AeroViz/plot/scatter.py +99 -0
  38. AeroViz/plot/templates/__init__.py +0 -3
  39. AeroViz/plot/templates/contour.py +25 -25
  40. AeroViz/plot/templates/corr_matrix.py +86 -93
  41. AeroViz/plot/templates/diurnal_pattern.py +24 -24
  42. AeroViz/plot/templates/koschmieder.py +106 -106
  43. AeroViz/plot/templates/metal_heatmap.py +34 -34
  44. AeroViz/plot/timeseries/timeseries.py +53 -60
  45. AeroViz/plot/utils/__init__.py +2 -1
  46. AeroViz/plot/utils/_color.py +57 -57
  47. AeroViz/plot/utils/_unit.py +48 -48
  48. AeroViz/plot/utils/plt_utils.py +92 -0
  49. AeroViz/plot/utils/sklearn_utils.py +49 -0
  50. AeroViz/plot/violin.py +79 -0
  51. AeroViz/process/__init__.py +15 -15
  52. AeroViz/process/core/DataProc.py +9 -9
  53. AeroViz/process/core/SizeDist.py +81 -81
  54. AeroViz/process/method/PyMieScatt_update.py +488 -488
  55. AeroViz/process/method/mie_theory.py +231 -229
  56. AeroViz/process/method/prop.py +40 -40
  57. AeroViz/process/script/AbstractDistCalc.py +103 -103
  58. AeroViz/process/script/Chemical.py +166 -166
  59. AeroViz/process/script/IMPACT.py +40 -40
  60. AeroViz/process/script/IMPROVE.py +152 -152
  61. AeroViz/process/script/Others.py +45 -45
  62. AeroViz/process/script/PSD.py +26 -26
  63. AeroViz/process/script/PSD_dry.py +69 -70
  64. AeroViz/process/script/retrieve_RI.py +50 -51
  65. AeroViz/rawDataReader/__init__.py +57 -57
  66. AeroViz/rawDataReader/core/__init__.py +328 -326
  67. AeroViz/rawDataReader/script/AE33.py +18 -18
  68. AeroViz/rawDataReader/script/AE43.py +20 -20
  69. AeroViz/rawDataReader/script/APS_3321.py +30 -30
  70. AeroViz/rawDataReader/script/Aurora.py +23 -23
  71. AeroViz/rawDataReader/script/BC1054.py +40 -40
  72. AeroViz/rawDataReader/script/EPA_vertical.py +9 -9
  73. AeroViz/rawDataReader/script/GRIMM.py +21 -21
  74. AeroViz/rawDataReader/script/IGAC_TH.py +67 -67
  75. AeroViz/rawDataReader/script/IGAC_ZM.py +59 -59
  76. AeroViz/rawDataReader/script/MA350.py +39 -39
  77. AeroViz/rawDataReader/script/NEPH.py +74 -74
  78. AeroViz/rawDataReader/script/OCEC_LCRES.py +21 -21
  79. AeroViz/rawDataReader/script/OCEC_RES.py +16 -16
  80. AeroViz/rawDataReader/script/SMPS_TH.py +25 -25
  81. AeroViz/rawDataReader/script/SMPS_aim11.py +32 -32
  82. AeroViz/rawDataReader/script/SMPS_genr.py +31 -31
  83. AeroViz/rawDataReader/script/TEOM.py +28 -28
  84. AeroViz/rawDataReader/script/Table.py +12 -12
  85. AeroViz/rawDataReader/script/VOC_TH.py +16 -16
  86. AeroViz/rawDataReader/script/VOC_ZM.py +28 -28
  87. AeroViz/rawDataReader/script/__init__.py +20 -20
  88. AeroViz/rawDataReader/utils/config.py +161 -161
  89. AeroViz/tools/database.py +65 -65
  90. AeroViz/tools/dataclassifier.py +106 -106
  91. AeroViz/tools/dataprinter.py +51 -51
  92. AeroViz/tools/datareader.py +38 -38
  93. {AeroViz-0.1.3.dist-info → AeroViz-0.1.3b0.dist-info}/METADATA +5 -4
  94. AeroViz-0.1.3b0.dist-info/RECORD +110 -0
  95. AeroViz/config/__init__.py +0 -0
  96. AeroViz/plot/improve/__init__.py +0 -1
  97. AeroViz/plot/improve/improve.py +0 -240
  98. AeroViz/plot/optical/aethalometer.py +0 -77
  99. AeroViz/plot/templates/event_evolution.py +0 -65
  100. AeroViz/plot/templates/regression.py +0 -256
  101. AeroViz/plot/templates/scatter.py +0 -130
  102. AeroViz/plot/templates/templates.py +0 -398
  103. AeroViz/plot/utils/_decorator.py +0 -74
  104. AeroViz-0.1.3.dist-info/RECORD +0 -111
  105. {AeroViz-0.1.3.dist-info → AeroViz-0.1.3b0.dist-info}/LICENSE +0 -0
  106. {AeroViz-0.1.3.dist-info → AeroViz-0.1.3b0.dist-info}/WHEEL +0 -0
  107. {AeroViz-0.1.3.dist-info → AeroViz-0.1.3b0.dist-info}/top_level.txt +0 -0
@@ -12,97 +12,90 @@ from AeroViz.plot.utils import *
12
12
  __all__ = ['corr_matrix']
13
13
 
14
14
 
15
- @set_figure(fs=8)
15
+ @set_figure
16
16
  def corr_matrix(data: pd.DataFrame,
17
- cmap: str = "RdBu",
18
- ax: Axes | None = None,
19
- **kwargs) -> tuple[Figure, Axes]:
20
- fig, ax = plt.subplots(**kwargs.get('fig_kws', {})) if ax is None else (ax.get_figure(), ax)
21
-
22
- columns = ['Extinction', 'Scattering', 'Absorption', 'PM1', 'PM25', 'PM10', 'PBLH', 'VC',
23
- 'AT', 'RH', 'WS', 'NO', 'NO2', 'NOx', 'O3', 'Benzene', 'Toluene',
24
- 'SO2', 'CO', 'THC', 'CH4', 'NMHC', 'NH3', 'HCl', 'HNO2', 'HNO3',
25
- 'Na+', 'NH4+', 'K+', 'Mg2+', 'Ca2+', 'Cl-', 'NO2-', 'NO3-', 'SO42-', ]
26
-
27
- df = data[columns]
28
-
29
- _corr = df.corr()
30
- corr = pd.melt(_corr.reset_index(),
31
- id_vars='index') # Unpivot the dataframe, so we can get pair of arrays for x and y
32
- corr.columns = ['x', 'y', 'value']
33
-
34
- p_values = _corr.apply(lambda col1: _corr.apply(lambda col2: pearsonr(col1, col2)[1]))
35
- p_values = p_values.mask(p_values > 0.05)
36
- p_values = pd.melt(p_values.reset_index(), id_vars='index').dropna()
37
- p_values.columns = ['x', 'y', 'value']
38
-
39
- # Mapping from column names to integer coordinates
40
- x_labels = [v for v in sorted(corr['x'].unique())]
41
- y_labels = [v for v in sorted(corr['y'].unique())]
42
- x_to_num = {p[1]: p[0] for p in enumerate(x_labels)}
43
- y_to_num = {p[1]: p[0] for p in enumerate(y_labels)}
44
-
45
- # Show column labels on the axes
46
- ax.set_xticks([x_to_num[v] for v in x_labels])
47
- ax.set_xticklabels(x_labels, rotation=90, horizontalalignment='center')
48
- ax.set_yticks([y_to_num[v] for v in y_labels])
49
- ax.set_yticklabels(y_labels)
50
-
51
- # ax.tick_params(axis='both', which='major', direction='out', top=True, left=True)
52
-
53
- ax.grid(False, 'major')
54
- ax.grid(True, 'minor')
55
- ax.set_xticks([t + 0.5 for t in ax.get_xticks()], minor=True)
56
- ax.set_yticks([t + 0.5 for t in ax.get_yticks()], minor=True)
57
-
58
- ax.set_xlim([-0.5, max([v for v in x_to_num.values()]) + 0.5])
59
- ax.set_ylim([-0.5, max([v for v in y_to_num.values()]) + 0.5])
60
-
61
- n_colors = 256 # Use 256 colors for the diverging color palette
62
- palette = sns.color_palette(cmap, n_colors=n_colors) # Create the palette
63
-
64
- # Range of values that will be mapped to the palette, i.e. min and max possible correlation
65
- color_min, color_max = [-1, 1]
66
-
67
- def value_to_color(val):
68
- val_position = float((val - color_min)) / (color_max - color_min)
69
- ind = int(val_position * (n_colors - 1)) # target index in the color palette
70
- return palette[ind]
71
-
72
- point = ax.scatter(
73
- x=corr['x'].map(x_to_num),
74
- y=corr['y'].map(y_to_num),
75
- s=corr['value'].abs() * 70,
76
- c=corr['value'].apply(value_to_color), # Vector of square color values, mapped to color palette
77
- marker='s',
78
- label='$R^{2}$'
79
- )
80
-
81
- axes_image = plt.cm.ScalarMappable(cmap=colormaps[cmap])
82
-
83
- cax = inset_axes(ax, width="5%",
84
- height="100%",
85
- loc='lower left',
86
- bbox_to_anchor=(1.02, 0., 1, 1),
87
- bbox_transform=ax.transAxes,
88
- borderpad=0)
89
-
90
- cbar = plt.colorbar(mappable=axes_image, cax=cax, label=r'$R^{2}$')
91
-
92
- cbar.set_ticks([0, 0.25, 0.5, 0.75, 1])
93
- cbar.set_ticklabels(np.linspace(-1, 1, 5))
94
-
95
- point2 = ax.scatter(
96
- x=p_values['x'].map(x_to_num),
97
- y=p_values['y'].map(y_to_num),
98
- s=10,
99
- marker='*',
100
- color='k',
101
- label='p < 0.05'
102
- )
103
-
104
- ax.legend(handles=[point2], labels=['p < 0.05'], bbox_to_anchor=(0.05, 1, 0.1, 0.05))
105
-
106
- plt.show()
107
-
108
- return fig, ax
17
+ cmap: str = "RdBu",
18
+ ax: Axes | None = None,
19
+ **kwargs
20
+ ) -> tuple[Figure, Axes]:
21
+ fig, ax = plt.subplots(**kwargs.get('fig_kws', {})) if ax is None else (ax.get_figure(), ax)
22
+
23
+ _corr = data.corr()
24
+ corr = pd.melt(_corr.reset_index(), id_vars='index')
25
+ corr.columns = ['x', 'y', 'value']
26
+
27
+ p_values = _corr.apply(lambda col1: _corr.apply(lambda col2: pearsonr(col1, col2)[1]))
28
+ p_values = p_values.mask(p_values > 0.05)
29
+ p_values = pd.melt(p_values.reset_index(), id_vars='index').dropna()
30
+ p_values.columns = ['x', 'y', 'value']
31
+
32
+ # Mapping from column names to integer coordinates
33
+ x_labels = [v for v in sorted(corr['x'].unique())]
34
+ y_labels = [v for v in sorted(corr['y'].unique())]
35
+ x_to_num = {p[1]: p[0] for p in enumerate(x_labels)}
36
+ y_to_num = {p[1]: p[0] for p in enumerate(y_labels)}
37
+
38
+ # Show column labels on the axes
39
+ ax.set_xticks([x_to_num[v] for v in x_labels])
40
+ ax.set_xticklabels(x_labels, rotation=90, horizontalalignment='center')
41
+ ax.set_yticks([y_to_num[v] for v in y_labels])
42
+ ax.set_yticklabels(y_labels)
43
+
44
+ # ax.tick_params(axis='both', which='major', direction='out', top=True, left=True)
45
+
46
+ ax.grid(False, 'major')
47
+ ax.grid(True, 'minor')
48
+ ax.set_xticks([t + 0.5 for t in ax.get_xticks()], minor=True)
49
+ ax.set_yticks([t + 0.5 for t in ax.get_yticks()], minor=True)
50
+
51
+ ax.set_xlim([-0.5, max([v for v in x_to_num.values()]) + 0.5])
52
+ ax.set_ylim([-0.5, max([v for v in y_to_num.values()]) + 0.5])
53
+
54
+ n_colors = 256 # Use 256 colors for the diverging color palette
55
+ palette = sns.color_palette(cmap, n_colors=n_colors) # Create the palette
56
+
57
+ # Range of values that will be mapped to the palette, i.e. min and max possible correlation
58
+ color_min, color_max = [-1, 1]
59
+
60
+ def value_to_color(val):
61
+ val_position = float((val - color_min)) / (color_max - color_min)
62
+ ind = int(val_position * (n_colors - 1)) # target index in the color palette
63
+ return palette[ind]
64
+
65
+ point = ax.scatter(
66
+ x=corr['x'].map(x_to_num),
67
+ y=corr['y'].map(y_to_num),
68
+ s=corr['value'].abs() * 70,
69
+ c=corr['value'].apply(value_to_color), # Vector of square color values, mapped to color palette
70
+ marker='s',
71
+ label='$R^{2}$'
72
+ )
73
+
74
+ axes_image = plt.cm.ScalarMappable(cmap=colormaps[cmap])
75
+
76
+ cax = inset_axes(ax, width="5%",
77
+ height="100%",
78
+ loc='lower left',
79
+ bbox_to_anchor=(1.02, 0., 1, 1),
80
+ bbox_transform=ax.transAxes,
81
+ borderpad=0)
82
+
83
+ cbar = plt.colorbar(mappable=axes_image, cax=cax, label=r'$R^{2}$')
84
+
85
+ cbar.set_ticks([0, 0.25, 0.5, 0.75, 1])
86
+ cbar.set_ticklabels(np.linspace(-1, 1, 5))
87
+
88
+ point2 = ax.scatter(
89
+ x=p_values['x'].map(x_to_num),
90
+ y=p_values['y'].map(y_to_num),
91
+ s=10,
92
+ marker='*',
93
+ color='k',
94
+ label='p < 0.05'
95
+ )
96
+
97
+ ax.legend(handles=[point2], labels=['p < 0.05'], bbox_to_anchor=(0.05, 1, 0.1, 0.05))
98
+
99
+ plt.show()
100
+
101
+ return fig, ax
@@ -8,35 +8,35 @@ from AeroViz.plot.utils import *
8
8
  __all__ = ['diurnal_pattern']
9
9
 
10
10
 
11
- @set_figure(figsize=(4, 4), fs=8)
11
+ @set_figure
12
12
  def diurnal_pattern(data_set: pd.DataFrame,
13
- data_std: pd.DataFrame,
14
- y: str | list[str],
15
- std_area=0.5,
16
- ax: Axes | None = None,
17
- **kwargs) -> tuple[Figure, Axes]:
18
- fig, ax = plt.subplots(**kwargs.get('fig_kws', {})) if ax is None else (ax.get_figure(), ax)
13
+ data_std: pd.DataFrame,
14
+ y: str | list[str],
15
+ std_area=0.5,
16
+ ax: Axes | None = None,
17
+ **kwargs) -> tuple[Figure, Axes]:
18
+ fig, ax = plt.subplots(**kwargs.get('fig_kws', {})) if ax is None else (ax.get_figure(), ax)
19
19
 
20
- Hour = range(0, 24)
20
+ Hour = range(0, 24)
21
21
 
22
- mean = data_set[y]
23
- std = data_std[y] * std_area
22
+ mean = data_set[y]
23
+ std = data_std[y] * std_area
24
24
 
25
- # Plot Diurnal pattern
26
- ax.plot(Hour, mean, 'blue')
27
- ax.fill_between(Hour, y1=mean + std, y2=mean - std, alpha=0.5, color='blue', edgecolor=None)
25
+ # Plot Diurnal pattern
26
+ ax.plot(Hour, mean, 'blue')
27
+ ax.fill_between(Hour, y1=mean + std, y2=mean - std, alpha=0.5, color='blue', edgecolor=None)
28
28
 
29
- ax.set(xlabel=kwargs.get('xlabel', 'Hours'),
30
- ylabel=kwargs.get('ylabel', Unit(y)),
31
- xlim=kwargs.get('xlim', (0, 23)),
32
- ylim=kwargs.get('ylim', (None, None)),
33
- xticks=kwargs.get('xticks', [0, 4, 8, 12, 16, 20]))
29
+ ax.set(xlabel=kwargs.get('xlabel', 'Hours'),
30
+ ylabel=kwargs.get('ylabel', Unit(y)),
31
+ xlim=kwargs.get('xlim', (0, 23)),
32
+ ylim=kwargs.get('ylim', (None, None)),
33
+ xticks=kwargs.get('xticks', [0, 4, 8, 12, 16, 20]))
34
34
 
35
- ax.tick_params(axis='both', which='major')
36
- ax.tick_params(axis='x', which='minor')
37
- ax.xaxis.set_minor_locator(AutoMinorLocator())
38
- ax.ticklabel_format(axis='y', style='sci', scilimits=(-2, 3), useMathText=True)
35
+ ax.tick_params(axis='both', which='major')
36
+ ax.tick_params(axis='x', which='minor')
37
+ ax.xaxis.set_minor_locator(AutoMinorLocator())
38
+ ax.ticklabel_format(axis='y', style='sci', scilimits=(-2, 3), useMathText=True)
39
39
 
40
- plt.show()
40
+ plt.show()
41
41
 
42
- return fig, ax
42
+ return fig, ax
@@ -13,144 +13,144 @@ __all__ = ['koschmieder']
13
13
 
14
14
  @set_figure(fs=12)
15
15
  def koschmieder(df: pd.DataFrame,
16
- y: Literal['Vis_Naked', 'Vis_LPV'],
17
- function: Literal['log', 'reciprocal'] = 'log',
18
- ax: Axes | None = None,
19
- **kwargs) -> tuple[Figure, Axes]:
20
- # x = Visibility, y = Extinction, log-log fit!!
21
- def _log_fit(x, y, func=lambda x, a: -x + a):
22
- x_log = np.log(x)
23
- y_log = np.log(y)
24
-
25
- popt, pcov = curve_fit(func, x_log, y_log)
16
+ y: Literal['Vis_Naked', 'Vis_LPV'],
17
+ function: Literal['log', 'reciprocal'] = 'log',
18
+ ax: Axes | None = None,
19
+ **kwargs) -> tuple[Figure, Axes]:
20
+ # x = Visibility, y = Extinction, log-log fit!!
21
+ def _log_fit(x, y, func=lambda x, a: -x + a):
22
+ x_log = np.log(x)
23
+ y_log = np.log(y)
24
+
25
+ popt, pcov = curve_fit(func, x_log, y_log)
26
26
 
27
- residuals = y_log - func(x_log, *popt)
28
- ss_res = np.sum(residuals ** 2)
29
- ss_total = np.sum((y_log - np.mean(y_log)) ** 2)
30
- r_squared = 1 - (ss_res / ss_total)
31
- print(f'Const_Log = {popt[0].round(3)}')
32
- print(f'Const = {np.exp(popt)[0].round(3)}')
33
- print(f'R^2 = {r_squared.round(3)}')
34
- return np.exp(popt)[0], pcov
35
-
36
- def _reciprocal_fit(x, y, func=lambda x, a, b: a / (x ** b)):
37
- popt, pcov = curve_fit(func, x, y)
27
+ residuals = y_log - func(x_log, *popt)
28
+ ss_res = np.sum(residuals ** 2)
29
+ ss_total = np.sum((y_log - np.mean(y_log)) ** 2)
30
+ r_squared = 1 - (ss_res / ss_total)
31
+ print(f'Const_Log = {popt[0].round(3)}')
32
+ print(f'Const = {np.exp(popt)[0].round(3)}')
33
+ print(f'R^2 = {r_squared.round(3)}')
34
+ return np.exp(popt)[0], pcov
35
+
36
+ def _reciprocal_fit(x, y, func=lambda x, a, b: a / (x ** b)):
37
+ popt, pcov = curve_fit(func, x, y)
38
38
 
39
- residuals = y - func(x, *popt)
40
- ss_res = np.sum(residuals ** 2)
41
- ss_total = np.sum((y - np.mean(y)) ** 2)
42
- r_squared = 1 - (ss_res / ss_total)
43
- print(f'Const = {popt.round(3)}')
44
- print(f' R^2 = {r_squared.round(3)}')
45
- return popt, pcov
39
+ residuals = y - func(x, *popt)
40
+ ss_res = np.sum(residuals ** 2)
41
+ ss_total = np.sum((y - np.mean(y)) ** 2)
42
+ r_squared = 1 - (ss_res / ss_total)
43
+ print(f'Const = {popt.round(3)}')
44
+ print(f' R^2 = {r_squared.round(3)}')
45
+ return popt, pcov
46
46
 
47
- fig, ax = plt.subplots(**kwargs.get('fig_kws', {})) if ax is None else (ax.get_figure(), ax)
47
+ fig, ax = plt.subplots(**kwargs.get('fig_kws', {})) if ax is None else (ax.get_figure(), ax)
48
48
 
49
- _df1 = df[['Extinction', 'ExtinctionByGas', y]].dropna().copy()
50
- _df2 = df[['total_ext_dry', 'ExtinctionByGas', y]].dropna().copy()
49
+ _df1 = df[['Extinction', 'ExtinctionByGas', y]].dropna().copy()
50
+ _df2 = df[['total_ext_dry', 'ExtinctionByGas', y]].dropna().copy()
51
51
 
52
- x_data1 = _df1[y]
53
- y_data1 = _df1['Extinction'] + _df1['ExtinctionByGas']
52
+ x_data1 = _df1[y]
53
+ y_data1 = _df1['Extinction'] + _df1['ExtinctionByGas']
54
54
 
55
- x_data2 = _df2[y]
56
- y_data2 = _df2['total_ext_dry'] + _df2['ExtinctionByGas']
55
+ x_data2 = _df2[y]
56
+ y_data2 = _df2['total_ext_dry'] + _df2['ExtinctionByGas']
57
57
 
58
- para_coeff = []
59
- boxcolors = ['#3f83bf', '#a5bf6b']
58
+ para_coeff = []
59
+ boxcolors = ['#3f83bf', '#a5bf6b']
60
60
 
61
- for i, (df_, x_data, y_data) in enumerate(zip([_df1, _df2], [x_data1, x_data2], [y_data1, y_data2])):
62
- df_['Total_Ext'] = y_data
61
+ for i, (df_, x_data, y_data) in enumerate(zip([_df1, _df2], [x_data1, x_data2], [y_data1, y_data2])):
62
+ df_['Total_Ext'] = y_data
63
63
 
64
- if y == 'Vis_Naked':
65
- df_grp = df_.groupby(f'{y}')
64
+ if y == 'Vis_Naked':
65
+ df_grp = df_.groupby(f'{y}')
66
66
 
67
- vals, median_vals, vis = [], [], []
68
- for j, (name, subdf) in enumerate(df_grp):
69
- if len(subdf['Total_Ext'].dropna()) > 20:
70
- vis.append('{:.0f}'.format(name))
71
- vals.append(subdf['Total_Ext'].dropna().values)
72
- median_vals.append(subdf['Total_Ext'].dropna().median())
67
+ vals, median_vals, vis = [], [], []
68
+ for j, (name, subdf) in enumerate(df_grp):
69
+ if len(subdf['Total_Ext'].dropna()) > 20:
70
+ vis.append('{:.0f}'.format(name))
71
+ vals.append(subdf['Total_Ext'].dropna().values)
72
+ median_vals.append(subdf['Total_Ext'].dropna().median())
73
73
 
74
- plt.boxplot(vals, labels=vis, positions=np.array(vis, dtype='int'), widths=0.4,
75
- showfliers=False, showmeans=True, meanline=False, patch_artist=True,
76
- boxprops=dict(facecolor=boxcolors[i], alpha=.7),
77
- meanprops=dict(marker='o', markerfacecolor='white', markeredgecolor='k', markersize=4),
78
- medianprops=dict(color='#000000', ls='-'))
74
+ plt.boxplot(vals, labels=vis, positions=np.array(vis, dtype='int'), widths=0.4,
75
+ showfliers=False, showmeans=True, meanline=False, patch_artist=True,
76
+ boxprops=dict(facecolor=boxcolors[i], alpha=.7),
77
+ meanprops=dict(marker='o', markerfacecolor='white', markeredgecolor='k', markersize=4),
78
+ medianprops=dict(color='#000000', ls='-'))
79
79
 
80
- plt.scatter(x_data, y_data, marker='.', s=10, facecolor='white', edgecolor=boxcolors[i], alpha=0.1)
80
+ plt.scatter(x_data, y_data, marker='.', s=10, facecolor='white', edgecolor=boxcolors[i], alpha=0.1)
81
81
 
82
- if y == 'Vis_LPV':
83
- bins = np.linspace(0, 70, 36)
84
- wid = (bins + (bins[1] - bins[0]) / 2)[0:-1]
82
+ if y == 'Vis_LPV':
83
+ bins = np.linspace(0, 70, 36)
84
+ wid = (bins + (bins[1] - bins[0]) / 2)[0:-1]
85
85
 
86
- df_[f'{x_data.name}' + '_bins'] = pd.cut(x=x_data, bins=bins, labels=wid)
86
+ df_[f'{x_data.name}' + '_bins'] = pd.cut(x=x_data, bins=bins, labels=wid)
87
87
 
88
- grouped = df_.groupby(f'{x_data.name}' + '_bins', observed=False)
88
+ grouped = df_.groupby(f'{x_data.name}' + '_bins', observed=False)
89
89
 
90
- vals, median_vals, vis = [], [], []
91
- for j, (name, subdf) in enumerate(grouped):
92
- if len(subdf['Total_Ext'].dropna()) > 20:
93
- vis.append('{:.1f}'.format(name))
94
- vals.append(subdf['Total_Ext'].dropna().values)
95
- median_vals.append(subdf['Total_Ext'].dropna().mean())
90
+ vals, median_vals, vis = [], [], []
91
+ for j, (name, subdf) in enumerate(grouped):
92
+ if len(subdf['Total_Ext'].dropna()) > 20:
93
+ vis.append('{:.1f}'.format(name))
94
+ vals.append(subdf['Total_Ext'].dropna().values)
95
+ median_vals.append(subdf['Total_Ext'].dropna().mean())
96
96
 
97
- plt.boxplot(vals, labels=vis, positions=np.array(vis, dtype='float'), widths=(bins[1] - bins[0]) / 2.5,
98
- showfliers=False, showmeans=True, meanline=False, patch_artist=True,
99
- boxprops=dict(facecolor=boxcolors[i], alpha=.7),
100
- meanprops=dict(marker='o', markerfacecolor='white', markeredgecolor='k', markersize=4),
101
- medianprops=dict(color='#000000', ls='-'))
97
+ plt.boxplot(vals, labels=vis, positions=np.array(vis, dtype='float'), widths=(bins[1] - bins[0]) / 2.5,
98
+ showfliers=False, showmeans=True, meanline=False, patch_artist=True,
99
+ boxprops=dict(facecolor=boxcolors[i], alpha=.7),
100
+ meanprops=dict(marker='o', markerfacecolor='white', markeredgecolor='k', markersize=4),
101
+ medianprops=dict(color='#000000', ls='-'))
102
102
 
103
- plt.scatter(x_data, y_data, marker='.', s=10, facecolor='white', edgecolor=boxcolors[i], alpha=0.1)
103
+ plt.scatter(x_data, y_data, marker='.', s=10, facecolor='white', edgecolor=boxcolors[i], alpha=0.1)
104
104
 
105
- # fit curve
106
- _x = np.array(vis, dtype='float')
107
- _y = np.array(median_vals, dtype='float')
105
+ # fit curve
106
+ _x = np.array(vis, dtype='float')
107
+ _y = np.array(median_vals, dtype='float')
108
108
 
109
- if function == 'log':
110
- func = lambda x, a: a / x
111
- coeff, pcov = _log_fit(_x, _y)
109
+ if function == 'log':
110
+ func = lambda x, a: a / x
111
+ coeff, pcov = _log_fit(_x, _y)
112
112
 
113
- else:
114
- func = lambda x, a, b: a / (x ** b)
115
- coeff, pcov = _reciprocal_fit(_x, _y)
113
+ else:
114
+ func = lambda x, a, b: a / (x ** b)
115
+ coeff, pcov = _reciprocal_fit(_x, _y)
116
116
 
117
- para_coeff.append(coeff)
117
+ para_coeff.append(coeff)
118
118
 
119
- # Plot lines (ref & Measurement)
120
- x_fit = np.linspace(0.1, 70, 1000)
119
+ # Plot lines (ref & Measurement)
120
+ x_fit = np.linspace(0.1, 70, 1000)
121
121
 
122
- if function == 'log':
123
- line1, = ax.plot(x_fit, func(x_fit, para_coeff[0]), c='b', lw=3)
124
- line2, = ax.plot(x_fit, func(x_fit, para_coeff[1]), c='g', lw=3)
122
+ if function == 'log':
123
+ line1, = ax.plot(x_fit, func(x_fit, para_coeff[0]), c='b', lw=3)
124
+ line2, = ax.plot(x_fit, func(x_fit, para_coeff[1]), c='g', lw=3)
125
125
 
126
- labels = ['Vis (km) = ' + f'{round(para_coeff[0])}' + ' / Ext (Dry Extinction)',
127
- 'Vis (km) = ' + f'{round(para_coeff[1])}' + ' / Ext (Amb Extinction)']
126
+ labels = ['Vis (km) = ' + f'{round(para_coeff[0])}' + ' / Ext (Dry Extinction)',
127
+ 'Vis (km) = ' + f'{round(para_coeff[1])}' + ' / Ext (Amb Extinction)']
128
128
 
129
- else:
130
- x_fit = np.linspace(0.1, 70, 1000)
131
- line1, = ax.plot(x_fit, func(x_fit, *para_coeff[0]), c='b', lw=3)
132
- line2, = ax.plot(x_fit, func(x_fit, *para_coeff[1]), c='g', lw=3)
129
+ else:
130
+ x_fit = np.linspace(0.1, 70, 1000)
131
+ line1, = ax.plot(x_fit, func(x_fit, *para_coeff[0]), c='b', lw=3)
132
+ line2, = ax.plot(x_fit, func(x_fit, *para_coeff[1]), c='g', lw=3)
133
133
 
134
- labels = [f'Ext = ' + '{:.0f} / Vis ^ {:.3f}'.format(*para_coeff[0]) + ' (Dry Extinction)',
135
- f'Ext = ' + '{:.0f} / Vis ^ {:.3f}'.format(*para_coeff[1]) + ' (Amb Extinction)']
134
+ labels = [f'Ext = ' + '{:.0f} / Vis ^ {:.3f}'.format(*para_coeff[0]) + ' (Dry Extinction)',
135
+ f'Ext = ' + '{:.0f} / Vis ^ {:.3f}'.format(*para_coeff[1]) + ' (Amb Extinction)']
136
136
 
137
- plt.legend(handles=[line1, line2], labels=labels, loc='upper right', prop=dict(size=10, weight='bold'),
138
- bbox_to_anchor=(0.99, 0.99))
137
+ plt.legend(handles=[line1, line2], labels=labels, loc='upper right', prop=dict(size=10, weight='bold'),
138
+ bbox_to_anchor=(0.99, 0.99))
139
139
 
140
- plt.xticks(ticks=np.array(range(0, 51, 5)), labels=np.array(range(0, 51, 5)))
141
- plt.xlim(0, 50)
142
- plt.ylim(0, 700)
143
- plt.title(r'$\bf Koschmieder\ relationship$')
144
- plt.xlabel(f'{y} (km)')
145
- plt.ylabel(r'$\bf Extinction\ coefficient\ (1/Mm)$')
140
+ plt.xticks(ticks=np.array(range(0, 51, 5)), labels=np.array(range(0, 51, 5)))
141
+ plt.xlim(0, 50)
142
+ plt.ylim(0, 700)
143
+ plt.title(r'$\bf Koschmieder\ relationship$')
144
+ plt.xlabel(f'{y} (km)')
145
+ plt.ylabel(r'$\bf Extinction\ coefficient\ (1/Mm)$')
146
146
 
147
- plt.show()
147
+ plt.show()
148
148
 
149
- return fig, ax
149
+ return fig, ax
150
150
 
151
151
 
152
152
  if __name__ == '__main__':
153
- from AeroViz.tools import DataBase
153
+ from AeroViz.tools import DataBase
154
154
 
155
- koschmieder(DataBase(), 'Vis_LPV', 'log')
156
- # koschmieder(DataBase, 'Vis_Naked', 'reciprocal')
155
+ koschmieder(DataBase(), 'Vis_LPV', 'log')
156
+ # koschmieder(DataBase, 'Vis_Naked', 'reciprocal')
@@ -9,49 +9,49 @@ from AeroViz.plot.utils import *
9
9
 
10
10
 
11
11
  def process_data(df):
12
- # detected_limit = 0.0001
13
- df = df.where(df >= 0.0001, np.nan)
14
- # Normalize the data
15
- df = DataFrame(StandardScaler().fit_transform(df), index=df.index, columns=df.columns)
16
- # Remove outliers
17
- df = df[(np.abs(df) < 6)]
18
- # Interpolate the missing values
19
- df = df.interpolate(method='linear')
20
- # Smooth the data
21
- df = df.rolling(window=3, min_periods=1).mean()
12
+ # detected_limit = 0.0001
13
+ df = df.where(df >= 0.0001, np.nan)
14
+ # Normalize the data
15
+ df = DataFrame(StandardScaler().fit_transform(df), index=df.index, columns=df.columns)
16
+ # Remove outliers
17
+ df = df[(np.abs(df) < 6)]
18
+ # Interpolate the missing values
19
+ df = df.interpolate(method='linear')
20
+ # Smooth the data
21
+ df = df.rolling(window=3, min_periods=1).mean()
22
22
 
23
- return df
23
+ return df
24
24
 
25
25
 
26
26
  @set_figure(figsize=(12, 3), fs=6)
27
27
  def metal_heatmaps(df, major_freq='24h', minor_freq='12h', ax: Axes | None = None, title=None, **kwargs
28
- ) -> tuple[Figure, Axes]:
29
- items = ['Al', 'Zr', 'Si', 'Ca', 'Ti', 'Mn', 'Fe', 'V', 'Cl', 'K',
30
- 'Sr', 'Ba', 'Bi', 'Pd', 'Sn', 'Cr', 'W', 'Cu', 'Zn',
31
- 'As', 'Co', 'Se', 'Br', 'Cd', 'Sb', 'In', 'Pb', 'Ni']
28
+ ) -> tuple[Figure, Axes]:
29
+ items = ['Al', 'Zr', 'Si', 'Ca', 'Ti', 'Mn', 'Fe', 'V', 'Cl', 'K',
30
+ 'Sr', 'Ba', 'Bi', 'Pd', 'Sn', 'Cr', 'W', 'Cu', 'Zn',
31
+ 'As', 'Co', 'Se', 'Br', 'Cd', 'Sb', 'In', 'Pb', 'Ni']
32
32
 
33
- df = df[items]
33
+ df = df[items]
34
34
 
35
- fig, ax = plt.subplots(**kwargs.get('fig_kws', {})) if ax is None else (ax.get_figure(), ax)
35
+ fig, ax = plt.subplots(**kwargs.get('fig_kws', {})) if ax is None else (ax.get_figure(), ax)
36
36
 
37
- sns.heatmap(df.T, vmax=3, cmap="jet", xticklabels=False, yticklabels=True,
38
- cbar_kws={'label': 'Z score'})
39
- ax.grid(color='gray', linestyle='-', linewidth=0.3)
40
- # Set x-tick positions and labels
41
- major_tick = date_range(start=df.index[0], end=df.index[-1], freq=major_freq)
42
- minor_tick = date_range(start=df.index[0], end=df.index[-1], freq=minor_freq)
37
+ sns.heatmap(df.T, vmax=3, cmap="jet", xticklabels=False, yticklabels=True,
38
+ cbar_kws={'label': 'Z score'})
39
+ ax.grid(color='gray', linestyle='-', linewidth=0.3)
40
+ # Set x-tick positions and labels
41
+ major_tick = date_range(start=df.index[0], end=df.index[-1], freq=major_freq)
42
+ minor_tick = date_range(start=df.index[0], end=df.index[-1], freq=minor_freq)
43
43
 
44
- # Set the major and minor ticks
45
- ax.set_xticks(ticks=[df.index.get_loc(t) for t in major_tick])
46
- ax.set_xticks(ticks=[df.index.get_loc(t) for t in minor_tick], minor=True)
47
- ax.set_xticklabels(major_tick.strftime('%F'))
48
- ax.tick_params(axis='y', rotation=0)
44
+ # Set the major and minor ticks
45
+ ax.set_xticks(ticks=[df.index.get_loc(t) for t in major_tick])
46
+ ax.set_xticks(ticks=[df.index.get_loc(t) for t in minor_tick], minor=True)
47
+ ax.set_xticklabels(major_tick.strftime('%F'))
48
+ ax.tick_params(axis='y', rotation=0)
49
49
 
50
- ax.set_title(f"{title}", fontsize=10)
51
- ax.set(xlabel='',
52
- ylabel='',
53
- )
50
+ ax.set_title(f"{title}", fontsize=10)
51
+ ax.set(xlabel='',
52
+ ylabel='',
53
+ )
54
54
 
55
- plt.show()
55
+ plt.show()
56
56
 
57
- return fig, ax
57
+ return fig, ax