rda-python-icoads 1.0.10__tar.gz → 1.0.11__tar.gz

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 rda-python-icoads might be problematic. Click here for more details.

Files changed (37) hide show
  1. {rda_python_icoads-1.0.10/src/rda_python_icoads.egg-info → rda_python_icoads-1.0.11}/PKG-INFO +3 -2
  2. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/pyproject.toml +1 -1
  3. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/PgIMMA.py +142 -102
  4. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/fillicoads.py +15 -8
  5. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11/src/rda_python_icoads.egg-info}/PKG-INFO +3 -2
  6. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/LICENSE +0 -0
  7. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/MANIFEST.in +0 -0
  8. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/README.md +0 -0
  9. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/setup.cfg +0 -0
  10. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/R3.0-stat_doc.pdf +0 -0
  11. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/README_R3.0_Subset.html +0 -0
  12. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/__init__.py +0 -0
  13. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/checkicoads.py +0 -0
  14. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/cleanicoads.py +0 -0
  15. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/countattm.py +0 -0
  16. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/countattmvar.py +0 -0
  17. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/counticoads.py +0 -0
  18. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/countsst.py +0 -0
  19. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/fillinventory.py +0 -0
  20. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/fillitable.py +0 -0
  21. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/fillmonth.py +0 -0
  22. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/fixiidx.py +0 -0
  23. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/imma1_subset.py +0 -0
  24. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/maxsst.py +0 -0
  25. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/msg +0 -0
  26. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/msg3.0_subset_readme.txt +0 -0
  27. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/msg3_subset.py +0 -0
  28. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/msg_download.py +0 -0
  29. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/msgsubset.f +0 -0
  30. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/rdimma1_csv.f +0 -0
  31. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads/writeicoads.py +0 -0
  32. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads.egg-info/SOURCES.txt +0 -0
  33. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads.egg-info/dependency_links.txt +0 -0
  34. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads.egg-info/entry_points.txt +0 -0
  35. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads.egg-info/requires.txt +0 -0
  36. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/src/rda_python_icoads.egg-info/top_level.txt +0 -0
  37. {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.11}/tests/test_icoads.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: rda_python_icoads
3
- Version: 1.0.10
3
+ Version: 1.0.11
4
4
  Summary: RDA python package to manage RDA ICOADS datasets
5
5
  Author-email: Zaihua Ji <zji@ucar.edu>
6
6
  Project-URL: Homepage, https://github.com/NCAR/rda-python-icoads
@@ -12,6 +12,7 @@ Requires-Python: >=3.7
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
14
  Requires-Dist: rda_python_common
15
+ Dynamic: license-file
15
16
 
16
17
  RDA python package to manage RDA ICOADS datasets.
17
18
 
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
6
6
 
7
7
  [project]
8
8
  name = "rda_python_icoads"
9
- version = "1.0.10"
9
+ version = "1.0.11"
10
10
  authors = [
11
11
  { name="Zaihua Ji", email="zji@ucar.edu" },
12
12
  ]
@@ -313,6 +313,7 @@ ISUPPL = { # stti = '99' attl = 0 (variable lenth)
313
313
  TABLECOUNT = 12
314
314
  IMMA_NAMES = ['icoreloc', 'icorereg', 'iicoads', 'iimmt5', 'imodqc', 'imetavos',
315
315
  'inocn', 'iecr', 'ireanqc', 'iivad', 'iuida', 'isuppl']
316
+ CHK_NAMES = ['iimmt5', 'imodqc', 'imetavos', 'inocn', 'iecr', 'ireanqc', 'iivad', 'isuppl']
316
317
 
317
318
  #
318
319
  # define IMMA sections, core + attms
@@ -342,6 +343,9 @@ MUNIQUE = {
342
343
  'iivad' : ['arci', 'cdi']
343
344
  }
344
345
 
346
+ IVADSC = 'ivaddb1'
347
+ CNTLSC = 'cntldb1'
348
+
345
349
  MULTI_NAMES = []
346
350
  ATTI2NAME = {}
347
351
  ATTCPOS = INVENTORY = CURTIDX = CURIIDX = 0
@@ -358,10 +362,13 @@ ATTM_VARS = {}
358
362
  MISSING = -999999
359
363
  ERROR = -999999
360
364
  LEADUID = 0
365
+ CURRN3 = -1
361
366
  CHKEXIST = 0
362
367
  UIDLENGTH = 0 # uid record len
363
368
  UIDOFFSET = 0 # uid value offset
364
369
  ATTMNAME = None # standalone attm section name to fill
370
+ DATE2TIDX = {}
371
+ TBLSTATUS = {}
365
372
 
366
373
  #
367
374
  # initialize the table information
@@ -395,6 +402,7 @@ def identify_attm_name(line):
395
402
  UIDOFFSET = 4
396
403
  UIDLENGTH = 15
397
404
  atti = line[15:17]
405
+ CURRN3 = int(line[12])
398
406
  else:
399
407
  atti = None
400
408
 
@@ -423,16 +431,15 @@ def cache_field_info(aname, var, uidopt = 0):
423
431
  #
424
432
  # append the individual fields and return imma records for one line input
425
433
  #
426
- def get_imma_records(line, cdate, records):
434
+ def get_imma_records(cdate, line, records):
427
435
 
428
- global CURIIDX, CURIUID
436
+ global CURIIDX
429
437
  llen = len(line)
430
438
  if llen == 0: return records
431
439
 
432
440
  if CURIUID: # got core section already
433
441
  coreidx = 2
434
442
  offset = UIDLENGTH
435
- uid = CURIUID
436
443
  else:
437
444
  coreidx = 0
438
445
  offset = 0
@@ -450,7 +457,7 @@ def get_imma_records(line, cdate, records):
450
457
  #48 if aname == 'iivad': pgrec['cdi'] = PgUtil.adddate('2014-01-01', 0, 0, I36(pgrec['cdi']), 'YYYMMDD')
451
458
  if aname not in records: records[aname] = initialize_attm_records(imma[3])
452
459
  if CURIUID:
453
- append_one_attm(uid, imma[0], imma[3], pgrec, records[aname])
460
+ append_one_attm(cdate, imma[0], imma[3], pgrec, records[aname])
454
461
  else:
455
462
  pgrecs[aname] = pgrec
456
463
 
@@ -459,32 +466,29 @@ def get_imma_records(line, cdate, records):
459
466
 
460
467
  if CURIUID: return records
461
468
 
462
- if 'iuida' not in pgrecs: PgLOG.pglog("Miss UID attm: " + line, PgLOG.LGEREX)
463
- uid = pgrecs['iuida']['uid']
464
- records['icoreloc']['date'].append(cdate)
465
-
466
469
  for aname in pgrecs:
467
470
  imma = IMMAS[aname]
468
- append_one_attm(uid, imma[0], imma[3], pgrecs[aname], records[aname])
471
+ append_one_attm(cdate, imma[0], imma[3], pgrecs[aname], records[aname])
469
472
 
470
473
  return records
471
474
 
472
475
  #
473
476
  # append the individual fields and return imma records for one line of multi-attm record
474
477
  #
475
- def get_imma_multiple_records(line, records):
478
+ def get_imma_multiple_records(cdate, line, records):
476
479
 
477
480
  llen = len(line)
478
481
  if llen == 0: return records
479
482
  uid = line[4:10]
480
483
  offset = 15
484
+ CURRN3 = int(line[12])
481
485
  aname = ATTI2NAME[line[15:17]]
482
486
  imma = IMMAS[aname]
483
487
  if aname not in records: records[aname] = initialize_attm_records(imma[3])
484
488
 
485
489
  while (llen-offset) > 3:
486
490
  pgrec = get_one_attm(imma[3], offset, line)
487
- append_one_attm(uid, imma[0], imma[3], pgrec, records[aname])
491
+ append_one_attm(cdate, imma[0], imma[3], pgrec, records[aname])
488
492
  offset += imma[2]
489
493
 
490
494
  return records
@@ -551,11 +555,10 @@ def set_imma_field(line):
551
555
  if not pgrec: return 0
552
556
 
553
557
  if not uid: PgLOG.pglog("Miss UID attm: " + line, PgLOG.LGEREX)
554
- if not get_itidx_date(uid): return 0
555
558
 
556
- tname = "{}_{}".format(FIELDINFO['aname'], CURTIDX)
557
- if PgDBI.pgget(tname, "", "iidx = {} AND {}".format(CURIIDX, cnd)): return 0
558
- return PgDBI.pgupdt(tname, pgrec, "iidx = {}".format(CURIIDX), PgLOG.LGEREX)
559
+ tname = f"{IVADSC}.{FIELDINFO['aname']}_{CURTIDX}"
560
+ if PgDBI.pgget(tname, "", f"iidx = {CURIIDX} AND {cnd}"): return 0
561
+ return PgDBI.pgupdt(tname, pgrec, f"iidx = {CURIIDX}", PgLOG.LGEREX)
559
562
 
560
563
  #
561
564
  # get all field values for a single attm
@@ -584,20 +587,18 @@ def get_one_attm(attm, offset, line):
584
587
  #
585
588
  def initialize_attm_records(attm):
586
589
 
587
- pgrecs = {'iidx' : [], 'uid' : []}
590
+ pgrecs = {'iidx' : [], 'date' : []}
588
591
  for var in attm: pgrecs[var] = []
589
- if 'yr' in attm: pgrecs['date'] = []
590
592
 
591
593
  return pgrecs
592
594
 
593
595
  #
594
596
  # append one attm record to the multiple attm records
595
597
  #
596
- def append_one_attm(uid, aidx, attm, pgrec, pgrecs):
598
+ def append_one_attm(cdate, aidx, attm, pgrec, pgrecs):
597
599
 
598
- global IMMA_COUNTS
599
600
  pgrecs['iidx'].append(CURIIDX)
600
- if 'uid' not in attm: pgrecs['uid'].append(uid)
601
+ pgrecs['date'].append(cdate)
601
602
  for var in attm: pgrecs[var].append(pgrec[var])
602
603
  IMMA_COUNTS[aidx] += 1 # row index for individual table
603
604
 
@@ -606,7 +607,7 @@ def append_one_attm(uid, aidx, attm, pgrec, pgrecs):
606
607
  #
607
608
  def get_imma_counts(line, acnts):
608
609
 
609
- global CURIIDX, CURIUID
610
+ global CURIIDX
610
611
  llen = len(line)
611
612
  if llen == 0: return acnts
612
613
 
@@ -655,8 +656,8 @@ def add_imma_records(cdate, records):
655
656
 
656
657
  global INVENTORY, CURTIDX
657
658
  if INVENTORY and IMMA_NAMES[0] in records: # add counting record into inventory table
658
- ulen = len(records[IMMA_NAMES[0]]['uid'])
659
- if ulen > 0: INVENTORY = add_inventory_record(INVENTORY['fname'], cdate, ulen, INVENTORY)
659
+ rcnt = len(records[IMMA_NAMES[0]]['iidx'])
660
+ if rcnt > 0: INVENTORY = add_inventory_record(INVENTORY['fname'], cdate, rcnt, INVENTORY)
660
661
  if CURTIDX < INVENTORY['tidx']: CURTIDX = INVENTORY['tidx']
661
662
  tidx = CURTIDX
662
663
  else:
@@ -665,7 +666,7 @@ def add_imma_records(cdate, records):
665
666
  for i in range(TABLECOUNT):
666
667
  if not IMMA_COUNTS[i]: continue
667
668
  aname = IMMA_NAMES[i]
668
- acnts[i] = add_records_to_table(aname, str(tidx), records[aname], cdate)
669
+ acnts[i] = add_records_to_table(IVADSC, aname, str(tidx), records[aname], cdate)
669
670
  IMMA_COUNTS[i] = 0
670
671
 
671
672
  iuida = records['iuida'] if 'iuida' in records else None
@@ -678,18 +679,20 @@ def add_imma_records(cdate, records):
678
679
  #
679
680
  def read_attm_for_date(aname, cdate, tidx = None):
680
681
 
681
- if tidx is None:
682
+ global CURTIDX
683
+ if not tidx:
682
684
  tidx = date2tidx(cdate)
683
- if tidx is None: return None
685
+ if not tidx: return None
686
+ CURTIDX = tidx
684
687
 
685
- if aname == IMMA_NAMES[0]: return read_coreloc_for_date(cdate, tidx)
688
+ table = f"{IVADSC}.{aname}_{tidx}"
689
+ if aname in CHK_NAMES and not check_table_status(table): return None
690
+ return PgDBI.pgmget(table, "*", f"date = '{cdate}' ORDER BY iidx", PgLOG.LGEREX)
686
691
 
687
- table = "{}_{}".format(aname, tidx)
688
- if not PgDBI.pgcheck(table): return None
689
- loctable = "{}_{}".format(IMMA_NAMES[0], tidx)
690
- jtables = "{} a, {} b".format(table, loctable)
692
+ def check_table_status(table):
691
693
 
692
- return PgDBI.pgmget(jtables, "a.*", "b.date = '{}' AND a.iidx = b.iidx ORDER BY iidx".format(cdate), PgLOG.LGEREX)
694
+ if table not in TBLSTATUS: TBLSTATUS[table] = True if PgDBI.pgcheck(table) else False
695
+ return TBLSTATUS[table]
693
696
 
694
697
  #
695
698
  # read core records for given date
@@ -702,26 +705,60 @@ def read_coreloc_for_date(cdate, tidx = None):
702
705
  if not tidx: return None
703
706
  CURTIDX = tidx
704
707
 
705
- return PgDBI.pgmget("{}_{}".format(IMMA_NAMES[0], tidx), '*', "date = '{}' ORDER BY iidx".format(cdate))
708
+ return PgDBI.pgmget(f"{IVADSC}.icoreloc_{tidx}", '*', f"date = '{cdate}' ORDER BY iidx")
709
+
710
+ def uid2iidx_tidx(uid, tidx):
711
+
712
+ uidx = uid[0:2].lower()
713
+ suid = uid[2:6]
714
+ table = f"{CNTLSC}.itidx_{uidx}"
715
+ cond = f"suid = '{suid}' AND tidx = {tidx}"
716
+ pgrec = PgDBI.pgget(table, "iidx", cond, PgLOG.LGEREX)
717
+ if not pgrec:
718
+ PgLOG.pglog(f"{suid}-{tidx}: suid-tidx not in {table}", PgLOG.LGEREX)
719
+
720
+ return pgrec['iidx']
721
+
722
+ def uid2iidx_date(uid, date):
723
+
724
+ uidx = uid[0:2].lower()
725
+ suid = uid[2:6]
726
+ table = f"{CNTLSC}.itidx_{uidx}"
727
+ cond = f"suid = '{suid}' AND date = {date}"
728
+ pgrec = PgDBI.pgget(table, "iidx", cond, PgLOG.LGEREX)
729
+ if not pgrec:
730
+ PgLOG.pglog(f"{suid}-{date}: suid-date not in {table}", PgLOG.LGEREX)
731
+
732
+ return pgrec['iidx']
733
+
734
+ def uid2iidx_rn3(uid, rn3):
735
+
736
+ uidx = uid[0:2].lower()
737
+ suid = uid[2:6]
738
+ table = f"{CNTLSC}.itidx_{uidx}"
739
+ cond = f"suid = '{suid}' AND rn3 = {rn3}"
740
+ pgrec = PgDBI.pgget(table, "iidx", cond, PgLOG.LGEREX)
741
+ if not pgrec:
742
+ PgLOG.pglog(f"{suid}-{rn3}: suid-rn3 not in {table}", PgLOG.LGEREX)
743
+
744
+ return pgrec['iidx']
706
745
 
707
746
  #
708
747
  # read attm record for given uid
709
748
  #
710
749
  def read_attm_for_uid(aname, uid, tidx):
711
750
 
712
- if aname == IMMA_NAMES[0]: return read_coreloc_for_uid(uid, tidx)
713
-
714
- table = "{}_{}".format(aname, tidx)
715
- if not PgDBI.pgcheck(table): return None
716
-
717
- return PgDBI.pgget(table, "*", "uid = '{}'".format(uid), PgLOG.LGEREX)
751
+ iidx = uid2iidx_tidx(uid, tidx)
752
+ table = f"{IVADSC}.{aname}_{tidx}"
753
+ return PgDBI.pgget(table, "*", f"iidx = '{iidx}'", PgLOG.LGEREX)
718
754
 
719
755
  #
720
756
  # read core records for given uid
721
757
  #
722
758
  def read_coreloc_for_uid(uid, tidx):
723
759
 
724
- return PgDBI.pgget("{}_{}".format(IMMA_NAMES[0], tidx), '*', "uid = '{}'".format(uid))
760
+ iidx = uid2iidx_tidx(uid, tidx)
761
+ return PgDBI.pgget(f"{IVADSC}.icoreloc_{tidx}", '*', f"iidx = {iidx}")
725
762
 
726
763
  #
727
764
  # write IMMA records to file
@@ -774,15 +811,15 @@ def write_imma_records(fh, cdate, tidx, dumpall):
774
811
  tidx = date2tidx(cdate)
775
812
  if not tidx: return None
776
813
 
777
- dcnd = "date = '{}' ORDER BY iidx".format(cdate)
778
- mtable = "{}_{}".format(IMMA_NAMES[0], tidx)
814
+ dcnd = f"date = '{cdate}' ORDER BY iidx"
815
+ mtable = f"{IVADSC}.icoreloc_{tidx}"
779
816
  pgrecs = PgDBI.pgmget(mtable, "*", dcnd)
780
817
  if not pgrecs: return None
781
818
  acnts[0] = count = len(pgrecs['iidx'])
782
819
  minidx = pgrecs['iidx'][0]
783
820
  jcnd = "m.iidx = n.iidx AND " + dcnd
784
- tcnd = "tidx = {} AND attm =".format(tidx)
785
- atable = "cntldb.iattm"
821
+ tcnd = f"tidx = {tidx} AND attm ="
822
+ atable = f"{CNTLSC}.iattm"
786
823
 
787
824
  lines = ['']*count
788
825
  attcs = [-2]*count
@@ -794,9 +831,9 @@ def write_imma_records(fh, cdate, tidx, dumpall):
794
831
  for a in range(1, TABLECOUNT):
795
832
  aname = IMMA_NAMES[a]
796
833
  if aname in MUNIQUE: continue
797
- if PgDBI.pgget(atable, "", "{} '{}'".format(tcnd, aname)):
798
- ntable = "{}_{}".format(aname, tidx)
799
- pgrecs = PgDBI.pgmget("{} m, {} n".format(mtable, ntable), "n.*", jcnd)
834
+ if PgDBI.pgget(atable, "", f"{tcnd} '{aname}'"):
835
+ ntable = f"{IVADSC}.{aname}_{tidx}"
836
+ pgrecs = PgDBI.pgmget(f"{mtable} m, {ntable} n", "n.*", jcnd)
800
837
  if not pgrecs: continue
801
838
  acnts[a] = len(pgrecs['iidx'])
802
839
  if dumpall and aname == "iuida":
@@ -810,9 +847,9 @@ def write_imma_records(fh, cdate, tidx, dumpall):
810
847
  for a in range(1, TABLECOUNT):
811
848
  aname = IMMA_NAMES[a]
812
849
  if MUNIQUE[aname] is None: continue
813
- if PgDBI.pgget(atable, "", "{} '{}'".format(tcnd, aname)):
814
- ntable = "{}_{}".format(aname, tidx)
815
- pgrecs = PgDBI.pgmget("{} m, {} n".format(mtable, ntable), "n.*", jcnd)
850
+ if PgDBI.pgget(atable, "", f"{tcnd} '{aname}'"):
851
+ ntable = f"{IVADSC}.{aname}_{tidx}"
852
+ pgrecs = PgDBI.pgmget(f"{mtable} m, {ntable} n", "n.*", jcnd)
816
853
  if not pgrecs: continue
817
854
  acnts[a] = len(pgrecs['iidx'])
818
855
  append_imma_lines(aname, minidx, acnts[a], pgrecs, ulines, lines, attcs)
@@ -899,10 +936,10 @@ def count_imma_records(cdate, tidx, cntall):
899
936
  tidx = date2tidx(cdate)
900
937
  if not tidx: return None
901
938
 
902
- atable = "cntldb.iattm"
903
- tcnd = "tidx = {}".format(tidx)
904
- dcnd = "date = '{}'".format(cdate)
905
- mtable = "{}_{}".format(IMMA_NAMES[0], tidx)
939
+ atable = f"{CNTLSC}.iattm"
940
+ tcnd = f"tidx = {tidx}"
941
+ dcnd = f"date = '{cdate}'"
942
+ mtable = f"{IVADSC}.icoreloc_{tidx}"
906
943
  jcnd = "m.iidx = n.iidx AND " + dcnd
907
944
  acnts[0] = PgDBI.pgget(mtable, "", dcnd)
908
945
  if not acnts[0]: return None
@@ -910,9 +947,9 @@ def count_imma_records(cdate, tidx, cntall):
910
947
  for i in range(1,TABLECOUNT):
911
948
  aname = IMMA_NAMES[i]
912
949
  if not cntall and aname in MUNIQUE: continue
913
- if PgDBI.pgget(atable, "", "{} AND attm = '{}'".format(tcnd, aname)):
914
- ntable = "{}_{}".format(aname, tidx)
915
- acnts[i] = PgDBI.pgget("{} m, {} n".format(mtable, ntable), "", jcnd)
950
+ if PgDBI.pgget(atable, "", f"{tcnd} AND attm = '{aname}'"):
951
+ ntable = f"{IVADSC}.{aname}_{tidx}"
952
+ acnts[i] = PgDBI.pgget(f"{mtable} m, {ntable} n", "", jcnd)
916
953
 
917
954
  return acnts
918
955
 
@@ -922,12 +959,12 @@ def count_imma_records(cdate, tidx, cntall):
922
959
  def add_inventory_record(fname, cdate, count, inventory, cntopt = 0):
923
960
 
924
961
  didx = 0
925
- table = "cntldb.inventory"
962
+ table = f"{CNTLSC}.inventory"
926
963
 
927
964
  if cntopt == 2:
928
- cnd = "date = '{}'".format(cdate)
965
+ cnd = f"date = '{cdate}'"
929
966
  pgrec = PgDBI.pgget(table, "didx, count", cnd, PgLOG.LGEREX)
930
- if not pgrec: PgLOG.pglog("{}: error get record for {}".format(table, cnd), PgLOG.LGEREX)
967
+ if not pgrec: PgLOG.pglog(f"{table}: error get record for {cnd}", PgLOG.LGEREX)
931
968
  count = pgrec['count']
932
969
  didx = pgrec['didx']
933
970
  record = {}
@@ -944,9 +981,9 @@ def add_inventory_record(fname, cdate, count, inventory, cntopt = 0):
944
981
  record['tcount'] = count
945
982
 
946
983
  if didx:
947
- cnd = "didx = {}".format(didx)
984
+ cnd = f"didx = {didx}"
948
985
  if not PgDBI.pgupdt(table, record, cnd, PgLOG.LGEREX):
949
- PgLOG.pglog("{}: error update table for {}".format(table, cnd), PgLOG.LGEREX)
986
+ PgLOG.pglog(f"{table}: error update table for {cnd}", PgLOG.LGEREX)
950
987
  else:
951
988
  didx = PgDBI.pgadd(table, record, PgLOG.LGEREX|PgLOG.AUTOID)
952
989
 
@@ -967,15 +1004,16 @@ def get_attm_names(tidx):
967
1004
  aindices = []
968
1005
  attms = {}
969
1006
  acnt = 0
970
- pgrecs = PgDBI.pgmget("cntldb.iattm", "attm", "tidx = {}".format(tidx), PgLOG.LGEREX)
971
- if not pgrecs: PgLOG.pglog("miss iattm record for tidx = {}".format(tidx), PgLOG.LGEREX)
1007
+ cnd = f"tidx = {tidx}"
1008
+ pgrecs = PgDBI.pgmget(f"{CNTLSC}.iattm", "attm", cnd, PgLOG.LGEREX)
1009
+ if not pgrecs: PgLOG.pglog(f"miss iattm record for {cnd}", PgLOG.LGEREX)
972
1010
  for aname in pgrecs['attm']: attms[aname] = 1
973
1011
 
974
1012
  for i in range(1, TABLECOUNT):
975
1013
  aname = IMMA_NAMES[i]
976
1014
  if aname in attms:
977
1015
  anames.append(aname)
978
- atables.append("{}_{}".format(aname, tidx))
1016
+ atables.append(f"{IVADSC}.{aname}_{tidx}")
979
1017
  aindices.append(i)
980
1018
  acnt += 1
981
1019
 
@@ -986,7 +1024,7 @@ def get_attm_names(tidx):
986
1024
  #
987
1025
  def get_attm_line(aname, atable, iidx, pgrec):
988
1026
 
989
- if not pgrec: pgrec = PgDBI.pgget(atable, "*", "iidx = {}".format(iidx), PgLOG.LGEREX)
1027
+ if not pgrec: pgrec = PgDBI.pgget(atable, "*", f"iidx = {iidx}", PgLOG.LGEREX)
990
1028
  return build_one_attm_line(aname, pgrec) if pgrec else None
991
1029
 
992
1030
  #
@@ -994,7 +1032,7 @@ def get_attm_line(aname, atable, iidx, pgrec):
994
1032
  #
995
1033
  def get_multiple_attm_line(aname, atable, iidx):
996
1034
 
997
- pgrecs = PgDBI.pgmget(atable, "*", "iidx = {} ORDER BY lidx".format(iidx), PgLOG.LGEREX)
1035
+ pgrecs = PgDBI.pgmget(atable, "*", f"iidx = {iidx} ORDER BY lidx", PgLOG.LGEREX)
998
1036
  icnt = (len(pgrecs['lidx']) if pgrecs else 0)
999
1037
  if not icnt: return (0, None)
1000
1038
 
@@ -1079,24 +1117,22 @@ def get_itidx_date(uid):
1079
1117
  global CURIUID, CURIIDX, CURTIDX
1080
1118
  uidx = uid[0:2].lower()
1081
1119
  suid = uid[2:6]
1082
- table = "cntldb.itidx_{}".format(uidx)
1083
-
1084
- pgrec = PgDBI.pgget(table, "*", "suid = '{}'".format(suid), PgLOG.LGEREX)
1085
- if not pgrec: return PgLOG.pglog("{}: SKIP suid not in {}".format(suid, table), PgLOG.WARNLG)
1120
+ table = f"{CNTLSC}.itidx_{uidx}"
1121
+ cond = f"suid = '{suid}' AND rn3 = {CURRN3}"
1122
+ pgrec = PgDBI.pgget(table, "*", cond, PgLOG.LGEREX)
1123
+ if not pgrec:
1124
+ msg = "{}-{}: suid-rn3 not in {}".format(suid, CURRN3, table)
1125
+ if CURRN3 < 0: msg += "\nProvide a RN3 (>= 0) to proceed"
1126
+ PgLOG.pglog(msg, PgLOG.LGEREX)
1086
1127
 
1087
1128
  if CHKEXIST: # check
1088
- table = "{}_{}".format(ATTMNAME, pgrec['tidx'])
1089
- cnd = "iidx = {}".format(pgrec['iidx'])
1090
- if ATTMNAME in MUNIQUE:
1091
- for fname in MUNIQUE[ATTMNAME]:
1092
- cnd += " AND {} = '{}'".format(fname, pgrec[fname])
1093
-
1129
+ table = f"{IVADSC}.{ATTMNAME}_{pgrec['tidx']}"
1130
+ cnd = f"iidx = {pgrec['iidx']}"
1094
1131
  if PgDBI.pgget(table, "", cnd): return None
1095
1132
 
1096
1133
  CURIUID = uid
1097
1134
  CURIIDX = pgrec['iidx']
1098
1135
  CURTIDX = pgrec['tidx']
1099
-
1100
1136
  return pgrec['date']
1101
1137
 
1102
1138
  #
@@ -1137,15 +1173,18 @@ def get_record_date(yr, mo, dy):
1137
1173
  #
1138
1174
  def date2tidx(cdate, getend = True):
1139
1175
 
1140
- table = "cntldb.inventory"
1176
+ if cdate in DATE2TIDX: return DATE2TIDX[cdate]
1177
+ table = f"{CNTLSC}.inventory"
1141
1178
  pgrec = PgDBI.pgget(table, "tidx", "date = '{}'".format(cdate), PgLOG.LGEREX)
1142
- if pgrec: return pgrec['tidx']
1179
+ if pgrec:
1180
+ DATE2TIDX[cdate] = pgrec['tidx']
1181
+ return pgrec['tidx']
1143
1182
 
1144
1183
  if getend:
1145
- cnd = "date < '{}'".format(cdate)
1184
+ cnd = f"date < '{cdate}'"
1146
1185
  pgrec = PgDBI.pgget(table, "max(tidx) tidx", cnd, PgLOG.LGEREX)
1147
1186
  else:
1148
- cnd = "date > '{}'".format(cdate)
1187
+ cnd = f"date > '{cdate}'"
1149
1188
  pgrec = PgDBI.pgget(table, "min(tidx) tidx", cnd, PgLOG.LGEREX)
1150
1189
  if pgrec:
1151
1190
  return pgrec['tidx']
@@ -1157,7 +1196,7 @@ def date2tidx(cdate, getend = True):
1157
1196
  #
1158
1197
  def iidx2date(iidx):
1159
1198
 
1160
- pgrec = PgDBI.pgget("cntldb.inventory", "date", "miniidx <= {} AND maxiidx >= {}".format(iidx, iidx), PgLOG.LGEREX)
1199
+ pgrec = PgDBI.pgget(f"{CNTLSC}.inventory", "date", f"miniidx <= {iidx} AND maxiidx >= {iidx}", PgLOG.LGEREX)
1161
1200
  return (pgrec['date'] if pgrec else None)
1162
1201
 
1163
1202
  #
@@ -1173,7 +1212,7 @@ def number2name(cn, fn):
1173
1212
  for i in range(2, TABLECOUNT):
1174
1213
  aname = IMMA_NAMES[i]
1175
1214
  if cn == int(IMMAS[aname][1]): break
1176
- if i >= TABLECOUNT: PgLOG.pglog("{}: Cannot find Component".format(cn), PgLOG.LGEREX)
1215
+ if i >= TABLECOUNT: PgLOG.pglog(f"{cn}: Cannot find Component", PgLOG.LGEREX)
1177
1216
  elif fn < 17:
1178
1217
  offset = 1
1179
1218
  aname = IMMA_NAMES[0]
@@ -1187,7 +1226,7 @@ def number2name(cn, fn):
1187
1226
  NUM2NAME[key] = [fname, aname]
1188
1227
  return NUM2NAME[key]
1189
1228
 
1190
- PgLOG.pglog("{}: Cannot find field name in Component '{}'".format(fn, aname), PgLOG.LGEREX)
1229
+ PgLOG.pglog(f"{fn}: Cannot find field name in Component '{aname}'", PgLOG.LGEREX)
1191
1230
 
1192
1231
  #
1193
1232
  # get component number and field number from give field name
@@ -1265,7 +1304,7 @@ def order_attm_variables(attm, aname = None):
1265
1304
  #
1266
1305
  def get_inventory_record(didx = 0, cntopt = 0):
1267
1306
 
1268
- table = "cntldb.inventory"
1307
+ table = f"{CNTLSC}.inventory"
1269
1308
 
1270
1309
  if not didx:
1271
1310
  if cntopt == 2:
@@ -1290,7 +1329,7 @@ def get_inventory_record(didx = 0, cntopt = 0):
1290
1329
  #
1291
1330
  def get_inventory_didx(cdate, prev):
1292
1331
 
1293
- table = "cntldb.inventory"
1332
+ table = f"{CNTLSC}.inventory"
1294
1333
  fld = "didx, date"
1295
1334
  if prev:
1296
1335
  cnd = "date < '{}' ORDER BY date DECS".format(cdate)
@@ -1305,9 +1344,9 @@ def get_inventory_didx(cdate, prev):
1305
1344
  #
1306
1345
  # initialize the global indices
1307
1346
  #
1308
- def init_current_indices(leaduid = 0, chkexist = 0):
1347
+ def init_current_indices(leaduid = 0, chkexist = 0, rn3 = 0):
1309
1348
 
1310
- global UIDIDX, CURIIDX, CURTIDX, CURIUID, AUTHREFS, LEADUID, CHKEXIST
1349
+ global UIDIDX, CURIIDX, CURTIDX, CURIUID, AUTHREFS, LEADUID, CHKEXIST, CURRN3
1311
1350
  # leading info for iuida
1312
1351
  UIDIDX = IMMAS['iuida'][0]
1313
1352
  CURIIDX = 0
@@ -1316,6 +1355,7 @@ def init_current_indices(leaduid = 0, chkexist = 0):
1316
1355
  AUTHREFS = {}
1317
1356
  LEADUID = leaduid
1318
1357
  CHKEXIST = chkexist
1358
+ CURRN3 = rn3
1319
1359
 
1320
1360
  #
1321
1361
  # initialize indices for givn date
@@ -1329,7 +1369,7 @@ def init_indices_for_date(cdate, fname):
1329
1369
  CURIIDX = INVENTORY['maxiidx']
1330
1370
  CURTIDX = INVENTORY['tidx']
1331
1371
  else:
1332
- pgrec = PgDBI.pgget("cntldb.inventory", "*", "date = '{}'".format(cdate), PgLOG.LGEREX)
1372
+ pgrec = PgDBI.pgget(f"{CNTLSC}.inventory", "*", "date = '{}'".format(cdate), PgLOG.LGEREX)
1333
1373
  if not pgrec: PgLOG.pglog("{}: give date not in inventory yet".format(cdate), PgLOG.LGEREX)
1334
1374
  if CURIIDX < pgrec['miniidx']:
1335
1375
  CURIIDX = pgrec['miniidx'] - 1
@@ -1343,21 +1383,21 @@ def update_control_tables(cdate, acnts, iuida, tidx = 0):
1343
1383
  if not tidx: tidx = date2tidx(cdate)
1344
1384
 
1345
1385
  if iuida and acnts[0]:
1346
- tname = "cntldb.itidx"
1347
1386
  records = {}
1348
1387
  for i in range(acnts[UIDIDX]):
1349
1388
  auid = iuida['uid'][i][0:2].lower()
1350
1389
  if auid not in records:
1351
- records[auid] = {'suid' : [], 'date' : [], 'tidx' : [], 'iidx' : []}
1390
+ records[auid] = {'iidx' : [], 'suid' : [], 'rn3' : [], 'date' : [], 'tidx' : []}
1352
1391
  records[auid]['suid'].append(iuida['uid'][i][2:6])
1392
+ records[auid]['rn3'].append(iuida['rn3'][i])
1353
1393
  records[auid]['date'].append(cdate)
1354
1394
  records[auid]['tidx'].append(tidx)
1355
1395
  records[auid]['iidx'].append(iuida['iidx'][i])
1356
1396
 
1357
1397
  for auid in records:
1358
- add_records_to_table(tname, auid, records[auid], cdate)
1398
+ add_records_to_table(CNTLSC, 'itidx', auid, records[auid], cdate)
1359
1399
 
1360
- tname = "cntldb.iattm"
1400
+ tname = f"{CNTLSC}.iattm"
1361
1401
  dname = tname + "_daily"
1362
1402
  for i in range(TABLECOUNT):
1363
1403
  if not acnts[i]: continue
@@ -1383,12 +1423,12 @@ def update_control_tables(cdate, acnts, iuida, tidx = 0):
1383
1423
  #
1384
1424
  # add records to a table
1385
1425
  #
1386
- def add_records_to_table(tname, suffix, records, cdate):
1426
+ def add_records_to_table(scname, tname, suffix, records, cdate):
1387
1427
 
1388
- table = "{}_{}".format(tname, suffix)
1389
- if not PgDBI.pgcheck(table):
1390
- pgcmd = PgDBI.get_pgddl_command(tname)
1391
- PgLOG.pgsystem("{} -x {}".format(pgcmd, suffix), PgLOG.LGWNEX)
1428
+ table = f"{scname}.{tname}_{suffix}"
1429
+ if not check_table_status(table):
1430
+ pgcmd = PgDBI.get_pgddl_command(tname = tname, suf = suffix, scname = scname)
1431
+ if PgLOG.pgsystem(pgcmd, PgLOG.LGWNEX): TBLSTATUS[table] = True
1392
1432
 
1393
1433
  cnt = PgDBI.pgmadd(table, records, PgLOG.LGEREX)
1394
1434
  s = 's' if cnt > 1 else ''
@@ -1409,13 +1449,13 @@ def match_imma_records(cdate, t1, t2, w, e, s, n, vt):
1409
1449
  tinfo = TINFO[cdate]
1410
1450
  if not tinfo: return 0
1411
1451
  else:
1412
- tinfo = PgDBI.pgget("cntldb.itable", "*", "bdate <= '{}' AND edate >= '{}'".format(cdate, cdate), PgLOG.LGWNEX)
1452
+ tinfo = PgDBI.pgget(f"{CNTLSC}.itable", "*", "bdate <= '{}' AND edate >= '{}'".format(cdate, cdate), PgLOG.LGWNEX)
1413
1453
  if not tinfo:
1414
1454
  TINFO[cdate] = 0
1415
1455
  return 0
1416
1456
 
1417
1457
  # match time/latitude
1418
- mrecs = PgDBI.pgmget("icoreloc_{}".format(tinfo['tidx']), "*",
1458
+ mrecs = PgDBI.pgmget(f"{IVADSC}.icoreloc_{tinfo['tidx']}", "*",
1419
1459
  "date = '{}' AND hr BETWEEN {} AND {} AND lat BETWEEN {} AND {}".format(cdate, t1, t2, s, n), PgLOG.LGWNEX)
1420
1460
  if not mrecs: return 0 # no match
1421
1461
 
@@ -1451,7 +1491,7 @@ def match_imma_vars(tinfo, mrec, vt):
1451
1491
  name = vt[v]
1452
1492
  if name not in mrecs:
1453
1493
  if name in tinfo:
1454
- mrecs[name] = PgDBI.pgget("{}_{}".format(name, tidx), "*", "iidx = {}".format(iidx))
1494
+ mrecs[name] = PgDBI.pgget(f"{IVADSC}.{name}_{tidx}", "*", f"iidx = {iidx}")
1455
1495
  if not mrecs[name]: mrecs[name] = 0
1456
1496
  else:
1457
1497
  mrecs[name] = 0
@@ -33,8 +33,10 @@ PVALS = {
33
33
  def main():
34
34
 
35
35
  addinventory = leaduid = chkexist = 0
36
+ rn3 = -1
36
37
  argv = sys.argv[1:]
37
-
38
+
39
+ option = None
38
40
  for arg in argv:
39
41
  if arg == "-b":
40
42
  PgLOG.PGLOG['BCKGRND'] = 1
@@ -44,27 +46,32 @@ def main():
44
46
  leaduid = 1
45
47
  elif arg == "-e":
46
48
  chkexist = 1
49
+ elif arg == "-r":
50
+ option = 'r'
47
51
  elif arg == "-i":
48
52
  addinventory = 1
49
53
  elif re.match(r'^-', arg):
50
54
  PgLOG.pglog(arg + ": Invalid Option", PgLOG.LGWNEX)
55
+ elif option == 'r':
56
+ rn3 = int(arg)
51
57
  else:
52
58
  PVALS['files'].append(arg)
53
59
 
54
60
  if not PVALS['files']:
55
- print("Usage: fillicoads [-a] [-e] [-i] [-u] FileNameList")
61
+ print("Usage: fillicoads [-a] [-e] [-i] [-r] [-u] FileNameList")
56
62
  print(" At least one file name needs to fill icoads data into Postgres Server")
57
63
  print(" Option -a: add all attms, including multi-line ones, such as IVAD and REANQC")
58
64
  print(" Option -i: add daily counting records into inventory table")
65
+ print(" Option -r: last digit of IMMA release number")
59
66
  print(" Option -u: standalone attachment records with leading 6-character UID")
60
67
  print(" Option -e: check existing record before adding attm")
61
68
  sys.exit(0)
62
69
 
63
70
  PgLOG.PGLOG['LOGFILE'] = "icoads.log"
64
- PgDBI.ivaddb_dbname()
65
-
71
+ PgDBI.set_scname(dbname = 'ivaddb', scname = 'ivaddb1', lnname = 'ivaddb', dbhost = PgLOG.PGLOG['PMISCHOST'])
72
+
66
73
  PgLOG.cmdlog("fillicoads {}".format(' '.join(argv)))
67
- PgIMMA.init_current_indices(leaduid, chkexist)
74
+ PgIMMA.init_current_indices(leaduid, chkexist, rn3)
68
75
  PVALS['names'] = '/'.join(PgIMMA.IMMA_NAMES)
69
76
  fill_imma_data(addinventory)
70
77
  PgLOG.cmdlog()
@@ -103,14 +110,14 @@ def process_imma_file(fname, addinventory):
103
110
  idate = cdate = PgIMMA.get_imma_date(line)
104
111
  if cdate:
105
112
  PgIMMA.init_indices_for_date(cdate, iname)
106
- records = PgIMMA.get_imma_records(line, cdate, records)
113
+ records = PgIMMA.get_imma_records(cdate, line, records)
107
114
  break
108
115
  line = IMMA.readline()
109
116
 
110
117
  line = IMMA.readline()
111
118
  while line:
112
119
  if PVALS['uatti'] and line[0:2] == PVALS['uatti']:
113
- records = PgIMMA.get_imma_multiple_records(line, records)
120
+ records = PgIMMA.get_imma_multiple_records(cdate, line, records)
114
121
  else:
115
122
  idate = PgIMMA.get_imma_date(line)
116
123
  if idate:
@@ -120,7 +127,7 @@ def process_imma_file(fname, addinventory):
120
127
  records = {}
121
128
  cdate = idate
122
129
  PgIMMA.init_indices_for_date(cdate, iname)
123
- records = PgIMMA.get_imma_records(line, idate, records)
130
+ records = PgIMMA.get_imma_records(idate, line, records)
124
131
  line = IMMA.readline()
125
132
 
126
133
  IMMA.close()
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: rda_python_icoads
3
- Version: 1.0.10
3
+ Version: 1.0.11
4
4
  Summary: RDA python package to manage RDA ICOADS datasets
5
5
  Author-email: Zaihua Ji <zji@ucar.edu>
6
6
  Project-URL: Homepage, https://github.com/NCAR/rda-python-icoads
@@ -12,6 +12,7 @@ Requires-Python: >=3.7
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
14
  Requires-Dist: rda_python_common
15
+ Dynamic: license-file
15
16
 
16
17
  RDA python package to manage RDA ICOADS datasets.
17
18