Generate Zoned Rectangle¶
This example shows how to make use of gFunctionDatabase.coordinate_generator.ZonedRectangle()
to create a series of rectangles with an outer perimeter (fixed spacing) base case
of 7x12.
Fig. 6 A gif of the systematic reduction of rows or columns for a zoned rectangle - whichever one will have the most uniform interior spacing. Ends with 1 borhole in center of field.¶
The files are stored in a key: value dictionary. The key for zoned rectangles is created in the function
gFunctionDatabase.coordinate_generator.ZonedRectangle.hash_key().
Nix |
5 |
4 |
4 |
4 |
3 |
3 |
3 |
2 |
2 |
1 |
1 |
1 |
1 |
Niy |
9 |
9 |
8 |
7 |
7 |
6 |
5 |
5 |
4 |
4 |
3 |
2 |
1 |
Source Code¶
1# Jack C. Cook
2# Saturday, February 6, 2021
3
4import gFunctionDatabase as gfl
5from natsort import natsorted
6from PIL import Image
7import os
8
9
10def main():
11 # Zoned Rectangle example: 7x12 field
12 # ------- Inputs --------
13 Nx = 7 # number of boreholes in the x-direction
14 Ny = 12 # number of boreholes in the y-direction
15 B = 5 # uniform spacing around outer perimeter
16 # -----------------------
17 z_rectangles = gfl.coordinate_generator.ZonedRectangle(Nx=Nx, Ny=Ny, B=B)
18 # Plot all of the borefields created, will be saved in /ZRect/Plots/
19 z_rectangles.visualize_coordinates('ZRect/Plots/', plot_ext='png')
20 print(z_rectangles.coordinates)
21
22 # Create csv files
23 z_rectangles.export_coordinates('ZRect/CSVs/')
24
25 # create a .gif from the plots we created
26 # Source: https://stackoverflow.com/a/57751793/11637415
27 # Note: Pillow wanted pngs for creating the gif
28 file_plot_names = os.listdir('ZRect/Plots/')
29 # we need to reverse the order to start from less zone to more zone, we'll use natsort to do it
30 # # sort the keys by order from largest to smallest
31 file_plot_names = natsorted(file_plot_names)
32 file_plot_names_sorted = list(reversed(file_plot_names))
33 print(file_plot_names_sorted)
34 frames = []
35 for file in file_plot_names_sorted:
36 frames.append(Image.open('ZRect/Plots/' + file))
37
38 frames[0].save(fp='ZRect/ZRect.gif', format='GIF', append_images=frames[0:],
39 save_all=True, duration=800, loop=0)
40
41
42if __name__ == '__main__':
43 main()