Commit 6f53a5ab20490b471b1ad9a4f9413bff4a486595
1 parent
c135e7ce
Add out_of_range exceptions for FITS image Python __getitem__ methods
Showing
9 changed files
with
378 additions
and
152 deletions
pyext/GFitsImageByte.i
| ... | ... | @@ -65,30 +65,55 @@ public: |
| 65 | 65 | ***************************************************************************/ |
| 66 | 66 | %extend GFitsImageByte { |
| 67 | 67 | unsigned char __getitem__(int GFitsImageInx[]) { |
| 68 | - if (GFitsImageInx[0] == 1) | |
| 69 | - return self->at(GFitsImageInx[1]); | |
| 70 | - else if (GFitsImageInx[0] == 2) | |
| 71 | - return self->at(GFitsImageInx[1], GFitsImageInx[2]); | |
| 72 | - else if (GFitsImageInx[0] == 3) | |
| 73 | - return self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]); | |
| 74 | - else if (GFitsImageInx[0] == 4) | |
| 75 | - return self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], GFitsImageInx[4]); | |
| 76 | - else | |
| 68 | + // Check image dimensions | |
| 69 | + for (int i = 0; i < GFitsImageInx[0]; ++i) { | |
| 70 | + if (GFitsImageInx[i+1] < 0 || GFitsImageInx[i+1] >= self->naxes(i)) { | |
| 71 | + throw GException::out_of_range("__getitem__(int)", | |
| 72 | + "FITS image axis "+ | |
| 73 | + gammalib::str(i)+" index", | |
| 74 | + GFitsImageInx[i+1], | |
| 75 | + self->naxes(i)); | |
| 76 | + } | |
| 77 | + } | |
| 78 | + // Return pixel value | |
| 79 | + if (GFitsImageInx[0] == 1) { | |
| 80 | + return (*self)(GFitsImageInx[1]); | |
| 81 | + } | |
| 82 | + else if (GFitsImageInx[0] == 2) { | |
| 83 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2]); | |
| 84 | + } | |
| 85 | + else if (GFitsImageInx[0] == 3) { | |
| 86 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]); | |
| 87 | + } | |
| 88 | + else if (GFitsImageInx[0] == 4) { | |
| 89 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], | |
| 90 | + GFitsImageInx[4]); | |
| 91 | + } | |
| 92 | + else { | |
| 77 | 93 | throw GException::fits_wrong_image_operator("__getitem__(int)", |
| 78 | 94 | self->naxis(), GFitsImageInx[0]); |
| 95 | + } | |
| 79 | 96 | } |
| 80 | 97 | void __setitem__(int GFitsImageInx[], unsigned char value) { |
| 81 | - if (GFitsImageInx[0] == 1) | |
| 98 | + if (GFitsImageInx[0] == 1) { | |
| 82 | 99 | self->at(GFitsImageInx[1]) = value; |
| 83 | - else if (GFitsImageInx[0] == 2) | |
| 100 | + } | |
| 101 | + else if (GFitsImageInx[0] == 2) { | |
| 84 | 102 | self->at(GFitsImageInx[1], GFitsImageInx[2]) = value; |
| 85 | - else if (GFitsImageInx[0] == 3) | |
| 86 | - self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]) = value; | |
| 87 | - else if (GFitsImageInx[0] == 4) | |
| 88 | - self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], GFitsImageInx[4]) = value; | |
| 89 | - else | |
| 103 | + } | |
| 104 | + else if (GFitsImageInx[0] == 3) { | |
| 105 | + self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]) = | |
| 106 | + value; | |
| 107 | + } | |
| 108 | + else if (GFitsImageInx[0] == 4) { | |
| 109 | + self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], | |
| 110 | + GFitsImageInx[4]) = value; | |
| 111 | + } | |
| 112 | + else { | |
| 90 | 113 | throw GException::fits_wrong_image_operator("__setitem__(int)", |
| 91 | - self->naxis(), GFitsImageInx[0]); | |
| 114 | + self->naxis(), | |
| 115 | + GFitsImageInx[0]); | |
| 116 | + } | |
| 92 | 117 | } |
| 93 | 118 | GFitsImageByte copy() { |
| 94 | 119 | return (*self); | ... | ... |
pyext/GFitsImageDouble.i
| ... | ... | @@ -65,30 +65,55 @@ public: |
| 65 | 65 | ***************************************************************************/ |
| 66 | 66 | %extend GFitsImageDouble { |
| 67 | 67 | double __getitem__(int GFitsImageInx[]) { |
| 68 | - if (GFitsImageInx[0] == 1) | |
| 69 | - return self->at(GFitsImageInx[1]); | |
| 70 | - else if (GFitsImageInx[0] == 2) | |
| 71 | - return self->at(GFitsImageInx[1], GFitsImageInx[2]); | |
| 72 | - else if (GFitsImageInx[0] == 3) | |
| 73 | - return self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]); | |
| 74 | - else if (GFitsImageInx[0] == 4) | |
| 75 | - return self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], GFitsImageInx[4]); | |
| 76 | - else | |
| 68 | + // Check image dimensions | |
| 69 | + for (int i = 0; i < GFitsImageInx[0]; ++i) { | |
| 70 | + if (GFitsImageInx[i+1] < 0 || GFitsImageInx[i+1] >= self->naxes(i)) { | |
| 71 | + throw GException::out_of_range("__getitem__(int)", | |
| 72 | + "FITS image axis "+ | |
| 73 | + gammalib::str(i)+" index", | |
| 74 | + GFitsImageInx[i+1], | |
| 75 | + self->naxes(i)); | |
| 76 | + } | |
| 77 | + } | |
| 78 | + // Return pixel value | |
| 79 | + if (GFitsImageInx[0] == 1) { | |
| 80 | + return (*self)(GFitsImageInx[1]); | |
| 81 | + } | |
| 82 | + else if (GFitsImageInx[0] == 2) { | |
| 83 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2]); | |
| 84 | + } | |
| 85 | + else if (GFitsImageInx[0] == 3) { | |
| 86 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]); | |
| 87 | + } | |
| 88 | + else if (GFitsImageInx[0] == 4) { | |
| 89 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], | |
| 90 | + GFitsImageInx[4]); | |
| 91 | + } | |
| 92 | + else { | |
| 77 | 93 | throw GException::fits_wrong_image_operator("__getitem__(int)", |
| 78 | 94 | self->naxis(), GFitsImageInx[0]); |
| 95 | + } | |
| 79 | 96 | } |
| 80 | 97 | void __setitem__(int GFitsImageInx[], double value) { |
| 81 | - if (GFitsImageInx[0] == 1) | |
| 98 | + if (GFitsImageInx[0] == 1) { | |
| 82 | 99 | self->at(GFitsImageInx[1]) = value; |
| 83 | - else if (GFitsImageInx[0] == 2) | |
| 100 | + } | |
| 101 | + else if (GFitsImageInx[0] == 2) { | |
| 84 | 102 | self->at(GFitsImageInx[1], GFitsImageInx[2]) = value; |
| 85 | - else if (GFitsImageInx[0] == 3) | |
| 86 | - self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]) = value; | |
| 87 | - else if (GFitsImageInx[0] == 4) | |
| 88 | - self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], GFitsImageInx[4]) = value; | |
| 89 | - else | |
| 103 | + } | |
| 104 | + else if (GFitsImageInx[0] == 3) { | |
| 105 | + self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]) = | |
| 106 | + value; | |
| 107 | + } | |
| 108 | + else if (GFitsImageInx[0] == 4) { | |
| 109 | + self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], | |
| 110 | + GFitsImageInx[4]) = value; | |
| 111 | + } | |
| 112 | + else { | |
| 90 | 113 | throw GException::fits_wrong_image_operator("__setitem__(int)", |
| 91 | - self->naxis(), GFitsImageInx[0]); | |
| 114 | + self->naxis(), | |
| 115 | + GFitsImageInx[0]); | |
| 116 | + } | |
| 92 | 117 | } |
| 93 | 118 | GFitsImageDouble copy() { |
| 94 | 119 | return (*self); | ... | ... |
pyext/GFitsImageFloat.i
| ... | ... | @@ -65,30 +65,55 @@ public: |
| 65 | 65 | ***************************************************************************/ |
| 66 | 66 | %extend GFitsImageFloat { |
| 67 | 67 | float __getitem__(int GFitsImageInx[]) { |
| 68 | - if (GFitsImageInx[0] == 1) | |
| 69 | - return self->at(GFitsImageInx[1]); | |
| 70 | - else if (GFitsImageInx[0] == 2) | |
| 71 | - return self->at(GFitsImageInx[1], GFitsImageInx[2]); | |
| 72 | - else if (GFitsImageInx[0] == 3) | |
| 73 | - return self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]); | |
| 74 | - else if (GFitsImageInx[0] == 4) | |
| 75 | - return self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], GFitsImageInx[4]); | |
| 76 | - else | |
| 68 | + // Check image dimensions | |
| 69 | + for (int i = 0; i < GFitsImageInx[0]; ++i) { | |
| 70 | + if (GFitsImageInx[i+1] < 0 || GFitsImageInx[i+1] >= self->naxes(i)) { | |
| 71 | + throw GException::out_of_range("__getitem__(int)", | |
| 72 | + "FITS image axis "+ | |
| 73 | + gammalib::str(i)+" index", | |
| 74 | + GFitsImageInx[i+1], | |
| 75 | + self->naxes(i)); | |
| 76 | + } | |
| 77 | + } | |
| 78 | + // Return pixel value | |
| 79 | + if (GFitsImageInx[0] == 1) { | |
| 80 | + return (*self)(GFitsImageInx[1]); | |
| 81 | + } | |
| 82 | + else if (GFitsImageInx[0] == 2) { | |
| 83 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2]); | |
| 84 | + } | |
| 85 | + else if (GFitsImageInx[0] == 3) { | |
| 86 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]); | |
| 87 | + } | |
| 88 | + else if (GFitsImageInx[0] == 4) { | |
| 89 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], | |
| 90 | + GFitsImageInx[4]); | |
| 91 | + } | |
| 92 | + else { | |
| 77 | 93 | throw GException::fits_wrong_image_operator("__getitem__(int)", |
| 78 | 94 | self->naxis(), GFitsImageInx[0]); |
| 95 | + } | |
| 79 | 96 | } |
| 80 | 97 | void __setitem__(int GFitsImageInx[], float value) { |
| 81 | - if (GFitsImageInx[0] == 1) | |
| 98 | + if (GFitsImageInx[0] == 1) { | |
| 82 | 99 | self->at(GFitsImageInx[1]) = value; |
| 83 | - else if (GFitsImageInx[0] == 2) | |
| 100 | + } | |
| 101 | + else if (GFitsImageInx[0] == 2) { | |
| 84 | 102 | self->at(GFitsImageInx[1], GFitsImageInx[2]) = value; |
| 85 | - else if (GFitsImageInx[0] == 3) | |
| 86 | - self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]) = value; | |
| 87 | - else if (GFitsImageInx[0] == 4) | |
| 88 | - self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], GFitsImageInx[4]) = value; | |
| 89 | - else | |
| 103 | + } | |
| 104 | + else if (GFitsImageInx[0] == 3) { | |
| 105 | + self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]) = | |
| 106 | + value; | |
| 107 | + } | |
| 108 | + else if (GFitsImageInx[0] == 4) { | |
| 109 | + self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], | |
| 110 | + GFitsImageInx[4]) = value; | |
| 111 | + } | |
| 112 | + else { | |
| 90 | 113 | throw GException::fits_wrong_image_operator("__setitem__(int)", |
| 91 | - self->naxis(), GFitsImageInx[0]); | |
| 114 | + self->naxis(), | |
| 115 | + GFitsImageInx[0]); | |
| 116 | + } | |
| 92 | 117 | } |
| 93 | 118 | GFitsImageFloat copy() { |
| 94 | 119 | return (*self); | ... | ... |
pyext/GFitsImageLong.i
| ... | ... | @@ -65,30 +65,55 @@ public: |
| 65 | 65 | ***************************************************************************/ |
| 66 | 66 | %extend GFitsImageLong { |
| 67 | 67 | long __getitem__(int GFitsImageInx[]) { |
| 68 | - if (GFitsImageInx[0] == 1) | |
| 69 | - return self->at(GFitsImageInx[1]); | |
| 70 | - else if (GFitsImageInx[0] == 2) | |
| 71 | - return self->at(GFitsImageInx[1], GFitsImageInx[2]); | |
| 72 | - else if (GFitsImageInx[0] == 3) | |
| 73 | - return self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]); | |
| 74 | - else if (GFitsImageInx[0] == 4) | |
| 75 | - return self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], GFitsImageInx[4]); | |
| 76 | - else | |
| 68 | + // Check image dimensions | |
| 69 | + for (int i = 0; i < GFitsImageInx[0]; ++i) { | |
| 70 | + if (GFitsImageInx[i+1] < 0 || GFitsImageInx[i+1] >= self->naxes(i)) { | |
| 71 | + throw GException::out_of_range("__getitem__(int)", | |
| 72 | + "FITS image axis "+ | |
| 73 | + gammalib::str(i)+" index", | |
| 74 | + GFitsImageInx[i+1], | |
| 75 | + self->naxes(i)); | |
| 76 | + } | |
| 77 | + } | |
| 78 | + // Return pixel value | |
| 79 | + if (GFitsImageInx[0] == 1) { | |
| 80 | + return (*self)(GFitsImageInx[1]); | |
| 81 | + } | |
| 82 | + else if (GFitsImageInx[0] == 2) { | |
| 83 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2]); | |
| 84 | + } | |
| 85 | + else if (GFitsImageInx[0] == 3) { | |
| 86 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]); | |
| 87 | + } | |
| 88 | + else if (GFitsImageInx[0] == 4) { | |
| 89 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], | |
| 90 | + GFitsImageInx[4]); | |
| 91 | + } | |
| 92 | + else { | |
| 77 | 93 | throw GException::fits_wrong_image_operator("__getitem__(int)", |
| 78 | 94 | self->naxis(), GFitsImageInx[0]); |
| 95 | + } | |
| 79 | 96 | } |
| 80 | 97 | void __setitem__(int GFitsImageInx[], long value) { |
| 81 | - if (GFitsImageInx[0] == 1) | |
| 98 | + if (GFitsImageInx[0] == 1) { | |
| 82 | 99 | self->at(GFitsImageInx[1]) = value; |
| 83 | - else if (GFitsImageInx[0] == 2) | |
| 100 | + } | |
| 101 | + else if (GFitsImageInx[0] == 2) { | |
| 84 | 102 | self->at(GFitsImageInx[1], GFitsImageInx[2]) = value; |
| 85 | - else if (GFitsImageInx[0] == 3) | |
| 86 | - self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]) = value; | |
| 87 | - else if (GFitsImageInx[0] == 4) | |
| 88 | - self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], GFitsImageInx[4]) = value; | |
| 89 | - else | |
| 103 | + } | |
| 104 | + else if (GFitsImageInx[0] == 3) { | |
| 105 | + self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]) = | |
| 106 | + value; | |
| 107 | + } | |
| 108 | + else if (GFitsImageInx[0] == 4) { | |
| 109 | + self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], | |
| 110 | + GFitsImageInx[4]) = value; | |
| 111 | + } | |
| 112 | + else { | |
| 90 | 113 | throw GException::fits_wrong_image_operator("__setitem__(int)", |
| 91 | - self->naxis(), GFitsImageInx[0]); | |
| 114 | + self->naxis(), | |
| 115 | + GFitsImageInx[0]); | |
| 116 | + } | |
| 92 | 117 | } |
| 93 | 118 | GFitsImageLong copy() { |
| 94 | 119 | return (*self); | ... | ... |
pyext/GFitsImageLongLong.i
| ... | ... | @@ -65,30 +65,55 @@ public: |
| 65 | 65 | ***************************************************************************/ |
| 66 | 66 | %extend GFitsImageLongLong { |
| 67 | 67 | long long __getitem__(int GFitsImageInx[]) { |
| 68 | - if (GFitsImageInx[0] == 1) | |
| 69 | - return self->at(GFitsImageInx[1]); | |
| 70 | - else if (GFitsImageInx[0] == 2) | |
| 71 | - return self->at(GFitsImageInx[1], GFitsImageInx[2]); | |
| 72 | - else if (GFitsImageInx[0] == 3) | |
| 73 | - return self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]); | |
| 74 | - else if (GFitsImageInx[0] == 4) | |
| 75 | - return self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], GFitsImageInx[4]); | |
| 76 | - else | |
| 68 | + // Check image dimensions | |
| 69 | + for (int i = 0; i < GFitsImageInx[0]; ++i) { | |
| 70 | + if (GFitsImageInx[i+1] < 0 || GFitsImageInx[i+1] >= self->naxes(i)) { | |
| 71 | + throw GException::out_of_range("__getitem__(int)", | |
| 72 | + "FITS image axis "+ | |
| 73 | + gammalib::str(i)+" index", | |
| 74 | + GFitsImageInx[i+1], | |
| 75 | + self->naxes(i)); | |
| 76 | + } | |
| 77 | + } | |
| 78 | + // Return pixel value | |
| 79 | + if (GFitsImageInx[0] == 1) { | |
| 80 | + return (*self)(GFitsImageInx[1]); | |
| 81 | + } | |
| 82 | + else if (GFitsImageInx[0] == 2) { | |
| 83 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2]); | |
| 84 | + } | |
| 85 | + else if (GFitsImageInx[0] == 3) { | |
| 86 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]); | |
| 87 | + } | |
| 88 | + else if (GFitsImageInx[0] == 4) { | |
| 89 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], | |
| 90 | + GFitsImageInx[4]); | |
| 91 | + } | |
| 92 | + else { | |
| 77 | 93 | throw GException::fits_wrong_image_operator("__getitem__(int)", |
| 78 | 94 | self->naxis(), GFitsImageInx[0]); |
| 95 | + } | |
| 79 | 96 | } |
| 80 | 97 | void __setitem__(int GFitsImageInx[], long long value) { |
| 81 | - if (GFitsImageInx[0] == 1) | |
| 98 | + if (GFitsImageInx[0] == 1) { | |
| 82 | 99 | self->at(GFitsImageInx[1]) = value; |
| 83 | - else if (GFitsImageInx[0] == 2) | |
| 100 | + } | |
| 101 | + else if (GFitsImageInx[0] == 2) { | |
| 84 | 102 | self->at(GFitsImageInx[1], GFitsImageInx[2]) = value; |
| 85 | - else if (GFitsImageInx[0] == 3) | |
| 86 | - self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]) = value; | |
| 87 | - else if (GFitsImageInx[0] == 4) | |
| 88 | - self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], GFitsImageInx[4]) = value; | |
| 89 | - else | |
| 103 | + } | |
| 104 | + else if (GFitsImageInx[0] == 3) { | |
| 105 | + self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]) = | |
| 106 | + value; | |
| 107 | + } | |
| 108 | + else if (GFitsImageInx[0] == 4) { | |
| 109 | + self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], | |
| 110 | + GFitsImageInx[4]) = value; | |
| 111 | + } | |
| 112 | + else { | |
| 90 | 113 | throw GException::fits_wrong_image_operator("__setitem__(int)", |
| 91 | - self->naxis(), GFitsImageInx[0]); | |
| 114 | + self->naxis(), | |
| 115 | + GFitsImageInx[0]); | |
| 116 | + } | |
| 92 | 117 | } |
| 93 | 118 | GFitsImageLongLong copy() { |
| 94 | 119 | return (*self); | ... | ... |
pyext/GFitsImageSByte.i
| ... | ... | @@ -65,30 +65,55 @@ public: |
| 65 | 65 | ***************************************************************************/ |
| 66 | 66 | %extend GFitsImageSByte { |
| 67 | 67 | char __getitem__(int GFitsImageInx[]) { |
| 68 | - if (GFitsImageInx[0] == 1) | |
| 69 | - return self->at(GFitsImageInx[1]); | |
| 70 | - else if (GFitsImageInx[0] == 2) | |
| 71 | - return self->at(GFitsImageInx[1], GFitsImageInx[2]); | |
| 72 | - else if (GFitsImageInx[0] == 3) | |
| 73 | - return self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]); | |
| 74 | - else if (GFitsImageInx[0] == 4) | |
| 75 | - return self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], GFitsImageInx[4]); | |
| 76 | - else | |
| 68 | + // Check image dimensions | |
| 69 | + for (int i = 0; i < GFitsImageInx[0]; ++i) { | |
| 70 | + if (GFitsImageInx[i+1] < 0 || GFitsImageInx[i+1] >= self->naxes(i)) { | |
| 71 | + throw GException::out_of_range("__getitem__(int)", | |
| 72 | + "FITS image axis "+ | |
| 73 | + gammalib::str(i)+" index", | |
| 74 | + GFitsImageInx[i+1], | |
| 75 | + self->naxes(i)); | |
| 76 | + } | |
| 77 | + } | |
| 78 | + // Return pixel value | |
| 79 | + if (GFitsImageInx[0] == 1) { | |
| 80 | + return (*self)(GFitsImageInx[1]); | |
| 81 | + } | |
| 82 | + else if (GFitsImageInx[0] == 2) { | |
| 83 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2]); | |
| 84 | + } | |
| 85 | + else if (GFitsImageInx[0] == 3) { | |
| 86 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]); | |
| 87 | + } | |
| 88 | + else if (GFitsImageInx[0] == 4) { | |
| 89 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], | |
| 90 | + GFitsImageInx[4]); | |
| 91 | + } | |
| 92 | + else { | |
| 77 | 93 | throw GException::fits_wrong_image_operator("__getitem__(int)", |
| 78 | 94 | self->naxis(), GFitsImageInx[0]); |
| 95 | + } | |
| 79 | 96 | } |
| 80 | 97 | void __setitem__(int GFitsImageInx[], char value) { |
| 81 | - if (GFitsImageInx[0] == 1) | |
| 98 | + if (GFitsImageInx[0] == 1) { | |
| 82 | 99 | self->at(GFitsImageInx[1]) = value; |
| 83 | - else if (GFitsImageInx[0] == 2) | |
| 100 | + } | |
| 101 | + else if (GFitsImageInx[0] == 2) { | |
| 84 | 102 | self->at(GFitsImageInx[1], GFitsImageInx[2]) = value; |
| 85 | - else if (GFitsImageInx[0] == 3) | |
| 86 | - self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]) = value; | |
| 87 | - else if (GFitsImageInx[0] == 4) | |
| 88 | - self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], GFitsImageInx[4]) = value; | |
| 89 | - else | |
| 103 | + } | |
| 104 | + else if (GFitsImageInx[0] == 3) { | |
| 105 | + self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]) = | |
| 106 | + value; | |
| 107 | + } | |
| 108 | + else if (GFitsImageInx[0] == 4) { | |
| 109 | + self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], | |
| 110 | + GFitsImageInx[4]) = value; | |
| 111 | + } | |
| 112 | + else { | |
| 90 | 113 | throw GException::fits_wrong_image_operator("__setitem__(int)", |
| 91 | - self->naxis(), GFitsImageInx[0]); | |
| 114 | + self->naxis(), | |
| 115 | + GFitsImageInx[0]); | |
| 116 | + } | |
| 92 | 117 | } |
| 93 | 118 | GFitsImageSByte copy() { |
| 94 | 119 | return (*self); | ... | ... |
pyext/GFitsImageShort.i
| ... | ... | @@ -66,29 +66,55 @@ public: |
| 66 | 66 | %extend GFitsImageShort { |
| 67 | 67 | short __getitem__(int GFitsImageInx[]) { |
| 68 | 68 | if (GFitsImageInx[0] == 1) |
| 69 | - return self->at(GFitsImageInx[1]); | |
| 70 | - else if (GFitsImageInx[0] == 2) | |
| 71 | - return self->at(GFitsImageInx[1], GFitsImageInx[2]); | |
| 72 | - else if (GFitsImageInx[0] == 3) | |
| 73 | - return self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]); | |
| 74 | - else if (GFitsImageInx[0] == 4) | |
| 75 | - return self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], GFitsImageInx[4]); | |
| 76 | - else | |
| 69 | + // Check image dimensions | |
| 70 | + for (int i = 0; i < GFitsImageInx[0]; ++i) { | |
| 71 | + if (GFitsImageInx[i+1] < 0 || GFitsImageInx[i+1] >= self->naxes(i)) { | |
| 72 | + throw GException::out_of_range("__getitem__(int)", | |
| 73 | + "FITS image axis "+ | |
| 74 | + gammalib::str(i)+" index", | |
| 75 | + GFitsImageInx[i+1], | |
| 76 | + self->naxes(i)); | |
| 77 | + } | |
| 78 | + } | |
| 79 | + // Return pixel value | |
| 80 | + if (GFitsImageInx[0] == 1) { | |
| 81 | + return (*self)(GFitsImageInx[1]); | |
| 82 | + } | |
| 83 | + else if (GFitsImageInx[0] == 2) { | |
| 84 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2]); | |
| 85 | + } | |
| 86 | + else if (GFitsImageInx[0] == 3) { | |
| 87 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]); | |
| 88 | + } | |
| 89 | + else if (GFitsImageInx[0] == 4) { | |
| 90 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], | |
| 91 | + GFitsImageInx[4]); | |
| 92 | + } | |
| 93 | + else { | |
| 77 | 94 | throw GException::fits_wrong_image_operator("__getitem__(int)", |
| 78 | 95 | self->naxis(), GFitsImageInx[0]); |
| 96 | + } | |
| 79 | 97 | } |
| 80 | 98 | void __setitem__(int GFitsImageInx[], short value) { |
| 81 | - if (GFitsImageInx[0] == 1) | |
| 99 | + if (GFitsImageInx[0] == 1) { | |
| 82 | 100 | self->at(GFitsImageInx[1]) = value; |
| 83 | - else if (GFitsImageInx[0] == 2) | |
| 101 | + } | |
| 102 | + else if (GFitsImageInx[0] == 2) { | |
| 84 | 103 | self->at(GFitsImageInx[1], GFitsImageInx[2]) = value; |
| 85 | - else if (GFitsImageInx[0] == 3) | |
| 86 | - self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]) = value; | |
| 87 | - else if (GFitsImageInx[0] == 4) | |
| 88 | - self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], GFitsImageInx[4]) = value; | |
| 89 | - else | |
| 104 | + } | |
| 105 | + else if (GFitsImageInx[0] == 3) { | |
| 106 | + self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]) = | |
| 107 | + value; | |
| 108 | + } | |
| 109 | + else if (GFitsImageInx[0] == 4) { | |
| 110 | + self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], | |
| 111 | + GFitsImageInx[4]) = value; | |
| 112 | + } | |
| 113 | + else { | |
| 90 | 114 | throw GException::fits_wrong_image_operator("__setitem__(int)", |
| 91 | - self->naxis(), GFitsImageInx[0]); | |
| 115 | + self->naxis(), | |
| 116 | + GFitsImageInx[0]); | |
| 117 | + } | |
| 92 | 118 | } |
| 93 | 119 | GFitsImageShort copy() { |
| 94 | 120 | return (*self); | ... | ... |
pyext/GFitsImageULong.i
| ... | ... | @@ -65,30 +65,55 @@ public: |
| 65 | 65 | ***************************************************************************/ |
| 66 | 66 | %extend GFitsImageULong { |
| 67 | 67 | unsigned long __getitem__(int GFitsImageInx[]) { |
| 68 | - if (GFitsImageInx[0] == 1) | |
| 69 | - return self->at(GFitsImageInx[1]); | |
| 70 | - else if (GFitsImageInx[0] == 2) | |
| 71 | - return self->at(GFitsImageInx[1], GFitsImageInx[2]); | |
| 72 | - else if (GFitsImageInx[0] == 3) | |
| 73 | - return self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]); | |
| 74 | - else if (GFitsImageInx[0] == 4) | |
| 75 | - return self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], GFitsImageInx[4]); | |
| 76 | - else | |
| 68 | + // Check image dimensions | |
| 69 | + for (int i = 0; i < GFitsImageInx[0]; ++i) { | |
| 70 | + if (GFitsImageInx[i+1] < 0 || GFitsImageInx[i+1] >= self->naxes(i)) { | |
| 71 | + throw GException::out_of_range("__getitem__(int)", | |
| 72 | + "FITS image axis "+ | |
| 73 | + gammalib::str(i)+" index", | |
| 74 | + GFitsImageInx[i+1], | |
| 75 | + self->naxes(i)); | |
| 76 | + } | |
| 77 | + } | |
| 78 | + // Return pixel value | |
| 79 | + if (GFitsImageInx[0] == 1) { | |
| 80 | + return (*self)(GFitsImageInx[1]); | |
| 81 | + } | |
| 82 | + else if (GFitsImageInx[0] == 2) { | |
| 83 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2]); | |
| 84 | + } | |
| 85 | + else if (GFitsImageInx[0] == 3) { | |
| 86 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]); | |
| 87 | + } | |
| 88 | + else if (GFitsImageInx[0] == 4) { | |
| 89 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], | |
| 90 | + GFitsImageInx[4]); | |
| 91 | + } | |
| 92 | + else { | |
| 77 | 93 | throw GException::fits_wrong_image_operator("__getitem__(int)", |
| 78 | 94 | self->naxis(), GFitsImageInx[0]); |
| 95 | + } | |
| 79 | 96 | } |
| 80 | 97 | void __setitem__(int GFitsImageInx[], unsigned long value) { |
| 81 | - if (GFitsImageInx[0] == 1) | |
| 98 | + if (GFitsImageInx[0] == 1) { | |
| 82 | 99 | self->at(GFitsImageInx[1]) = value; |
| 83 | - else if (GFitsImageInx[0] == 2) | |
| 100 | + } | |
| 101 | + else if (GFitsImageInx[0] == 2) { | |
| 84 | 102 | self->at(GFitsImageInx[1], GFitsImageInx[2]) = value; |
| 85 | - else if (GFitsImageInx[0] == 3) | |
| 86 | - self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]) = value; | |
| 87 | - else if (GFitsImageInx[0] == 4) | |
| 88 | - self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], GFitsImageInx[4]) = value; | |
| 89 | - else | |
| 103 | + } | |
| 104 | + else if (GFitsImageInx[0] == 3) { | |
| 105 | + self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]) = | |
| 106 | + value; | |
| 107 | + } | |
| 108 | + else if (GFitsImageInx[0] == 4) { | |
| 109 | + self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], | |
| 110 | + GFitsImageInx[4]) = value; | |
| 111 | + } | |
| 112 | + else { | |
| 90 | 113 | throw GException::fits_wrong_image_operator("__setitem__(int)", |
| 91 | - self->naxis(), GFitsImageInx[0]); | |
| 114 | + self->naxis(), | |
| 115 | + GFitsImageInx[0]); | |
| 116 | + } | |
| 92 | 117 | } |
| 93 | 118 | GFitsImageULong copy() { |
| 94 | 119 | return (*self); | ... | ... |
pyext/GFitsImageUShort.i
| ... | ... | @@ -66,30 +66,55 @@ public: |
| 66 | 66 | ***************************************************************************/ |
| 67 | 67 | %extend GFitsImageUShort { |
| 68 | 68 | unsigned short __getitem__(int GFitsImageInx[]) { |
| 69 | - if (GFitsImageInx[0] == 1) | |
| 70 | - return self->at(GFitsImageInx[1]); | |
| 71 | - else if (GFitsImageInx[0] == 2) | |
| 72 | - return self->at(GFitsImageInx[1], GFitsImageInx[2]); | |
| 73 | - else if (GFitsImageInx[0] == 3) | |
| 74 | - return self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]); | |
| 75 | - else if (GFitsImageInx[0] == 4) | |
| 76 | - return self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], GFitsImageInx[4]); | |
| 77 | - else | |
| 69 | + // Check image dimensions | |
| 70 | + for (int i = 0; i < GFitsImageInx[0]; ++i) { | |
| 71 | + if (GFitsImageInx[i+1] < 0 || GFitsImageInx[i+1] >= self->naxes(i)) { | |
| 72 | + throw GException::out_of_range("__getitem__(int)", | |
| 73 | + "FITS image axis "+ | |
| 74 | + gammalib::str(i)+" index", | |
| 75 | + GFitsImageInx[i+1], | |
| 76 | + self->naxes(i)); | |
| 77 | + } | |
| 78 | + } | |
| 79 | + // Return pixel value | |
| 80 | + if (GFitsImageInx[0] == 1) { | |
| 81 | + return (*self)(GFitsImageInx[1]); | |
| 82 | + } | |
| 83 | + else if (GFitsImageInx[0] == 2) { | |
| 84 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2]); | |
| 85 | + } | |
| 86 | + else if (GFitsImageInx[0] == 3) { | |
| 87 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]); | |
| 88 | + } | |
| 89 | + else if (GFitsImageInx[0] == 4) { | |
| 90 | + return (*self)(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], | |
| 91 | + GFitsImageInx[4]); | |
| 92 | + } | |
| 93 | + else { | |
| 78 | 94 | throw GException::fits_wrong_image_operator("__getitem__(int)", |
| 79 | 95 | self->naxis(), GFitsImageInx[0]); |
| 96 | + } | |
| 80 | 97 | } |
| 81 | 98 | void __setitem__(int GFitsImageInx[], unsigned short value) { |
| 82 | - if (GFitsImageInx[0] == 1) | |
| 99 | + if (GFitsImageInx[0] == 1) { | |
| 83 | 100 | self->at(GFitsImageInx[1]) = value; |
| 84 | - else if (GFitsImageInx[0] == 2) | |
| 101 | + } | |
| 102 | + else if (GFitsImageInx[0] == 2) { | |
| 85 | 103 | self->at(GFitsImageInx[1], GFitsImageInx[2]) = value; |
| 86 | - else if (GFitsImageInx[0] == 3) | |
| 87 | - self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]) = value; | |
| 88 | - else if (GFitsImageInx[0] == 4) | |
| 89 | - self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], GFitsImageInx[4]) = value; | |
| 90 | - else | |
| 104 | + } | |
| 105 | + else if (GFitsImageInx[0] == 3) { | |
| 106 | + self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3]) = | |
| 107 | + value; | |
| 108 | + } | |
| 109 | + else if (GFitsImageInx[0] == 4) { | |
| 110 | + self->at(GFitsImageInx[1], GFitsImageInx[2], GFitsImageInx[3], | |
| 111 | + GFitsImageInx[4]) = value; | |
| 112 | + } | |
| 113 | + else { | |
| 91 | 114 | throw GException::fits_wrong_image_operator("__setitem__(int)", |
| 92 | - self->naxis(), GFitsImageInx[0]); | |
| 115 | + self->naxis(), | |
| 116 | + GFitsImageInx[0]); | |
| 117 | + } | |
| 93 | 118 | } |
| 94 | 119 | GFitsImageUShort copy() { |
| 95 | 120 | return (*self); | ... | ... |