Skip to content

Commit

Permalink
[522] black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
james.adams committed Sep 19, 2023
1 parent ead6196 commit e20eb3e
Show file tree
Hide file tree
Showing 18 changed files with 1,710 additions and 1,776 deletions.
10 changes: 4 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import toml

# since our source files are under a src folder we need to add that as our first path
sys.path.insert(0, os.path.abspath('../src'))
sys.path.insert(0, os.path.abspath("../src"))

# -- Project information -----------------------------------------------------

Expand All @@ -29,10 +29,10 @@
pyproject = toml.load("../pyproject.toml")

# get the full release version, including alpha/beta/rc tags
release = pyproject['tool']['poetry']['version']
release = pyproject["tool"]["poetry"]["version"]

# get the major.minor version
version = '.'.join(release.split('.')[:2])
version = ".".join(release.split(".")[:2])

# -- General configuration ---------------------------------------------------

Expand Down Expand Up @@ -149,9 +149,7 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, "climate_indices", "climate_indices Documentation", [author], 1)
]
man_pages = [(master_doc, "climate_indices", "climate_indices Documentation", [author], 1)]


# -- Options for Texinfo output ----------------------------------------------
Expand Down
39 changes: 23 additions & 16 deletions notebooks/concurrent_shared_memory_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"outputs": [],
"source": [
"# create a large array of random values\n",
"random = np.random.rand(400,400,1200)"
"random = np.random.rand(400, 400, 1200)"
]
},
{
Expand All @@ -34,7 +34,7 @@
"# create a shared memory array for the input and result arrays, copying the original input data\n",
"shm_random = shared_memory.SharedMemory(create=True, size=random.data.nbytes)\n",
"shared_random = np.ndarray(random.shape, dtype=random.dtype, buffer=shm_random.buf)\n",
"shared_random[:,:,:] = random[:,:,:]\n",
"shared_random[:, :, :] = random[:, :, :]\n",
"shm_name_random = shm_random.name\n",
"\n",
"shm_result = shared_memory.SharedMemory(create=True, size=random.data.nbytes)\n",
Expand All @@ -61,12 +61,21 @@
"def shm_add_average(\n",
" arguments: Dict,\n",
"):\n",
" existing_shm_input = shared_memory.SharedMemory(name=arguments['shm_name_input'])\n",
" shm_ary_input = np.ndarray(shape=arguments['shape'], dtype=arguments['dtype'], buffer=existing_shm_input.buf)\n",
" existing_shm_result = shared_memory.SharedMemory(name=arguments['shm_name_result'])\n",
" shm_ary_result = np.ndarray(shape=arguments['shape'], dtype=arguments['dtype'], buffer=existing_shm_result.buf)\n",
" shm_ary_result[arguments['lat_index'], arguments['lon_index']] = \\\n",
" add_average(shm_ary_input[arguments['lat_index'], arguments['lon_index']])"
" existing_shm_input = shared_memory.SharedMemory(name=arguments[\"shm_name_input\"])\n",
" shm_ary_input = np.ndarray(\n",
" shape=arguments[\"shape\"],\n",
" dtype=arguments[\"dtype\"],\n",
" buffer=existing_shm_input.buf,\n",
" )\n",
" existing_shm_result = shared_memory.SharedMemory(name=arguments[\"shm_name_result\"])\n",
" shm_ary_result = np.ndarray(\n",
" shape=arguments[\"shape\"],\n",
" dtype=arguments[\"dtype\"],\n",
" buffer=existing_shm_result.buf,\n",
" )\n",
" shm_ary_result[arguments[\"lat_index\"], arguments[\"lon_index\"]] = add_average(\n",
" shm_ary_input[arguments[\"lat_index\"], arguments[\"lon_index\"]]\n",
" )"
]
},
{
Expand All @@ -88,20 +97,18 @@
"arguments_list = []\n",
"for lat_index in range(shared_random.shape[0]):\n",
" for lon_index in range(shared_random.shape[1]):\n",
"\n",
" arguments = {\n",
" 'lat_index': lat_index,\n",
" 'lon_index': lon_index,\n",
" 'shm_name_input': shm_name_random,\n",
" 'shm_name_result': shm_name_result,\n",
" 'dtype': shared_random.dtype,\n",
" 'shape': shared_random.shape\n",
" \"lat_index\": lat_index,\n",
" \"lon_index\": lon_index,\n",
" \"shm_name_input\": shm_name_random,\n",
" \"shm_name_result\": shm_name_result,\n",
" \"dtype\": shared_random.dtype,\n",
" \"shape\": shared_random.shape,\n",
" }\n",
" arguments_list.append(arguments)\n",
"\n",
"# use a ProcessPoolExecutor to download the images in parallel\n",
"with concurrent.futures.ProcessPoolExecutor(max_workers=cpu_count()) as executor:\n",
"\n",
" # use the executor to map the download function to the iterable of arguments\n",
" executor.map(shm_add_average, arguments_list)"
]
Expand Down
Loading

0 comments on commit e20eb3e

Please sign in to comment.