File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -65,9 +65,9 @@ def get_tile_coord_from_nixy(nix, niy):
6565 Parameters
6666 ----------
6767 nix : str or list
68- tile number(s) for x
68+ tile number(s) for x coordinate(s);
6969 niy : str or list
70- tile number(s) for y
70+ tile number(s) for y coordinate(s)
7171
7272 See also
7373 --------
@@ -79,12 +79,25 @@ def get_tile_coord_from_nixy(nix, niy):
7979 right ascension and declination
8080
8181 """
82- # Transform to int
82+ number_pattern = re .compile (r'\d{3}' )
83+
84+ # Transform from str to int
8385 if not np .isscalar (nix ):
86+ # Check input numbers
87+ if not all (
88+ [bool (number_pattern .fullmatch (number )) for number in nix + niy ]
89+ ):
90+ raise ValueError ('Input needs to be three-digit numbers' )
91+
8492 # Transform to list
8593 xi = np .array (nix ).astype (int )
8694 yi = np .array (niy ).astype (int )
8795 else :
96+ if not all (
97+ [bool (number_pattern .fullmatch (number )) for number in [nix , niy ]]
98+ ):
99+ raise ValueError ('Input needs to be three-digit numbers' )
100+
88101 xi = int (nix )
89102 yi = int (niy )
90103
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ def setUp(self):
3030 self ._ra = [216.86237 , 214.43017 ]
3131 self ._unit = units .deg
3232
33+ self ._nix_nok = ['23x' , '1234' ]
3334 self ._tile_number_nok = '12x.456'
3435
3536 def tearDown (self ):
@@ -109,3 +110,23 @@ def test_get_tile_coord_from_nixy(self):
109110 # Test units
110111 self .assertTrue (ra [idx ].unit == self ._unit )
111112 self .assertTrue (dec [idx ].unit == self ._unit )
113+
114+ # Test exception for invalid input
115+ self .assertRaises (
116+ ValueError ,
117+ cfis .get_tile_coord_from_nixy ,
118+ self ._nix_nok ,
119+ self ._niy ,
120+ )
121+ self .assertRaises (
122+ ValueError ,
123+ cfis .get_tile_coord_from_nixy ,
124+ self ._niy ,
125+ self ._nix_nok ,
126+ )
127+ self .assertRaises (
128+ ValueError ,
129+ cfis .get_tile_coord_from_nixy ,
130+ self ._nix_nok [0 ],
131+ self ._niy [0 ],
132+ )
You can’t perform that action at this time.
0 commit comments