diff --git a/.basedpyright/baseline.json b/.basedpyright/baseline.json index 20facb1c..4376065f 100644 --- a/.basedpyright/baseline.json +++ b/.basedpyright/baseline.json @@ -13687,43 +13687,19 @@ "lineCount": 1 } }, - { - "code": "reportUnannotatedClassAttribute", - "range": { - "startColumn": 13, - "endColumn": 14, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { - "startColumn": 8, - "endColumn": 23, - "lineCount": 1 - } - }, - { - "code": "reportUnannotatedClassAttribute", - "range": { - "startColumn": 13, - "endColumn": 23, + "startColumn": 24, + "endColumn": 50, "lineCount": 1 } }, { "code": "reportUnknownMemberType", "range": { - "startColumn": 8, - "endColumn": 24, - "lineCount": 1 - } - }, - { - "code": "reportUnannotatedClassAttribute", - "range": { - "startColumn": 13, - "endColumn": 24, + "startColumn": 25, + "endColumn": 52, "lineCount": 1 } }, @@ -13735,22 +13711,6 @@ "lineCount": 3 } }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 8, - "endColumn": 27, - "lineCount": 1 - } - }, - { - "code": "reportUnannotatedClassAttribute", - "range": { - "startColumn": 13, - "endColumn": 27, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { @@ -13759,59 +13719,27 @@ "lineCount": 1 } }, - { - "code": "reportUnannotatedClassAttribute", - "range": { - "startColumn": 13, - "endColumn": 20, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 20, - "endColumn": 35, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 22, - "endColumn": 37, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 22, - "endColumn": 37, - "lineCount": 1 - } - }, { "code": "reportAny", "range": { - "startColumn": 8, - "endColumn": 25, + "startColumn": 15, + "endColumn": 40, "lineCount": 1 } }, { "code": "reportAny", "range": { - "startColumn": 15, - "endColumn": 40, + "startColumn": 29, + "endColumn": 39, "lineCount": 1 } }, { - "code": "reportUnknownParameterType", + "code": "reportAny", "range": { - "startColumn": 12, - "endColumn": 22, + "startColumn": 29, + "endColumn": 39, "lineCount": 1 } }, @@ -13831,30 +13759,6 @@ "lineCount": 1 } }, - { - "code": "reportReturnType", - "range": { - "startColumn": 15, - "endColumn": 70, - "lineCount": 3 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 8, - "endColumn": 15, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 11, - "endColumn": 27, - "lineCount": 1 - } - }, { "code": "reportAny", "range": { @@ -13863,14 +13767,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 30, - "endColumn": 49, - "lineCount": 1 - } - }, { "code": "reportAny", "range": { @@ -13880,15 +13776,15 @@ } }, { - "code": "reportUnknownMemberType", + "code": "reportAny", "range": { - "startColumn": 30, - "endColumn": 46, + "startColumn": 12, + "endColumn": 18, "lineCount": 1 } }, { - "code": "reportUnknownMemberType", + "code": "reportAny", "range": { "startColumn": 15, "endColumn": 29, @@ -13896,34 +13792,10 @@ } }, { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 27, - "endColumn": 34, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 27, - "endColumn": 34, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 22, - "endColumn": 37, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", + "code": "reportAny", "range": { - "startColumn": 22, - "endColumn": 37, + "startColumn": 15, + "endColumn": 33, "lineCount": 1 } }, @@ -13935,14 +13807,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 23, - "endColumn": 30, - "lineCount": 1 - } - }, { "code": "reportAny", "range": { @@ -13991,14 +13855,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 31, - "endColumn": 47, - "lineCount": 1 - } - }, { "code": "reportAny", "range": { @@ -14019,31 +13875,31 @@ "code": "reportUnknownMemberType", "range": { "startColumn": 16, - "endColumn": 33, + "endColumn": 32, "lineCount": 1 } }, { - "code": "reportUnknownMemberType", + "code": "reportReturnType", "range": { - "startColumn": 16, - "endColumn": 32, + "startColumn": 15, + "endColumn": 78, "lineCount": 1 } }, { - "code": "reportAny", + "code": "reportAssignmentType", "range": { - "startColumn": 34, - "endColumn": 46, + "startColumn": 21, + "endColumn": 49, "lineCount": 1 } }, { - "code": "reportAny", + "code": "reportReturnType", "range": { - "startColumn": 34, - "endColumn": 46, + "startColumn": 15, + "endColumn": 21, "lineCount": 1 } }, @@ -14056,34 +13912,34 @@ } }, { - "code": "reportUnknownParameterType", + "code": "reportUnknownMemberType", "range": { - "startColumn": 8, - "endColumn": 22, + "startColumn": 19, + "endColumn": 35, "lineCount": 1 } }, { - "code": "reportUnknownParameterType", + "code": "reportOperatorIssue", "range": { - "startColumn": 29, - "endColumn": 37, + "startColumn": 23, + "endColumn": 50, "lineCount": 1 } }, { - "code": "reportMissingParameterType", + "code": "reportUnknownMemberType", "range": { - "startColumn": 29, - "endColumn": 37, + "startColumn": 15, + "endColumn": 28, "lineCount": 1 } }, { - "code": "reportUnknownMemberType", + "code": "reportReturnType", "range": { - "startColumn": 19, - "endColumn": 35, + "startColumn": 15, + "endColumn": 23, "lineCount": 1 } }, @@ -14112,127 +13968,47 @@ } }, { - "code": "reportUnknownParameterType", + "code": "reportArgumentType", "range": { - "startColumn": 19, - "endColumn": 22, + "startColumn": 31, + "endColumn": 34, "lineCount": 1 } }, { - "code": "reportMissingParameterType", + "code": "reportUnknownMemberType", "range": { - "startColumn": 19, - "endColumn": 22, + "startColumn": 8, + "endColumn": 16, "lineCount": 1 } }, { - "code": "reportUnknownParameterType", + "code": "reportAny", "range": { - "startColumn": 24, - "endColumn": 25, + "startColumn": 12, + "endColumn": 42, "lineCount": 1 } }, { - "code": "reportMissingParameterType", + "code": "reportAny", "range": { - "startColumn": 24, - "endColumn": 25, + "startColumn": 12, + "endColumn": 46, "lineCount": 1 } }, { - "code": "reportUnknownMemberType", + "code": "reportAny", "range": { - "startColumn": 15, - "endColumn": 24, + "startColumn": 12, + "endColumn": 42, "lineCount": 1 } }, { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 32, - "endColumn": 35, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 37, - "endColumn": 38, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 31, - "endColumn": 34, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 36, - "endColumn": 37, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 8, - "endColumn": 16, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 12, - "endColumn": 31, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 12, - "endColumn": 42, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 12, - "endColumn": 46, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 12, - "endColumn": 31, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 12, - "endColumn": 42, - "lineCount": 1 - } - }, - { - "code": "reportAny", + "code": "reportAny", "range": { "startColumn": 12, "endColumn": 46, @@ -14247,22 +14023,6 @@ "lineCount": 1 } }, - { - "code": "reportAny", - "range": { - "startColumn": 23, - "endColumn": 35, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 23, - "endColumn": 35, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { @@ -14271,51 +14031,11 @@ "lineCount": 1 } }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 21, - "endColumn": 36, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 38, - "endColumn": 53, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 4, - "endColumn": 5, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 4, - "endColumn": 9, - "lineCount": 1 - } - }, { "code": "reportAny", "range": { - "startColumn": 4, - "endColumn": 17, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 4, - "endColumn": 16, + "startColumn": 19, + "endColumn": 40, "lineCount": 1 } } @@ -19335,22 +19055,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 35, - "endColumn": 73, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 36, - "endColumn": 45, - "lineCount": 1 - } - }, { "code": "reportUnknownArgumentType", "range": { @@ -19383,22 +19087,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 30, - "endColumn": 52, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 30, - "endColumn": 70, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { @@ -20817,14 +20505,6 @@ "lineCount": 1 } }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 49, - "endColumn": 50, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { @@ -20833,14 +20513,6 @@ "lineCount": 1 } }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 50, - "endColumn": 53, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { @@ -20882,15 +20554,7 @@ } }, { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 51, - "endColumn": 60, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", + "code": "reportArgumentType", "range": { "startColumn": 51, "endColumn": 60, @@ -20905,22 +20569,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 19, - "endColumn": 28, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 19, - "endColumn": 34, - "lineCount": 1 - } - }, { "code": "reportUnknownArgumentType", "range": { @@ -20953,14 +20601,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 17, - "endColumn": 45, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { @@ -21009,14 +20649,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 17, - "endColumn": 45, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { @@ -21073,14 +20705,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 17, - "endColumn": 45, - "lineCount": 1 - } - }, { "code": "reportAny", "range": { @@ -21249,22 +20873,6 @@ "lineCount": 1 } }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 51, - "endColumn": 54, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 14, - "endColumn": 23, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { @@ -21362,15 +20970,7 @@ } }, { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 23, - "endColumn": 30, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", + "code": "reportUnknownMemberType", "range": { "startColumn": 35, "endColumn": 54, @@ -21393,14 +20993,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 31, - "endColumn": 38, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { @@ -21425,14 +21017,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 35, - "endColumn": 42, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { @@ -21457,14 +21041,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 39, - "endColumn": 46, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { @@ -21489,14 +21065,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 43, - "endColumn": 50, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { @@ -23318,7 +22886,7 @@ } }, { - "code": "reportAny", + "code": "reportUnknownArgumentType", "range": { "startColumn": 26, "endColumn": 40, @@ -28047,38 +27615,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 4, - "endColumn": 32, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 47, - "endColumn": 56, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 47, - "endColumn": 56, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 71, - "endColumn": 77, - "lineCount": 1 - } - }, { "code": "reportUnknownArgumentType", "range": { @@ -28167,38 +27703,6 @@ "lineCount": 1 } }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 37, - "endColumn": 45, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 25, - "endColumn": 34, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 25, - "endColumn": 34, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 8, - "endColumn": 36, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { @@ -29124,829 +28628,197 @@ ], "./sumpy/visualization.py": [ { - "code": "reportUnknownParameterType", + "code": "reportAny", "range": { - "startColumn": 4, - "endColumn": 29, + "startColumn": 12, + "endColumn": 23, "lineCount": 1 } }, { - "code": "reportUnknownParameterType", + "code": "reportAny", "range": { - "startColumn": 30, - "endColumn": 34, + "startColumn": 26, + "endColumn": 40, "lineCount": 1 } }, { - "code": "reportMissingParameterType", + "code": "reportReturnType", "range": { - "startColumn": 30, - "endColumn": 34, + "startColumn": 25, + "endColumn": 51, "lineCount": 1 } }, { - "code": "reportUnknownParameterType", + "code": "reportReturnType", "range": { - "startColumn": 36, - "endColumn": 45, + "startColumn": 32, + "endColumn": 58, "lineCount": 1 } }, { - "code": "reportMissingParameterType", + "code": "reportReturnType", "range": { - "startColumn": 36, - "endColumn": 45, + "startColumn": 32, + "endColumn": 58, "lineCount": 1 } }, { - "code": "reportUnknownMemberType", + "code": "reportAny", "range": { - "startColumn": 26, + "startColumn": 31, "endColumn": 40, "lineCount": 1 } }, { - "code": "reportUnknownMemberType", + "code": "reportAny", "range": { "startColumn": 26, - "endColumn": 37, + "endColumn": 30, "lineCount": 1 } }, { - "code": "reportUnknownMemberType", + "code": "reportAny", "range": { - "startColumn": 15, - "endColumn": 31, + "startColumn": 32, + "endColumn": 36, "lineCount": 1 } }, { "code": "reportUnknownMemberType", "range": { - "startColumn": 24, - "endColumn": 40, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 45, - "endColumn": 50, + "startColumn": 22, + "endColumn": 44, "lineCount": 1 } }, { - "code": "reportUnknownArgumentType", + "code": "reportUnknownMemberType", "range": { - "startColumn": 52, - "endColumn": 57, + "startColumn": 22, + "endColumn": 58, "lineCount": 1 } }, { - "code": "reportUnknownArgumentType", + "code": "reportAny", "range": { - "startColumn": 52, - "endColumn": 57, + "startColumn": 15, + "endColumn": 54, "lineCount": 1 } }, { - "code": "reportUnknownParameterType", + "code": "reportAny", "range": { - "startColumn": 33, - "endColumn": 37, + "startColumn": 8, + "endColumn": 33, "lineCount": 1 } }, { - "code": "reportMissingParameterType", + "code": "reportAny", "range": { - "startColumn": 33, - "endColumn": 37, + "startColumn": 14, + "endColumn": 20, "lineCount": 1 } }, { - "code": "reportUnknownParameterType", + "code": "reportUnknownMemberType", "range": { - "startColumn": 39, - "endColumn": 40, + "startColumn": 18, + "endColumn": 29, "lineCount": 1 } }, { - "code": "reportMissingParameterType", + "code": "reportAny", "range": { - "startColumn": 39, - "endColumn": 40, + "startColumn": 15, + "endColumn": 63, "lineCount": 1 } }, { - "code": "reportMissingParameterType", + "code": "reportUnknownMemberType", "range": { - "startColumn": 42, - "endColumn": 55, + "startColumn": 38, + "endColumn": 52, "lineCount": 1 } }, { - "code": "reportUnknownArgumentType", + "code": "reportUnknownMemberType", "range": { - "startColumn": 21, - "endColumn": 27, + "startColumn": 8, + "endColumn": 15, "lineCount": 1 } }, { - "code": "reportUnknownArgumentType", + "code": "reportUnknownMemberType", "range": { - "startColumn": 15, - "endColumn": 16, + "startColumn": 8, + "endColumn": 15, "lineCount": 1 } }, { - "code": "reportUnknownArgumentType", + "code": "reportAny", "range": { - "startColumn": 20, - "endColumn": 69, + "startColumn": 14, + "endColumn": 20, "lineCount": 1 } }, { - "code": "reportUnknownArgumentType", + "code": "reportMissingImports", "range": { - "startColumn": 25, - "endColumn": 41, + "startColumn": 13, + "endColumn": 19, "lineCount": 1 } }, { - "code": "reportUnknownArgumentType", + "code": "reportUnknownMemberType", "range": { - "startColumn": 24, - "endColumn": 30, + "startColumn": 8, + "endColumn": 21, "lineCount": 1 } }, { - "code": "reportUnknownArgumentType", + "code": "reportUnknownMemberType", "range": { - "startColumn": 32, - "endColumn": 38, + "startColumn": 12, + "endColumn": 21, "lineCount": 1 } }, { - "code": "reportArgumentType", + "code": "reportAny", "range": { - "startColumn": 40, - "endColumn": 47, + "startColumn": 14, + "endColumn": 20, "lineCount": 1 } }, { - "code": "reportUnknownParameterType", + "code": "reportUnknownMemberType", "range": { - "startColumn": 23, + "startColumn": 18, "endColumn": 29, "lineCount": 1 } }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 23, - "endColumn": 29, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 31, - "endColumn": 37, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 41, - "endColumn": 48, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 28, - "endColumn": 34, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 8, - "endColumn": 23, - "lineCount": 1 - } - }, - { - "code": "reportUnannotatedClassAttribute", - "range": { - "startColumn": 13, - "endColumn": 23, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 27, - "endColumn": 30, - "lineCount": 1 - } - }, - { - "code": "reportUnannotatedClassAttribute", - "range": { - "startColumn": 13, - "endColumn": 14, - "lineCount": 1 - } - }, - { - "code": "reportUnannotatedClassAttribute", - "range": { - "startColumn": 13, - "endColumn": 14, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 12, - "endColumn": 19, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 19, - "endColumn": 26, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 23, - "endColumn": 26, - "lineCount": 1 - } - }, - { - "code": "reportIndexIssue", - "range": { - "startColumn": 15, - "endColumn": 22, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 22, - "endColumn": 26, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 28, - "endColumn": 32, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 34, - "endColumn": 47, - "lineCount": 1 - } - }, - { - "code": "reportIndexIssue", - "range": { - "startColumn": 37, - "endColumn": 44, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 31, - "endColumn": 34, - "lineCount": 1 - } - }, - { - "code": "reportUnannotatedClassAttribute", - "range": { - "startColumn": 13, - "endColumn": 22, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 8, - "endColumn": 19, - "lineCount": 1 - } - }, - { - "code": "reportUnannotatedClassAttribute", - "range": { - "startColumn": 13, - "endColumn": 19, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 22, - "endColumn": 44, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 22, - "endColumn": 58, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 45, - "endColumn": 48, - "lineCount": 1 - } - }, - { - "code": "reportUnannotatedClassAttribute", - "range": { - "startColumn": 13, - "endColumn": 20, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 31, - "endColumn": 38, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 8, - "endColumn": 28, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 15, - "endColumn": 54, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 8, - "endColumn": 20, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 8, - "endColumn": 33, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 40, - "endColumn": 43, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 40, - "endColumn": 43, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 45, - "endColumn": 52, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 45, - "endColumn": 52, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 12, - "endColumn": 21, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 34, - "endColumn": 40, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 34, - "endColumn": 40, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 26, - "endColumn": 37, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 26, - "endColumn": 45, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 15, - "endColumn": 36, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 15, - "endColumn": 36, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 15, - "endColumn": 24, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 15, - "endColumn": 24, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 18, - "endColumn": 29, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 23, - "endColumn": 34, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 15, - "endColumn": 63, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 38, - "endColumn": 52, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 8, - "endColumn": 15, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 8, - "endColumn": 15, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 36, - "endColumn": 39, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 36, - "endColumn": 39, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 41, - "endColumn": 48, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 57, - "endColumn": 63, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 57, - "endColumn": 63, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 12, - "endColumn": 23, - "lineCount": 1 - } - }, - { - "code": "reportMissingImports", - "range": { - "startColumn": 13, - "endColumn": 19, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 8, - "endColumn": 21, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 12, - "endColumn": 21, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 29, - "endColumn": 38, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 29, - "endColumn": 38, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 40, - "endColumn": 44, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 40, - "endColumn": 44, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 46, - "endColumn": 55, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 63, - "endColumn": 72, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 30, - "endColumn": 39, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 27, - "endColumn": 75, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 32, - "endColumn": 74, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 58, - "endColumn": 62, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 36, - "endColumn": 39, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 36, - "endColumn": 39, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 41, - "endColumn": 48, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 41, - "endColumn": 48, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 57, - "endColumn": 63, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 57, - "endColumn": 63, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 15, - "endColumn": 24, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 15, - "endColumn": 24, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 18, - "endColumn": 29, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 23, - "endColumn": 34, - "lineCount": 1 - } - }, { "code": "reportMissingImports", "range": { diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f3dd2f1..a22d16eb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,7 +42,7 @@ jobs: curl -L -O https://tiker.net/ci-support-v0 . ./ci-support-v0 build_py_project_in_conda_env - cipip install pytest pyfmmlib scipy scipy-stubs matplotlib pyvisfile + cipip install pytest pyfmmlib scipy scipy-stubs matplotlib pyvisfile optype cipip install basedpyright basedpyright diff --git a/doc/conf.py b/doc/conf.py index 21e6be08..8f13feca 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -27,12 +27,16 @@ nitpick_ignore_regex = [ ["py:class", r"symengine\.(.+)"], # :cry: ["py:class", r"ToTagSetConvertible"], # :cry: + # NOTE: optype does not have Sphinx compatible documentation + ["py:class", r"op.*"], + ["py:class", r"onp.*"], ] sphinxconfig_missing_reference_aliases = { # numpy "Array1D": "class:numpy.ndarray", "Array2D": "class:numpy.ndarray", + "ArrayND": "class:numpy.ndarray", "np.floating": "class:numpy.floating", "np.complexfloating": "class:numpy.complexfloating", "np.inexact": "class:numpy.inexact", diff --git a/sumpy/point_calculus.py b/sumpy/point_calculus.py index 2309b2e6..a83eef26 100644 --- a/sumpy/point_calculus.py +++ b/sumpy/point_calculus.py @@ -22,24 +22,27 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -from typing import TYPE_CHECKING, Literal, TypeAlias +from typing import TYPE_CHECKING, Any, Literal, TypeAlias, TypeVar, overload import numpy as np import numpy.linalg as la from pytools import memoize_method, obj_array +from sumpy.visualization import FieldPlotter + if TYPE_CHECKING: from collections.abc import Callable, Sequence - from optype.numpy import Array1D, Array2D + from optype.numpy import Array1D, Array2D, ArrayND __doc__ = """ .. autodata:: NodesKind :noindex: +.. autoclass:: InexactT .. class:: NodesKind .. autoclass:: CalculusPatch @@ -48,6 +51,7 @@ """ +InexactT = TypeVar("InexactT", bound=np.inexact[Any]) NodesKind: TypeAlias = Literal["chebyshev", "equispaced", "legendre"] @@ -55,14 +59,14 @@ class CalculusPatch: """Sets up a grid of points on which derivatives can be calculated. Useful to verify that an evaluated potential actually solves a PDE. - .. attribute:: dim - - .. attribute:: points - - shape: ``(dim, npoints_total)`` + .. autoattribute:: dim + .. autoattribute:: npoints + .. autoattribute:: points + .. autoattribute:: center .. automethod:: weights .. automethod:: basis + .. automethod:: diff .. automethod:: dx .. automethod:: dy @@ -71,40 +75,52 @@ class CalculusPatch: .. automethod:: div .. automethod:: curl .. automethod:: eval_at_center - .. autoattribute:: x - .. autoattribute:: y - .. autoattribute:: z + + .. autoproperty:: x + .. autoproperty:: y + .. autoproperty:: z + .. automethod:: norm .. automethod:: plot_nodes .. automethod:: plot """ + dim: int - center: Array1D[np.floating] - points: Array2D[np.floating] npoints: int + points: Array2D[np.floating[Any]] + """Shape: ``(dim, npoints)``.""" + center: Array1D[np.floating[Any]] + + h: float + _points_1d: Array1D[np.floating[Any]] + _weights_1d: Array1D[np.floating[Any]] | None + _points_shaped: ArrayND[np.floating[Any]] + """An array of shape ``(dim, nnodes, ...)``.""" + _pshape: tuple[int, ...] def __init__(self, - center: Array1D[np.floating], + center: Array1D[np.floating[Any]], h: float = 1e-1, order: int = 4, - nodes: NodesKind = "chebyshev"): + nodes: NodesKind = "chebyshev") -> None: self.center = center + dtype = center.dtype npoints = order + 1 if nodes == "equispaced": - points_1d = np.linspace(-h/2, h/2, npoints) + points_1d = np.linspace(-h/2, h/2, npoints, dtype=dtype) weights_1d = None elif nodes == "chebyshev": - a = np.arange(npoints, dtype=np.float64) + a = np.arange(npoints, dtype=dtype) points_1d = (h/2)*np.cos((2*(a+1)-1)/(2*npoints)*np.pi) weights_1d = None elif nodes == "legendre": from scipy.special import legendre points_1d, weights_1d, _ = legendre(npoints).weights.T - points_1d = points_1d * (h/2) - weights_1d = weights_1d * (h/2) + points_1d = (points_1d * (h/2)).astype(dtype) + weights_1d = (weights_1d * (h/2)).astype(dtype) else: raise ValueError(f"invalid node set: {nodes}") @@ -127,7 +143,7 @@ def __init__(self, self._pshape = points_shaped.shape[1:] @memoize_method - def _vandermonde_1d(self): + def _vandermonde_1d(self) -> Array2D[np.floating[Any]]: points_1d = self._points_1d npoints = len(self._points_1d) @@ -138,11 +154,13 @@ def _vandermonde_1d(self): return vandermonde @memoize_method - def _zero_eval_vec_1d(self): + def _zero_eval_vec_1d(self) -> Array1D[np.floating[Any]]: # The zeroth coefficient--all others involve x=0. return self._vandermonde_1d()[0] - def basis(self) -> Sequence[Callable[[Array2D[np.floating]], Array1D[np.floating]]]: + def basis(self) -> Sequence[ + Callable[[Array2D[np.floating[Any]]], Array1D[np.floating[Any]]] + ]: """ :returns: a :class:`list` containing functions that realize a high-order interpolation basis on the :py:attr:`points`. @@ -152,11 +170,15 @@ def basis(self) -> Sequence[Callable[[Array2D[np.floating]], Array1D[np.floating from pytools import indices_in_shape - def eval_basis(ind: tuple[int, ...], x: Array2D[np.floating]): - result = 1 + def eval_basis( + ind: tuple[int, ...], + x: Array2D[np.floating[Any]] + ) -> Array1D[np.floating[Any]]: + result = np.ones(x[0].shape, dtype=x.dtype) for i in range(self.dim): coord = (x[i] - self.center[i])/(self.h/2) result *= eval_chebyt(ind[i], coord) + return result from functools import partial @@ -165,8 +187,8 @@ def eval_basis(ind: tuple[int, ...], x: Array2D[np.floating]): for ind in indices_in_shape((self.npoints,)*self.dim)] @memoize_method - def weights(self): - """" + def weights(self) -> ArrayND[np.floating[Any]]: + """ :returns: a vector of high-order quadrature weights on the :attr:`points` """ @@ -182,7 +204,7 @@ def weights(self): return result.reshape(-1) @memoize_method - def _diff_mat_1d(self, nderivs): + def _diff_mat_1d(self, nderivs: int) -> Array2D[np.floating[Any]]: npoints = len(self._points_1d) vandermonde = self._vandermonde_1d() @@ -193,26 +215,33 @@ def _diff_mat_1d(self, nderivs): n_diff_mat = n_diff_mat.dot(coeff_diff_mat) deriv_coeffs_mat = la.solve(vandermonde.T, n_diff_mat.T).T - return vandermonde.dot(deriv_coeffs_mat) + return vandermonde @ deriv_coeffs_mat + + @overload + def diff(self, axis: int, f_values: np.number[Any] | complex, + nderivs: int = 1) -> Literal[0]: ... + + @overload + def diff(self, axis: int, f_values: Array1D[InexactT], + nderivs: int = 1) -> Array1D[InexactT]: ... def diff(self, axis: int, - f_values: Array1D[np.inexact], + f_values: np.number[Any] | complex | Array1D[InexactT], nderivs: int = 1 - ) -> Array1D[np.inexact] | Literal[0]: + ) -> Array1D[InexactT] | Literal[0]: """Return the derivative along *axis* of *f_values*. - :arg f_values: an array of shape ``(npoints_total,)`` - :returns: an array of shape ``(npoints_total,)`` + :arg f_values: an array of shape ``(npoints,)`` + :returns: an array of shape ``(npoints,)`` """ from numbers import Number - if isinstance(f_values, np.number | Number): + if isinstance(f_values, (int, float, complex, np.number, Number)): # constants differentiate to 0 return 0 dim = len(self.center) - assert axis < dim axes = "klmno" @@ -224,45 +253,49 @@ def diff(self, self._diff_mat_1d(nderivs), f_values.reshape(*self._pshape)).reshape(-1) - def dx(self, f_values: Array1D[np.inexact]): + def dx(self, f_values: Array1D[InexactT]) -> Array1D[InexactT]: return self.diff(0, f_values) - def dy(self, f_values: Array1D[np.inexact]): + def dy(self, f_values: Array1D[InexactT]) -> Array1D[InexactT]: return self.diff(1, f_values) - def dz(self, f_values: Array1D[np.inexact]): + def dz(self, f_values: Array1D[InexactT]) -> Array1D[InexactT]: return self.diff(2, f_values) - def laplace(self, f_values: Array1D[np.inexact]): + def laplace(self, f_values: Array1D[InexactT]) -> Array1D[InexactT]: """Return the Laplacian of *f_values*. - :arg f_values: an array of shape ``(npoints_total,)`` - :returns: an array of shape ``(npoints_total,)`` + :arg f_values: an array of shape ``(npoints,)`` + :returns: an array of shape ``(npoints,)`` representing the application + of the Laplacian to *f_values*. """ return sum(self.diff(iaxis, f_values, 2) for iaxis in range(self.dim)) def div(self, - arg: obj_array.ObjectArray1D[Array1D[np.inexact]] - ) -> Array1D[np.inexact] | int: + arg: obj_array.ObjectArray1D[Array1D[InexactT]] + ) -> Array1D[InexactT]: r""" :arg arg: an object array containing - :class:`numpy.ndarray`\ s with shape ``(npoints_total,)``. + :class:`numpy.ndarray`\ s with shape ``(npoints,)``. """ - result: Array1D[np.inexact] | int = 0 + result: Array1D[InexactT] | int = 0 for i, arg_i in enumerate(arg): result = result + self.diff(i, arg_i) return result def curl(self, - arg: obj_array.ObjectArray1D[Array1D[np.inexact]] - ) -> obj_array.ObjectArray1D[Array1D[np.inexact]]: + arg: obj_array.ObjectArray1D[Array1D[InexactT]] + ) -> obj_array.ObjectArray1D[Array1D[InexactT]]: r"""Take the curl of the vector quantity *arg*. :arg arg: an object array of shape ``(3,)`` containing - :class:`numpy.ndarray`\ s with shape ``(npoints_total,)``. + :class:`numpy.ndarray`\ s with shape ``(npoints,)``. """ + if arg.size != 3: + raise ValueError(f"can only take the curl of a 3d vector: {arg.shape}") + from pytools import levi_civita return obj_array.new_1d([ sum( @@ -270,10 +303,12 @@ def curl(self, for m in range(3) for n in range(3)) for k in range(3)]) - def eval_at_center(self, f_values): + def eval_at_center( + self, f_values: Array1D[InexactT] + ) -> InexactT: """Interpolate *f_values* to the center point. - :arg f_values: an array of shape ``(npoints_total,)`` + :arg f_values: an array of shape ``(npoints,)`` :returns: a scalar. """ f_values = f_values.reshape(*self._pshape) @@ -282,21 +317,26 @@ def eval_at_center(self, f_values): for _ in range(self.dim): f_values = zero_eval_vec_1d @ f_values + assert f_values.ndim == 0 return f_values @property - def x(self) -> Array1D[np.floating]: + def x(self) -> Array1D[np.floating[Any]]: return self.points[0] @property - def y(self) -> Array1D[np.floating]: + def y(self) -> Array1D[np.floating[Any]]: return self.points[1] @property - def z(self) -> Array1D[np.floating]: + def z(self) -> Array1D[np.floating[Any]]: return self.points[2] - def norm(self, arg, p): + def norm(self, + arg: ( + obj_array.ObjectArray1D[ArrayND[InexactT]] + | ArrayND[InexactT]), + p: float) -> np.floating[Any]: if p == np.inf: if arg.dtype == object: return max( @@ -307,7 +347,13 @@ def norm(self, arg, p): else: raise ValueError("unsupported norm") - def plot_nodes(self): + def make_field_plotter(self) -> FieldPlotter: + return FieldPlotter(self.center, self.h, points=self._points_shaped) + + def plot_nodes(self) -> None: + if self.dim != 2: + raise ValueError(f"cannot plot {self.dim}d fields") + import matplotlib.pyplot as plt plt.gca().set_aspect("equal") plt.plot( @@ -315,7 +361,15 @@ def plot_nodes(self): self._points_shaped[1].reshape(-1), "o") - def plot(self, f: Array1D[np.floating]): + def plot(self, f: Array1D[np.floating[Any]]) -> None: + from warnings import warn + warn(f"Calling '{type(self).__name__}.plot' is deprecated. Use " + f"'{type(self).__name__}.make_field_plotter' instead, which also " + "supports 3d fields.", DeprecationWarning, stacklevel=2) + + if self.dim != 2: + raise ValueError(f"cannot plot {self.dim}d fields") + f = f.reshape(*self._pshape) import matplotlib.pyplot as plt @@ -324,14 +378,17 @@ def plot(self, f: Array1D[np.floating]): def frequency_domain_maxwell( - cpatch: CalculusPatch, - e: obj_array.ObjectArray1D[Array1D[np.complexfloating]], - h: obj_array.ObjectArray1D[Array1D[np.complexfloating]], - k: complex - ): + cpatch: CalculusPatch, + e: obj_array.ObjectArray1D[Array1D[np.complexfloating[Any]]], + h: obj_array.ObjectArray1D[Array1D[np.complexfloating[Any]]], + k: complex + ) -> tuple[obj_array.ObjectArray1D[Array1D[np.complexfloating[Any]]], + obj_array.ObjectArray1D[Array1D[np.complexfloating[Any]]], + Array1D[np.complexfloating[Any]], + Array1D[np.complexfloating[Any]]]: mu = 1 epsilon = 1 - c = 1/np.sqrt(mu*epsilon) + c = np.float64(1/np.sqrt(mu*epsilon)) omega = k*c b = mu*h diff --git a/sumpy/symbolic.py b/sumpy/symbolic.py index 64a26294..0459485f 100644 --- a/sumpy/symbolic.py +++ b/sumpy/symbolic.py @@ -98,7 +98,7 @@ def _find_symbolic_backend(): if TYPE_CHECKING or not USE_SYMENGINE: import sympy as sym - from pymbolic.interop.sympy import ( # type: ignore[assignment] + from pymbolic.interop.sympy import ( PymbolicToSympyMapper as PymbolicToSympyMapperBase, SympyToPymbolicMapper as SympyToPymbolicMapperBase, ) diff --git a/sumpy/toys.py b/sumpy/toys.py index 71318a31..3ccda9c8 100644 --- a/sumpy/toys.py +++ b/sumpy/toys.py @@ -540,7 +540,7 @@ def __add__(self, other: Number_ish | PotentialSource) -> PotentialSource: def __sub__(self, other: Number_ish | PotentialSource) -> PotentialSource: return self.__add__(-other) - def __rsub__(self, # type:ignore[misc] + def __rsub__(self, other: Number_ish | PotentialSource ) -> PotentialSource: return (-self).__add__(other) @@ -725,7 +725,7 @@ def __init__(self, psources: Sequence[PotentialSource]) -> None: def center(self) -> np.ndarray: for psource in self.psources: try: - return psource.center # type: ignore[attr-defined] + return psource.center except AttributeError: pass diff --git a/sumpy/visualization.py b/sumpy/visualization.py index 9033f24d..f3ffacac 100644 --- a/sumpy/visualization.py +++ b/sumpy/visualization.py @@ -29,10 +29,21 @@ .. autoclass:: FieldPlotter """ +from typing import TYPE_CHECKING, Any, cast + import numpy as np -def separate_by_real_and_imag(data, real_only): +if TYPE_CHECKING: + import pathlib + from collections.abc import Iterable, Iterator, Sequence + + import optype.numpy as onp + + +def separate_by_real_and_imag( + data: Iterable[tuple[str, onp.ArrayND[Any]]], *, + real_only: bool) -> Iterator[tuple[str, onp.ArrayND[Any]]]: from pytools.obj_array import obj_array_imag_copy, obj_array_real_copy for name, field in data: @@ -51,7 +62,10 @@ def separate_by_real_and_imag(data, real_only): yield (f"{name}_i", obj_array_imag_copy(field)) -def make_field_plotter_from_bbox(bbox, h, extend_factor=0): +def make_field_plotter_from_bbox( + bbox: tuple[onp.Array1D[np.floating[Any]], onp.Array1D[np.floating[Any]]], + h: float | Sequence[float], + extend_factor: float = 0) -> FieldPlotter: """ :arg bbox: a tuple (low, high) of points represented as 1D numpy arrays indicating the low and high ends of the extent of a bounding box. @@ -63,74 +77,95 @@ def make_field_plotter_from_bbox(bbox, h, extend_factor=0): """ low, high = bbox - extent = (high-low) * (1 + extend_factor) - center = 0.5*(high+low) - + extent: onp.Array1D[np.floating[Any]] = (high-low) * (1 + extend_factor) + center: onp.Array1D[np.floating[Any]] = 0.5*(high+low) dimensions = len(center) + from numbers import Number - if isinstance(h, Number): - h = (h,)*dimensions + if isinstance(h, (int, float, Number)): + h = cast("Sequence[float]", (h,)*dimensions) else: if len(h) != dimensions: raise ValueError("length of 'h' must match number of dimensions") from math import ceil - npoints = tuple(ceil(extent[i] / h[i]) for i in range(dimensions)) - + npoints = tuple(ceil(float(extent[i]) / h[i]) for i in range(dimensions)) return FieldPlotter(center, extent, npoints) class FieldPlotter: """ + .. autoattribute:: dimensions + .. autoattribute:: npoints + .. autoattribute:: points + .. automethod:: set_matplotlib_limits .. automethod:: show_scalar_in_matplotlib .. automethod:: show_scalar_in_mayavi .. automethod:: write_vtk_file """ - def __init__(self, center, extent=1, npoints=1000): - center = np.asarray(center) - self.dimensions, = dim, = center.shape - self.a = a = center-extent*0.5 - self.b = b = center+extent*0.5 - - from numbers import Number - if isinstance(npoints, Number): - npoints = dim*(npoints,) - else: - if len(npoints) != dim: - raise ValueError("length of npoints must match dimension") - for i in range(dim): - if npoints[i] == 1: - a[i] = center[i] + dimensions: int + npoints: int + points: onp.Array2D[np.floating[Any]] - mgrid_index = tuple( - slice(a[i], b[i], 1j*npoints[i]) - for i in range(dim)) + a: onp.Array1D[np.floating[Any]] + b: onp.Array1D[np.floating[Any]] + nd_points: onp.ArrayND[np.floating[Any]] - # np.asarray is technically unneeded, used to placate pylint - # https://github.com/pylint-dev/pylint/issues/9989 - mgrid = np.asarray(np.mgrid[mgrid_index]) + def __init__(self, + center: onp.ToArray1D[np.floating[Any]], + extent: float | onp.Array1D[np.floating[Any]] = 1, + npoints: int | tuple[int, ...] = 1000, + points: onp.ArrayND[np.floating[Any]] | None = None) -> None: + center = np.asarray(center) + dim, = cast("tuple[int]", center.shape) + + self.dimensions = dim + self.a = a = center - 0.5 * extent + self.b = b = center + 0.5 * extent + + if points is None: + from numbers import Number + if isinstance(npoints, (int, Number)): + npoints = dim*(npoints,) + else: + if len(npoints) != dim: + raise ValueError("length of npoints must match dimension") + + for i in range(dim): + if npoints[i] == 1: + a[i] = center[i] + + mgrid_index = tuple( + slice(a[i], b[i], 1j*npoints[i]) + for i in range(dim)) + mgrid = np.mgrid[mgrid_index] + else: + mgrid = points # (axis, point x idx, point y idx, ...) self.nd_points = mgrid - self.points = self.nd_points.reshape(dim, -1).copy() + self.npoints = int(np.prod(mgrid.shape[1:])) - from pytools import product - self.npoints = product(npoints) - - def _get_nontrivial_dims(self): + def _get_nontrivial_dims(self) -> onp.Array1D[np.bool_]: return np.array(self.nd_points.shape[1:]) != 1 - def _get_squeezed_bounds(self): + def _get_squeezed_bounds( + self + ) -> tuple[onp.Array1D[np.floating[Any]], onp.Array1D[np.floating[Any]]]: nontriv_dims = self._get_nontrivial_dims() return self.a[nontriv_dims], self.b[nontriv_dims] - def show_scalar_in_matplotlib(self, fld, max_val=None, - func_name="imshow", **kwargs): + def show_scalar_in_matplotlib( + self, + fld: onp.ArrayND[Any], + max_val: float | None = None, + func_name: str = "imshow", + **kwargs: Any) -> Any: squeezed_points = self.points.squeeze() if len(squeezed_points.shape) != 2: @@ -158,31 +193,43 @@ def show_scalar_in_matplotlib(self, fld, max_val=None, import matplotlib.pyplot as pt return getattr(pt, func_name)(squeezed_fld.T, **kwargs) - def set_matplotlib_limits(self): + def set_matplotlib_limits(self) -> None: import matplotlib.pyplot as pt a, b = self._get_squeezed_bounds() pt.xlim((a[0], b[0])) pt.ylim((a[1], b[1])) - def show_vector_in_mayavi(self, fld, do_show=True, **kwargs): + def show_vector_in_mayavi( + self, + fld: onp.ArrayND[Any], + do_show: bool = True, + **kwargs: Any) -> None: c = self.points from mayavi import mlab - mlab.quiver3d(c[0], c[1], c[2], fld[0], fld[1], fld[2], - **kwargs) + mlab.quiver3d(c[0], c[1], c[2], fld[0], fld[1], fld[2], **kwargs) if do_show: mlab.show() - def write_vtk_file(self, file_name, data, real_only=False, overwrite=False): + def write_vtk_file( + self, + file_name: str | pathlib.Path, + data: Iterable[tuple[str, onp.ArrayND[Any]]], *, + real_only: bool = False, + overwrite: bool = False) -> None: from pyvisfile.vtk import write_structured_grid write_structured_grid(file_name, self.nd_points, - point_data=list(separate_by_real_and_imag(data, real_only)), + point_data=list(separate_by_real_and_imag(data, real_only=real_only)), overwrite=overwrite) - def show_scalar_in_mayavi(self, fld, max_val=None, **kwargs): + def show_scalar_in_mayavi( + self, + fld: onp.ArrayND[Any], + max_val: float | None = None, + **kwargs: Any) -> None: if max_val is not None: fld[fld > max_val] = max_val fld[fld < -max_val] = -max_val