pikobs 3.0.331__py3-none-any.whl → 3.0.332__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.
@@ -374,50 +374,65 @@ def create_and_populate_moyenne_table(
374
374
  # it into its own column. Every other family leaves `channel` as
375
375
  # a literal NULL and groups exactly as before -- this is a pure
376
376
  # addition, the non-radiance extraction path is unchanged.
377
+ #
378
+ # CRITICAL: the per-channel rows must NEVER be the only rows
379
+ # inserted for a radiance family. The SAME id_obs (profile)
380
+ # appears in MANY channel rows (one per channel it reports), so
381
+ # summing Nobsdata/Nobsprofile ACROSS channel rows -- exactly
382
+ # what every consumer of `moyenne` that isn't channel-aware does
383
+ # (the main Nobs/Nobsprofile series behind the mosaic, global
384
+ # time series, and profile summary table) -- silently multiplies
385
+ # the true profile count by roughly the number of channels
386
+ # reported (confirmed directly: a 10-profile/15-channel test
387
+ # case summed to 150, not 10). The fix is to ALSO insert a
388
+ # SEPARATE, non-channel-split row (channel=NULL) with the
389
+ # correct, ungrouped-by-channel counts, so every consumer that
390
+ # filters `WHERE channel IS NULL` (the main series) gets the
391
+ # right numbers, while `WHERE channel IS NOT NULL` (the
392
+ # per-channel breakdown) still works exactly as before.
377
393
  # ------------------------------------------------------------------
378
394
  is_radiance = (VCOTYP == 'CANAL')
379
395
  if is_radiance:
380
- channel_expr = "vcoord"
381
- group_by_clause = f"{group_col}, vcoord"
396
+ passes = [("NULL", group_col), ("vcoord", f"{group_col}, vcoord")]
382
397
  else:
383
- channel_expr = "NULL"
384
- group_by_clause = group_col
385
-
386
- insert_query = f"""
387
- INSERT INTO moyenne (Nobsdata, Nobsprofile, avg_omp, avg_oma, id_stn, channel, date)
388
- SELECT
389
- count(DISTINCT(id_data)),
390
- count(DISTINCT(id_obs)),
391
- {avg_omp_expr},
392
- {avg_oma_expr},
393
- {id_stn_expr},
394
- {channel_expr},
395
- {date_match.group(1)}
396
- FROM db.header
397
- NATURAL JOIN db.DATA
398
- WHERE obsvalue IS NOT NULL
399
- {flag_criteria}
400
- {LATLONCRIT}
401
- {VCOCRIT}
402
- {family_filter}
403
- GROUP BY {group_by_clause};
404
- """
405
-
406
- try:
407
- cursor.execute(insert_query)
408
- except sqlite3.OperationalError as err:
409
- msg = str(err).lower()
410
- fb_query = insert_query
411
- for metric in agr_list:
412
- if metric in msg:
413
- print(f"[WARNING] Column '{metric}' not found in "
414
- f"{os.path.basename(existing_db_filename)}; storing NULL.",
415
- flush=True)
416
- fb_query = fb_query.replace(f"AVG({metric})", "NULL")
417
- if fb_query != insert_query:
418
- cursor.execute(fb_query)
419
- else:
420
- raise
398
+ passes = [("NULL", group_col)]
399
+
400
+ for channel_expr, group_by_clause in passes:
401
+ insert_query = f"""
402
+ INSERT INTO moyenne (Nobsdata, Nobsprofile, avg_omp, avg_oma, id_stn, channel, date)
403
+ SELECT
404
+ count(DISTINCT(id_data)),
405
+ count(DISTINCT(id_obs)),
406
+ {avg_omp_expr},
407
+ {avg_oma_expr},
408
+ {id_stn_expr},
409
+ {channel_expr},
410
+ {date_match.group(1)}
411
+ FROM db.header
412
+ NATURAL JOIN db.DATA
413
+ WHERE obsvalue IS NOT NULL
414
+ {flag_criteria}
415
+ {LATLONCRIT}
416
+ {VCOCRIT}
417
+ {family_filter}
418
+ GROUP BY {group_by_clause};
419
+ """
420
+
421
+ try:
422
+ cursor.execute(insert_query)
423
+ except sqlite3.OperationalError as err:
424
+ msg = str(err).lower()
425
+ fb_query = insert_query
426
+ for metric in agr_list:
427
+ if metric in msg:
428
+ print(f"[WARNING] Column '{metric}' not found in "
429
+ f"{os.path.basename(existing_db_filename)}; storing NULL.",
430
+ flush=True)
431
+ fb_query = fb_query.replace(f"AVG({metric})", "NULL")
432
+ if fb_query != insert_query:
433
+ cursor.execute(fb_query)
434
+ else:
435
+ raise
421
436
  mem_conn.commit()
422
437
 
423
438
  try:
@@ -891,7 +891,7 @@ def obstimedb_plot(
891
891
  select_extra.append(
892
892
  f"SUM(CASE WHEN {col} IS NOT NULL THEN Nobsdata ELSE 0 END) as _wden_{metric}")
893
893
  query = ("SELECT date, id_stn, " + ", ".join(select_extra) +
894
- " FROM moyenne GROUP BY date, id_stn;")
894
+ " FROM moyenne WHERE channel IS NULL GROUP BY date, id_stn;")
895
895
  try:
896
896
  df = pd.read_sql_query(query, conn)
897
897
  except Exception as e:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pikobs
3
- Version: 3.0.331
3
+ Version: 3.0.332
4
4
  Summary: pikobs
5
5
  Home-page: https://gitlab.science.gc.ca/dlo001/pikobs
6
6
  Author: David Lobon
@@ -42,8 +42,8 @@ pikobs/obscutoff/__init__.py,sha256=zBvprGRCin9W3w6_k-SZLJ-p-lZa82cqXr1aDIti-UE,
42
42
  pikobs/obscutoff/obscutoff.py,sha256=z78FWocYD8QZus6z5X4tQ738__K5q8_RxzngEm9N0iQ,40238
43
43
  pikobs/obscutoff/obscutoff_plot.py,sha256=AiqPI6IvViuzoVQzia9NK97lDHtsqcn0newN8MRjojQ,37858
44
44
  pikobs/obstimedb/__init__.py,sha256=0-sYoNyHDzRGXT1mzbU5Ek0hSGGlUXn84yx7lvE3qVk,56
45
- pikobs/obstimedb/obstimedb.py,sha256=XJo1D49-b6uWZjUSO2wV57IjOdf8vCCuUSvKFy2A78A,26478
46
- pikobs/obstimedb/obstimedb_plot.py,sha256=idsW_80Nlllc1LjtkQozsLvo4Za8xKaqXlNWOy2uCHE,68749
45
+ pikobs/obstimedb/obstimedb.py,sha256=LQYwCV3rm5tJQZKj5hd9y7MH_D2TqJ2AEEFmM0nuXOM,27668
46
+ pikobs/obstimedb/obstimedb_plot.py,sha256=1JZyZZzPW-dUfPMGUoWx9fM-DRaHVeXchm9RVlB4J-4,68771
47
47
  pikobs/pbs_submit/__init__.py,sha256=atE3cvhxT_mLdd7RFpRQEIicE0rhoqNMm1bqMtckqmA,26
48
48
  pikobs/pbs_submit/pbs_submit.py,sha256=UT8mZnLtCo2xSKW8IZVOsON2x_jIPjBTcpId5RTF6zo,9562
49
49
  pikobs/pikobsburp2rdb/__init__.py,sha256=gGD_XwalMfcunOvTeN4ogtTqBdL5HSOfdWhy6zdIr8E,31
@@ -73,7 +73,7 @@ pikobs/web/viewer.py,sha256=EZsFajvuyIcEoIcqnUAJ65gvqLgq69jqtGjUd4_RZIE,23372
73
73
  pikobs/zone/__init__.py,sha256=3crOJs1I5hf34SkRFtmDCXWwdAoYGuL52gG8QWuiN1Y,45
74
74
  pikobs/zone/zone.py,sha256=UtwUYKZgw9u6OKn2gRFw2m3Th8ChqMFkiO4OOG9FLrA,54443
75
75
  pikobs/zone/zone_plot.py,sha256=epESi90eeoofrqVDCkhjY6QMEyuH1WWbiPjAmNPwWe0,26773
76
- pikobs-3.0.331.dist-info/METADATA,sha256=6vGqbe3YN1ws4LlIMcQgGJ6HZ65QcHZbfsY0ysHhxGs,1059
77
- pikobs-3.0.331.dist-info/WHEEL,sha256=AtBG6SXL3KF_v0NxLf0ehyVOh0cold-JbJYXNGorC6Q,92
78
- pikobs-3.0.331.dist-info/top_level.txt,sha256=UAWCWWUoD-o_b3nFqEG6V0_v37qzVY7i_BPRhfMdnJ0,7
79
- pikobs-3.0.331.dist-info/RECORD,,
76
+ pikobs-3.0.332.dist-info/METADATA,sha256=acD_bePcLiOXWxmwgCLBibBRWne5ec-5hQErZhBHF5c,1059
77
+ pikobs-3.0.332.dist-info/WHEEL,sha256=AtBG6SXL3KF_v0NxLf0ehyVOh0cold-JbJYXNGorC6Q,92
78
+ pikobs-3.0.332.dist-info/top_level.txt,sha256=UAWCWWUoD-o_b3nFqEG6V0_v37qzVY7i_BPRhfMdnJ0,7
79
+ pikobs-3.0.332.dist-info/RECORD,,