-
Notifications
You must be signed in to change notification settings - Fork 303
/
mfstructure.py
2502 lines (2285 loc) · 91 KB
/
mfstructure.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
mfstructure module. Contains classes related to package structure
"""
import os
import traceback
import ast
import keyword
from enum import Enum
from textwrap import TextWrapper
import numpy as np
from ..mfbase import PackageContainer, StructException
numeric_index_text = (
"This argument is an index variable, which means that "
"it should be treated as zero-based when working with "
"FloPy and Python. Flopy will automatically subtract "
"one when loading index variables and add one when "
"writing index variables."
)
class DfnType(Enum):
common = 1
sim_name_file = 2
sim_tdis_file = 3
ims_file = 4
exch_file = 5
model_name_file = 6
model_file = 7
gnc_file = 8
mvr_file = 9
utl = 10
unknown = 999
class Dfn:
"""
Base class for package file definitions
Attributes
----------
dfndir : path
folder containing package definition files (dfn)
common : path
file containing common information
multi_package : dict
contains the names of all packages that are allowed to have multiple
instances in a model/simulation
Methods
-------
get_file_list : () : list
returns all of the dfn files found in dfndir. files are returned in
a specified order defined in the local variable file_order
See Also
--------
Notes
-----
Examples
----
"""
def __init__(self):
# directories
self.dfndir = os.path.join(".", "dfn")
self.common = os.path.join(self.dfndir, "common.dfn")
# FIX: Transport - multi packages are hard coded
self.multi_package = {
"exggwfgwf": 0,
"gwfchd": 0,
"gwfwel": 0,
"gwfdrn": 0,
"gwfriv": 0,
"gwfghb": 0,
"gwfrch": 0,
"gwfrcha": 0,
"gwfevt": 0,
"gwfevta": 0,
"gwfmaw": 0,
"gwfsfr": 0,
"gwflak": 0,
"gwfuzf": 0,
"lnfcgeo": 0,
"lnfrgeo": 0,
"lnfngeo": 0,
"utlobs": 0,
"utlts": 0,
"utltas": 0,
"utlspc": 0,
"utlspca": 0,
}
def get_file_list(self):
file_order = [
"sim-nam", # dfn completed tex updated
"sim-tdis", # dfn completed tex updated
"exg-gwfgwf", # dfn completed tex updated
"sln-ims", # dfn completed tex updated
"gwf-nam", # dfn completed tex updated
"gwf-dis", # dfn completed tex updated
"gwf-disv", # dfn completed tex updated
"gwf-disu", # dfn completed tex updated
"lnf-disl", # dfn completed tex updated
"gwf-ic", # dfn completed tex updated
"gwf-npf", # dfn completed tex updated
"gwf-sto", # dfn completed tex updated
"gwf-hfb", # dfn completed tex updated
"gwf-chd", # dfn completed tex updated
"gwf-wel", # dfn completed tex updated
"gwf-drn", # dfn completed tex updated
"gwf-riv", # dfn completed tex updated
"gwf-ghb", # dfn completed tex updated
"gwf-rch", # dfn completed tex updated
"gwf-rcha", # dfn completed tex updated
"gwf-evt", # dfn completed tex updated
"gwf-evta", # dfn completed tex updated
"gwf-maw", # dfn completed tex updated
"gwf-sfr", # dfn completed tex updated
"gwf-lak", # dfn completed tex updated
"gwf-uzf", # dfn completed tex updated
"gwf-mvr", # dfn completed tex updated
"gwf-gnc", # dfn completed tex updated
"gwf-oc", # dfn completed tex updated
"utl-obs",
"utl-ts",
"utl-tab",
"utl-tas",
]
dfn_path, tail = os.path.split(os.path.realpath(__file__))
dfn_path = os.path.join(dfn_path, "dfn")
# construct list of dfn files to process in the order of file_order
files = os.listdir(dfn_path)
for f in files:
if "common" in f or "flopy" in f:
continue
package_abbr = os.path.splitext(f)[0]
if package_abbr not in file_order:
file_order.append(package_abbr)
return [
f"{fname}.dfn" for fname in file_order if f"{fname}.dfn" in files
]
def _file_type(self, file_name):
# determine file type
if len(file_name) >= 6 and file_name[0:6] == "common":
return DfnType.common, None
elif file_name[0:3] == "sim":
if file_name[3:6] == "nam":
return DfnType.sim_name_file, None
elif file_name[3:7] == "tdis":
return DfnType.sim_tdis_file, None
else:
return DfnType.unknown, None
elif file_name[0:3] == "nam":
return DfnType.sim_name_file, None
elif file_name[0:4] == "tdis":
return DfnType.sim_tdis_file, None
elif file_name[0:3] == "sln" or file_name[0:3] == "ims":
return DfnType.ims_file, None
elif file_name[0:3] == "exg":
return DfnType.exch_file, file_name[3:6]
elif file_name[0:3] == "utl":
return DfnType.utl, None
else:
model_type = file_name[0:3]
if file_name[3:6] == "nam":
return DfnType.model_name_file, model_type
elif file_name[3:6] == "gnc":
return DfnType.gnc_file, model_type
elif file_name[3:6] == "mvr":
return DfnType.mvr_file, model_type
else:
return DfnType.model_file, model_type
class DfnPackage(Dfn):
"""
Dfn child class that loads dfn information from a list structure stored
in the auto-built package classes
Attributes
----------
package : MFPackage
MFPackage subclass that contains dfn information
Methods
-------
multi_package_support : () : bool
returns flag for multi-package support
get_block_structure_dict : (path : tuple, common : bool, model_file :
bool) : dict
returns a dictionary of block structure information for the package
See Also
--------
Notes
-----
Examples
----
"""
def __init__(self, package):
super().__init__()
self.package = package
self.package_type = package._package_type
self.dfn_file_name = package.dfn_file_name
# the package type is always the text after the last -
package_name = self.package_type.split("-")
self.package_type = package_name[-1]
if not isinstance(package_name, str) and len(package_name) > 1:
self.package_prefix = "".join(package_name[:-1])
else:
self.package_prefix = ""
self.dfn_type, self.model_type = self._file_type(
self.dfn_file_name.replace("-", "")
)
self.dfn_list = package.dfn
def multi_package_support(self):
return self.package.package_abbr in self.multi_package
def get_block_structure_dict(self, path, common, model_file):
block_dict = {}
dataset_items_in_block = {}
self.dataset_items_needed_dict = {}
keystring_items_needed_dict = {}
current_block = None
for dfn_entry in self.dfn_list:
# load next data item
new_data_item_struct = MFDataItemStructure()
for next_line in dfn_entry:
new_data_item_struct.set_value(next_line, common)
# if block does not exist
if (
current_block is None
or current_block.name != new_data_item_struct.block_name
):
# create block
current_block = MFBlockStructure(
new_data_item_struct.block_name, path, model_file
)
# put block in block_dict
block_dict[current_block.name] = current_block
# init dataset item lookup
self.dataset_items_needed_dict = {}
dataset_items_in_block = {}
# resolve block type
if len(current_block.block_header_structure) > 0:
if (
len(
current_block.block_header_structure[
0
].data_item_structures
)
> 0
and current_block.block_header_structure[0]
.data_item_structures[0]
.type
== DatumType.integer
):
block_type = BlockType.transient
else:
block_type = BlockType.multiple
else:
block_type = BlockType.single
if new_data_item_struct.block_variable:
block_dataset_struct = MFDataStructure(
new_data_item_struct,
model_file,
self.package_type,
self.dfn_list,
)
block_dataset_struct.parent_block = current_block
self._process_needed_data_items(
block_dataset_struct, dataset_items_in_block
)
block_dataset_struct.set_path(
path + (new_data_item_struct.block_name,)
)
block_dataset_struct.add_item(new_data_item_struct)
current_block.add_dataset(block_dataset_struct)
else:
new_data_item_struct.block_type = block_type
dataset_items_in_block[
new_data_item_struct.name
] = new_data_item_struct
# if data item belongs to existing dataset(s)
item_location_found = False
if new_data_item_struct.name in self.dataset_items_needed_dict:
if new_data_item_struct.type == DatumType.record:
# record within a record - create a data set in
# place of the data item
new_data_item_struct = self._new_dataset(
new_data_item_struct,
current_block,
dataset_items_in_block,
path,
model_file,
False,
)
new_data_item_struct.record_within_record = True
for dataset in self.dataset_items_needed_dict[
new_data_item_struct.name
]:
item_added = dataset.add_item(
new_data_item_struct, record=True
)
item_location_found = item_location_found or item_added
# if data item belongs to an existing keystring
if new_data_item_struct.name in keystring_items_needed_dict:
new_data_item_struct.set_path(
keystring_items_needed_dict[
new_data_item_struct.name
].path
)
if new_data_item_struct.type == DatumType.record:
# record within a keystring - create a data set in
# place of the data item
new_data_item_struct = self._new_dataset(
new_data_item_struct,
current_block,
dataset_items_in_block,
path,
model_file,
False,
)
keystring_items_needed_dict[
new_data_item_struct.name
].keystring_dict[
new_data_item_struct.name
] = new_data_item_struct
item_location_found = True
if new_data_item_struct.type == DatumType.keystring:
# add keystrings to search list
for (
key,
val,
) in new_data_item_struct.keystring_dict.items():
keystring_items_needed_dict[key] = new_data_item_struct
# if data set does not exist
if not item_location_found:
self._new_dataset(
new_data_item_struct,
current_block,
dataset_items_in_block,
path,
model_file,
True,
)
if (
current_block.name.upper() == "SOLUTIONGROUP"
and len(current_block.block_header_structure) == 0
):
# solution_group a special case for now
block_data_item_struct = MFDataItemStructure()
block_data_item_struct.name = "order_num"
block_data_item_struct.data_items = ["order_num"]
block_data_item_struct.type = DatumType.integer
block_data_item_struct.longname = "order_num"
block_data_item_struct.description = (
"internal variable to keep track of "
"solution group number"
)
block_dataset_struct = MFDataStructure(
block_data_item_struct,
model_file,
self.package_type,
self.dfn_list,
)
block_dataset_struct.parent_block = current_block
block_dataset_struct.set_path(
path + (new_data_item_struct.block_name,)
)
block_dataset_struct.add_item(block_data_item_struct)
current_block.add_dataset(block_dataset_struct)
return block_dict
def _new_dataset(
self,
new_data_item_struct,
current_block,
dataset_items_in_block,
path,
model_file,
add_to_block=True,
):
current_dataset_struct = MFDataStructure(
new_data_item_struct, model_file, self.package_type, self.dfn_list
)
current_dataset_struct.set_path(
path + (new_data_item_struct.block_name,)
)
self._process_needed_data_items(
current_dataset_struct, dataset_items_in_block
)
if add_to_block:
# add dataset
current_block.add_dataset(current_dataset_struct)
current_dataset_struct.parent_block = current_block
current_dataset_struct.add_item(new_data_item_struct)
return current_dataset_struct
def _process_needed_data_items(
self, current_dataset_struct, dataset_items_in_block
):
# add data items needed to dictionary
for (
item_name,
val,
) in current_dataset_struct.expected_data_items.items():
if item_name in dataset_items_in_block:
current_dataset_struct.add_item(
dataset_items_in_block[item_name]
)
else:
if item_name in self.dataset_items_needed_dict:
self.dataset_items_needed_dict[item_name].append(
current_dataset_struct
)
else:
self.dataset_items_needed_dict[item_name] = [
current_dataset_struct
]
class DfnFile(Dfn):
"""
Dfn child class that loads dfn information from a package definition (dfn)
file
Attributes
----------
file : str
name of the file to be loaded
Methods
-------
multi_package_support : () : bool
returns flag for multi-package support
dict_by_name : {} : dict
returns a dictionary of data item descriptions from the dfn file with
the data item name as the dictionary key
get_block_structure_dict : (path : tuple, common : bool, model_file :
bool) : dict
returns a dictionary of block structure information for the package
See Also
--------
Notes
-----
Examples
----
"""
def __init__(self, file):
super().__init__()
dfn_path, tail = os.path.split(os.path.realpath(__file__))
dfn_path = os.path.join(dfn_path, "dfn")
self._file_path = os.path.join(dfn_path, file)
self.dfn_file_name = file
self.dfn_type, self.model_type = self._file_type(
self.dfn_file_name.replace("-", "")
)
self.package_type = os.path.splitext(file[4:])[0]
# the package type is always the text after the last -
package_name = self.package_type.split("-")
self.package_type = package_name[-1]
if not isinstance(package_name, str) and len(package_name) > 1:
self.package_prefix = "".join(package_name[:-1])
else:
self.package_prefix = ""
self.file = file
self.dataset_items_needed_dict = {}
self.dfn_list = []
def multi_package_support(self):
base_file = os.path.splitext(self.file)[0]
base_file = base_file.replace("-", "")
return base_file in self.multi_package
def dict_by_name(self):
name_dict = {}
name = None
dfn_fp = open(self._file_path, "r")
for line in dfn_fp:
if self._valid_line(line):
arr_line = line.strip().split()
if arr_line[0] == "name":
name = arr_line[1]
elif arr_line[0] == "description" and name is not None:
name_dict[name] = " ".join(arr_line[1:])
dfn_fp.close()
return name_dict
def get_block_structure_dict(self, path, common, model_file):
self.dfn_list = []
block_dict = {}
dataset_items_in_block = {}
self.dataset_items_needed_dict = {}
keystring_items_needed_dict = {}
current_block = None
dfn_fp = open(self._file_path, "r")
for line in dfn_fp:
if self._valid_line(line):
# load next data item
new_data_item_struct = MFDataItemStructure()
new_data_item_struct.set_value(line, common)
self.dfn_list.append([line])
for next_line in dfn_fp:
if self._empty_line(next_line):
break
if self._valid_line(next_line):
new_data_item_struct.set_value(next_line, common)
self.dfn_list[-1].append(next_line)
# if block does not exist
if (
current_block is None
or current_block.name != new_data_item_struct.block_name
):
# create block
current_block = MFBlockStructure(
new_data_item_struct.block_name, path, model_file
)
# put block in block_dict
block_dict[current_block.name] = current_block
# init dataset item lookup
self.dataset_items_needed_dict = {}
dataset_items_in_block = {}
# resolve block type
if len(current_block.block_header_structure) > 0:
if (
len(
current_block.block_header_structure[
0
].data_item_structures
)
> 0
and current_block.block_header_structure[0]
.data_item_structures[0]
.type
== DatumType.integer
):
block_type = BlockType.transient
else:
block_type = BlockType.multiple
else:
block_type = BlockType.single
if new_data_item_struct.block_variable:
block_dataset_struct = MFDataStructure(
new_data_item_struct,
model_file,
self.package_type,
self.dfn_list,
)
block_dataset_struct.parent_block = current_block
self._process_needed_data_items(
block_dataset_struct, dataset_items_in_block
)
block_dataset_struct.set_path(
path + (new_data_item_struct.block_name,)
)
block_dataset_struct.add_item(
new_data_item_struct, False, self.dfn_list
)
current_block.add_dataset(block_dataset_struct)
else:
new_data_item_struct.block_type = block_type
dataset_items_in_block[
new_data_item_struct.name
] = new_data_item_struct
# if data item belongs to existing dataset(s)
item_location_found = False
if (
new_data_item_struct.name
in self.dataset_items_needed_dict
):
if new_data_item_struct.type == DatumType.record:
# record within a record - create a data set in
# place of the data item
new_data_item_struct = self._new_dataset(
new_data_item_struct,
current_block,
dataset_items_in_block,
path,
model_file,
False,
)
new_data_item_struct.record_within_record = True
for dataset in self.dataset_items_needed_dict[
new_data_item_struct.name
]:
item_added = dataset.add_item(
new_data_item_struct, True, self.dfn_list
)
item_location_found = (
item_location_found or item_added
)
# if data item belongs to an existing keystring
if (
new_data_item_struct.name
in keystring_items_needed_dict
):
new_data_item_struct.set_path(
keystring_items_needed_dict[
new_data_item_struct.name
].path
)
if new_data_item_struct.type == DatumType.record:
# record within a keystring - create a data set in
# place of the data item
new_data_item_struct = self._new_dataset(
new_data_item_struct,
current_block,
dataset_items_in_block,
path,
model_file,
False,
)
keystring_items_needed_dict[
new_data_item_struct.name
].keystring_dict[
new_data_item_struct.name
] = new_data_item_struct
item_location_found = True
if new_data_item_struct.type == DatumType.keystring:
# add keystrings to search list
for (
key,
val,
) in new_data_item_struct.keystring_dict.items():
keystring_items_needed_dict[
key
] = new_data_item_struct
# if data set does not exist
if not item_location_found:
self._new_dataset(
new_data_item_struct,
current_block,
dataset_items_in_block,
path,
model_file,
True,
)
if (
current_block.name.upper() == "SOLUTIONGROUP"
and len(current_block.block_header_structure) == 0
):
# solution_group a special case for now
block_data_item_struct = MFDataItemStructure()
block_data_item_struct.name = "order_num"
block_data_item_struct.data_items = ["order_num"]
block_data_item_struct.type = DatumType.integer
block_data_item_struct.longname = "order_num"
block_data_item_struct.description = (
"internal variable to keep track of "
"solution group number"
)
block_dataset_struct = MFDataStructure(
block_data_item_struct,
model_file,
self.package_type,
self.dfn_list,
)
block_dataset_struct.parent_block = current_block
block_dataset_struct.set_path(
path + (new_data_item_struct.block_name,)
)
block_dataset_struct.add_item(
block_data_item_struct, False, self.dfn_list
)
current_block.add_dataset(block_dataset_struct)
dfn_fp.close()
return block_dict
def _new_dataset(
self,
new_data_item_struct,
current_block,
dataset_items_in_block,
path,
model_file,
add_to_block=True,
):
current_dataset_struct = MFDataStructure(
new_data_item_struct, model_file, self.package_type, self.dfn_list
)
current_dataset_struct.set_path(
path + (new_data_item_struct.block_name,)
)
self._process_needed_data_items(
current_dataset_struct, dataset_items_in_block
)
if add_to_block:
# add dataset
current_block.add_dataset(current_dataset_struct)
current_dataset_struct.parent_block = current_block
current_dataset_struct.add_item(
new_data_item_struct, False, self.dfn_list
)
return current_dataset_struct
def _process_needed_data_items(
self, current_dataset_struct, dataset_items_in_block
):
# add data items needed to dictionary
for (
item_name,
val,
) in current_dataset_struct.expected_data_items.items():
if item_name in dataset_items_in_block:
current_dataset_struct.add_item(
dataset_items_in_block[item_name], False, self.dfn_list
)
else:
if item_name in self.dataset_items_needed_dict:
self.dataset_items_needed_dict[item_name].append(
current_dataset_struct
)
else:
self.dataset_items_needed_dict[item_name] = [
current_dataset_struct
]
def _valid_line(self, line):
if len(line.strip()) > 1 and line[0] != "#":
return True
return False
def _empty_line(self, line):
if len(line.strip()) <= 1:
return True
return False
class DataType(Enum):
"""
Types of data that can be found in a package file
"""
scalar_keyword = 1
scalar = 2
array = 3
array_transient = 4
list = 5
list_transient = 6
list_multiple = 7
scalar_transient = 8
scalar_keyword_transient = 9
class DatumType(Enum):
"""
Types of individual pieces of data
"""
keyword = 1
integer = 2
double_precision = 3
string = 4
constant = 5
list_defined = 6
keystring = 7
record = 8
repeating_record = 9
recarray = 10
class BlockType(Enum):
"""
Types of blocks that can be found in a package file
"""
single = 1
multiple = 2
transient = 3
class MFDataItemStructure:
"""
Defines the structure of a single MF6 data item in a dfn file
Attributes
----------
block_name : str
name of block that data item is in
name : str
name of data item
name_list : list
list of alternate names for the data item, includes data item's main
name "name"
python_name : str
name of data item referenced in python, with illegal python characters
removed
type : str
type of the data item as it appears in the dfn file
type_obj : python type
type of the data item as a python type
valid_values : list
list of valid values for the data item. if empty, this constraint does
not apply
data_items : list
list of data items contained in this data_item, including itself
in_record : bool
in_record attribute as appears in dfn file
tagged : bool
whether data item is tagged. if the data item is tagged its name is
included in the MF6 input file
just_data : bool
when just_data is true only data appears in the MF6 input file.
otherwise, name information appears
shape : list
describes the shape of the data
layer_dims : list
which dimensions in the shape function as layers, if None defaults to
"layer"
reader : basestring
reader that MF6 uses to read the data
optional : bool
whether data item is optional or required as part of the MFData in the
MF6 input file
longname : str
long name of the data item
description : str
description of the data item
path : tuple
a tuple describing the data item's location within the simulation
(<model>,<package>,<block>,<data>)
repeating : bool
whether or not the data item can repeat in the MF6 input file
block_variable : bool
if true, this data item is part of the block header
block_type : BlockType
whether the block containing this item is a single non-repeating block,
a multiple repeating block, or a transient repeating block
keystring_dict : dict
dictionary containing acceptable keystrings if this data item is of
type keystring
is_cellid : bool
true if this data item is definitely of type cellid
possible_cellid : bool
true if this data item may be of type cellid
ucase : bool
this data item must be displayed in upper case in the MF6 input file
Methods
-------
remove_cellid : (resolved_shape : list, cellid_size : int)
removes the cellid size from the shape of a data item
set_path : (path : tuple)
sets the path to this data item to path
get_rec_type : () : object type
gets the type of object of this data item to be used in a numpy
recarray
See Also
--------
Notes
-----
Examples
--------
"""
def __init__(self):
self.file_name_keywords = {"filein": False, "fileout": False}
self.file_name_key_seq = {"fname": True}
self.contained_keywords = {"fname": True, "file": True, "tdis6": True}
self.block_name = None
self.name = None
self.display_name = None
self.name_length = None
self.is_aux = False
self.is_boundname = False
self.is_mname = False
self.name_list = []
self.python_name = None
self.type = None
self.type_string = None
self.type_obj = None
self.valid_values = []
self.data_items = None
self.in_record = False
self.tagged = True
self.just_data = False
self.shape = []
self.layer_dims = ["nlay"]
self.reader = None
self.optional = False
self.longname = None
self.description = ""
self.path = None
self.repeating = False
self.block_variable = False
self.block_type = BlockType.single
self.keystring_dict = {}
self.is_cellid = False
self.possible_cellid = False
self.ucase = False
self.preserve_case = False
self.default_value = None
self.numeric_index = False
self.support_negative_index = False
self.construct_package = None
self.construct_data = None
self.parameter_name = None
self.one_per_pkg = False
self.jagged_array = None
def set_value(self, line, common):
arr_line = line.strip().split()
if len(arr_line) > 1:
if arr_line[0] == "block":
self.block_name = " ".join(arr_line[1:])
elif arr_line[0] == "name":
if self.type == DatumType.keyword:
# display keyword names in upper case
self.display_name = " ".join(arr_line[1:]).upper()
else:
self.display_name = " ".join(arr_line[1:]).lower()
self.name = " ".join(arr_line[1:]).lower()
self.name_list.append(self.name)
if len(self.name) >= 6 and self.name[0:6] == "cellid":
self.is_cellid = True
if self.name and self.name[0:2] == "id":
self.possible_cellid = True
self.python_name = self.name.replace("-", "_").lower()
# don't allow name to be a python keyword
if keyword.iskeyword(self.name):
self.python_name = f"{self.python_name}_"
# performance optimizations
if self.name == "aux":
self.is_aux = True
if self.name == "boundname":
self.is_boundname = True
if self.name[0:5] == "mname":
self.is_mname = True
self.name_length = len(self.name)
elif arr_line[0] == "other_names":
arr_names = " ".join(arr_line[1:]).lower().split(",")
for name in arr_names:
self.name_list.append(name)
elif arr_line[0] == "type":
if self.support_negative_index:
# type already automatically set when
# support_negative_index flag is set
return
type_line = arr_line[1:]
if len(type_line) <= 0:
raise StructException(
'Data structure "{}" does not have '
"a type specified"
".".format(self.name),
self.path,
)
self.type_string = type_line[0].lower()
self.type = self._str_to_enum_type(type_line[0])
if (
self.type == DatumType.recarray
or self.type == DatumType.record
or self.type == DatumType.repeating_record
or self.type == DatumType.keystring
):
self.data_items = type_line[1:]
if self.type == DatumType.keystring:
for item in self.data_items:
self.keystring_dict[item.lower()] = 0
else:
self.data_items = [self.name]
self.type_obj = self._get_type()
if self.type == DatumType.keyword:
# display keyword names in upper case
if self.display_name is not None: