ebas-plot 0.2.1__py3-none-any.whl → 0.2.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ebas-plot
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: Plotting utilities for EBAS netCDF datasets.
5
5
  Author-email: Lise Eder Murberg <lemu@nilu.no>, Marthe Brevig <mbre@nilu.no>, Jonathan Elias Holme <jhol@nilu.no>
6
6
  License-Expression: AGPL-3.0-or-later
@@ -0,0 +1,7 @@
1
+ ebas_plot.py,sha256=U4fO2YSyIBPui4xNo1lCYCKPG7JpHaRsCpsEfmEPU-Q,43588
2
+ ebas_plot-0.2.3.dist-info/licenses/LICENSE,sha256=7ZpO8LOz0uwP0ZXf1VdifRWnVKK6wPAICJ9ULsrndDs,840
3
+ ebas_plot-0.2.3.dist-info/METADATA,sha256=XbPKpLzAVzsIkIVTcBKdniI7HMcuRU2jbiZDLKwMcOc,3758
4
+ ebas_plot-0.2.3.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
5
+ ebas_plot-0.2.3.dist-info/entry_points.txt,sha256=pOXlW0kxym2YdjkQw2HxLtHgXoaLOgQBzxZ78uVovn0,45
6
+ ebas_plot-0.2.3.dist-info/top_level.txt,sha256=EcUPwQUC64wFbj_S3eIgWmItisCrkva69sjFY-5ywd4,10
7
+ ebas_plot-0.2.3.dist-info/RECORD,,
ebas_plot.py CHANGED
@@ -8,7 +8,7 @@ import requests
8
8
  from netCDF4 import date2num, num2date
9
9
  import pandas as pd
10
10
 
11
- __version__ = "0.2.1"
11
+ __version__ = "0.2.3"
12
12
 
13
13
 
14
14
  class DatasetAccessError(Exception):
@@ -212,7 +212,9 @@ def _open_dataset(url: str, token: str | None) -> xr.Dataset:
212
212
  if token:
213
213
  session = requests.Session()
214
214
  session.headers["Authorization"] = f"Bearer {token}"
215
- return xr.open_dataset(opendap_url, engine="pydap", session=session)
215
+ # dap2:// pins the protocol (silences pydap's fallback warning); pydap maps it back to https.
216
+ dap_url = opendap_url.replace("https://", "dap2://", 1)
217
+ return xr.open_dataset(dap_url, engine="pydap", session=session)
216
218
 
217
219
  try:
218
220
  return xr.open_dataset(opendap_url, engine="netcdf4")
@@ -445,6 +447,38 @@ def _group_vars_by_physical_quantity(ds: xr.Dataset, plot_vars: list[str]) -> li
445
447
  return list(groups.items())
446
448
 
447
449
 
450
+ def _fill_pnsd_time_gaps(
451
+ x_time: np.ndarray, z: np.ndarray, time_step: pd.Timedelta,
452
+ ) -> tuple[np.ndarray, np.ndarray]:
453
+ """Insert all-NaN columns for absent time steps without moving observations."""
454
+ if len(x_time) < 2 or pd.isna(time_step) or time_step <= pd.Timedelta(0):
455
+ return x_time, z
456
+ timestamps = pd.DatetimeIndex(x_time).as_unit("ns")
457
+ intervals = np.diff(timestamps.asi8)
458
+ gap_indices = np.flatnonzero(intervals > 1.5 * time_step.value) + 1
459
+ if not len(gap_indices):
460
+ return x_time, z
461
+ missing_counts = (intervals[gap_indices - 1] - (time_step / 2).value) // time_step.value
462
+ cumulative_missing = np.cumsum(missing_counts)
463
+ total_missing = int(cumulative_missing[-1])
464
+ offsets = np.arange(total_missing) - np.repeat(
465
+ cumulative_missing - missing_counts, missing_counts
466
+ )
467
+ shifts = np.zeros(len(x_time), dtype=np.int64)
468
+ shifts[gap_indices] = missing_counts
469
+ observed_positions = np.arange(len(x_time)) + np.cumsum(shifts)
470
+ missing_positions = np.repeat(observed_positions[gap_indices - 1] + 1, missing_counts) + offsets
471
+ filled_times = np.empty(len(x_time) + total_missing, dtype="datetime64[ns]")
472
+ filled_times[observed_positions] = timestamps.to_numpy()
473
+ filled_times[missing_positions] = (
474
+ np.repeat(timestamps.asi8[gap_indices - 1], missing_counts)
475
+ + (offsets + 1) * time_step.value
476
+ ).astype("datetime64[ns]")
477
+ filled_values = np.full((z.shape[0], len(filled_times)), np.nan, dtype=z.dtype)
478
+ filled_values[:, observed_positions] = z
479
+ return filled_times, filled_values
480
+
481
+
448
482
  def plot_pnsd(ds: xr.Dataset) -> go.Figure:
449
483
  """Plot particle number size distribution (PNSD) as a heatmap."""
450
484
  var_name = _pnsd_var(ds)
@@ -465,6 +499,9 @@ def plot_pnsd(ds: xr.Dataset) -> go.Figure:
465
499
  z = np.log10(z_raw)
466
500
  x_time = get_plot_time(ds)
467
501
  y_d = ds["d_D"].values
502
+ if not np.issubdtype(np.asarray(x_time).dtype, np.number):
503
+ time_step = pd.Series(pd.to_datetime(x_time)).diff().median()
504
+ x_time, z = _fill_pnsd_time_gaps(x_time, z, _sampling_resolution(ds, time_step))
468
505
 
469
506
  # Fixed logarithmic scale from -1.0 to 5.0 with 0.2 interval; APS instruments cap lower (max 3.0).
470
507
  log_min = -1.0
@@ -487,6 +524,7 @@ def plot_pnsd(ds: xr.Dataset) -> go.Figure:
487
524
  zmin=log_min,
488
525
  zmax=log_max,
489
526
  zsmooth='best',
527
+ connectgaps=False,
490
528
  colorscale=plotly_discrete_colorscale,
491
529
  showscale=True,
492
530
  colorbar=dict(
@@ -1,7 +0,0 @@
1
- ebas_plot.py,sha256=6F0coXZ2XHFuPj8kCUTGZ5gGyZGOMflcFmpfRJQF_yI,41573
2
- ebas_plot-0.2.1.dist-info/licenses/LICENSE,sha256=7ZpO8LOz0uwP0ZXf1VdifRWnVKK6wPAICJ9ULsrndDs,840
3
- ebas_plot-0.2.1.dist-info/METADATA,sha256=WTwbaDW_vUZhKiaJKRAuUYFfyMOl5GlVba5OtEvM7VI,3758
4
- ebas_plot-0.2.1.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
5
- ebas_plot-0.2.1.dist-info/entry_points.txt,sha256=pOXlW0kxym2YdjkQw2HxLtHgXoaLOgQBzxZ78uVovn0,45
6
- ebas_plot-0.2.1.dist-info/top_level.txt,sha256=EcUPwQUC64wFbj_S3eIgWmItisCrkva69sjFY-5ywd4,10
7
- ebas_plot-0.2.1.dist-info/RECORD,,