11import numpy as np
22import pytest
33import unyt
4- from numpy .typing import NDArray
54
65import yt
76from yt .data_objects .selection_objects .region import YTRegion
@@ -167,20 +166,19 @@ def makemasses(i, j, k):
167166 assert_rel_equal (expected_out , img .v , 5 )
168167
169168
170-
171169@pytest .mark .parametrize ("axis" , [0 , 1 , 2 ])
172170@pytest .mark .parametrize ("shiftcenter" , [True , False ])
173171@pytest .mark .parametrize ("periodic" , [True , False ])
174172@pytest .mark .parametrize ("depth" , [None , (1.0 , "cm" ), (5.0 , "cm" )])
175- @pytest .mark .parametrize ("hsmlfac" , [0.2 , 0.5 , 1.0 ])
173+ @pytest .mark .parametrize ("hsmlfac" , [0.2 , 0.5 , 1.0 ])
176174def test_sph_proj_pixelave_alongaxes (
177175 axis : int ,
178176 shiftcenter : bool ,
179177 periodic : bool ,
180178 depth : float ,
181179 hsmlfac : float ,
182180) -> None :
183- # weighted and unweighted tested in one round:
181+ # weighted and unweighted tested in one round:
184182 # need weight map to downsample the baseline weighted map
185183 if shiftcenter :
186184 center = unyt .unyt_array (np .array ((0.6 , 0.5 , 0.4 )), "cm" )
@@ -279,9 +277,8 @@ def makemasses(i, j, k):
279277 baseimg = resreduce_image (_baseimg , buff_size )
280278 _baseimg_wtd = baseprj_wtd .frb .data [("gas" , "density" )]
281279 _divimg = np .copy (baseimg .v )
282- _divimg [_divimg == 0. ] = - 1. # avoid div. by 0 test failures
283- baseimg_wtd = (resreduce_image (_baseimg * _baseimg_wtd .v , buff_size )
284- / _divimg )
280+ _divimg [_divimg == 0.0 ] = - 1.0 # avoid div. by 0 test failures
281+ baseimg_wtd = resreduce_image (_baseimg * _baseimg_wtd .v , buff_size ) / _divimg
285282
286283 print (
287284 f"axis: { axis } , shiftcenter: { shiftcenter } , "
@@ -301,46 +298,48 @@ def makemasses(i, j, k):
301298 # subsampling with multiple particles is not quite at 4.
302299 # pixel values seem to converge more slowly though, so we test
303300 # mass conservation explicitly, and pixel agreement at low
304- # precision
301+ # precision
305302 assert_rel_equal (baseimg .v , testimg .v , 1 )
306303 assert_rel_equal (np .sum (baseimg .v ), np .sum (testimg .v ), 2 )
307304 assert_rel_equal (baseimg_wtd .v , testimg_wtd .v , 1 )
308305
309306
310307def test_massconservation_pixave ():
311- bbox = np .array ([[0. , 3. ], [0. , 3. ], [0. , 3. ]])
308+ bbox = np .array ([[0.0 , 3.0 ], [0.0 , 3.0 ], [0.0 , 3.0 ]])
312309 pz = 1.5
313310 periodic = True
314- periods = 3.
311+ periods = 3.0
315312 nrandom = 50
316-
313+
317314 # random centers, three pixel size + hsml sets
318315 # test three cases in the backend routine
319316 rng = np .random .default_rng ()
320- pxs = rng .uniform (0. , 3. , nrandom )
321- pys = rng .uniform (0. , 3. , nrandom )
317+ pxs = rng .uniform (0.0 , 3.0 , nrandom )
318+ pys = rng .uniform (0.0 , 3.0 , nrandom )
322319 # particles < pixels: overlap 1, 2x1, or 2x2 pixels
323320 hsmls1 = rng .uniform (0.01 , 0.05 , nrandom )
324321 outsize1 = (7 , 7 )
325322 # particles ~ pixels: typical 2x2 overlaps
326323 hsmls2 = rng .uniform (0.1 , 0.25 , nrandom )
327324 outsize2 = (7 , 7 )
328- # particles > pixels:
325+ # particles > pixels:
329326 hsmls3 = rng .uniform (0.07 , 0.8 , nrandom )
330327 outsize3 = (50 , 50 )
331-
332- for i , (hsmls , outsize ) in enumerate ([(hsmls1 , outsize1 ),
333- (hsmls2 , outsize2 ),
334- (hsmls3 , outsize3 ),
335- ]):
336328
329+ for i , (hsmls , outsize ) in enumerate (
330+ [
331+ (hsmls1 , outsize1 ),
332+ (hsmls2 , outsize2 ),
333+ (hsmls3 , outsize3 ),
334+ ]
335+ ):
337336 masses_rel = []
338337 for i in range (nrandom ):
339338 data = {
340339 "particle_position_x" : (np .array ([pxs [i ]]), "cm" ),
341340 "particle_position_y" : (np .array ([pys [i ]]), "cm" ),
342341 "particle_position_z" : (np .array ([pz ]), "cm" ),
343- "particle_mass" : (np .array ([1. ]), "g" ),
342+ "particle_mass" : (np .array ([1.0 ]), "g" ),
344343 "particle_velocity_x" : (np .zeros (1 ), "cm/s" ),
345344 "particle_velocity_y" : (np .zeros (1 ), "cm/s" ),
346345 "particle_velocity_z" : (np .zeros (1 ), "cm/s" ),
@@ -360,25 +359,28 @@ def test_massconservation_pixave():
360359
361360 proj = ds .proj (("gas" , "density" ), 2 )
362361 frb = proj .to_frb (
363- width = (3. , "cm" ),
362+ width = (3.0 , "cm" ),
364363 resolution = outsize ,
365- height = (3. , "cm" ),
364+ height = (3.0 , "cm" ),
366365 center = np .array ([1.5 , 1.5 , 1.5 ]),
367366 periodic = True ,
368367 pixelmeaning = "pixelave" ,
369368 )
370369 out = frb .get_image (("gas" , "density" ))
371- mass_in = 1.
370+ mass_in = 1.0
372371 mass_out = np .sum (out .v ) * periods ** 2 / np .prod (outsize )
373- masses_rel .append (mass_out / mass_in - 1. )
372+ masses_rel .append (mass_out / mass_in - 1.0 )
374373 masses_rel = np .array (masses_rel )
375374 minrel = np .min (masses_rel )
376375 maxrel = np .max (masses_rel )
377- print (f"Mass conservation test pixel/hsml set { i } :"
378- " mass conservation deviations fractions"
379- f" { minrel :.2e} -- { maxrel :.2e} " )
376+ print (
377+ f"Mass conservation test pixel/hsml set { i } :"
378+ " mass conservation deviations fractions"
379+ f" { minrel :.2e} -- { maxrel :.2e} "
380+ )
380381 assert np .all (np .abs (masses_rel ) < 1e-4 )
381382
383+
382384@pytest .mark .parametrize ("periodic" , [True , False ])
383385@pytest .mark .parametrize ("shiftcenter" , [False , True ])
384386@pytest .mark .parametrize ("zoff" , [0.0 , 0.1 , 0.5 , 1.0 ])
0 commit comments