Skip to content

Commit

Permalink
Remove py27 relics, black everything
Browse files Browse the repository at this point in the history
  • Loading branch information
berland committed Jan 5, 2023
1 parent 8e8a167 commit 783b439
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 297 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

- name: Install dependencies
run: |
sudo pip install cmake-format black==22.1.0
sudo pip install cmake-format black
- name: Clang Format
run: ./script/clang-format --check
Expand All @@ -25,4 +25,4 @@ jobs:
- name: Black
run: |
black --check python/ --exclude=docs
black --check .
14 changes: 7 additions & 7 deletions cmake/create_cmakelists.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import sys



def findFilesAndDirectories(directory):
all_files = listdir(directory)
files = []
Expand All @@ -24,7 +23,8 @@ def findRelativeModulePath(directory):
"""@type directory: str"""
index = directory.rfind("python/")
index += len("python/")
return directory[index:len(directory)]
return directory[index : len(directory)]


def createPythonSources(files, test_sources=False):
result = ""
Expand All @@ -42,6 +42,7 @@ def createPythonSources(files, test_sources=False):

return result


def addSubDirectories(directories):
result = ""

Expand All @@ -50,20 +51,23 @@ def addSubDirectories(directories):

return result


def addPythonPackage(relative_module_path, test_sources=False):
module_name = ".".join(relative_module_path.split("/"))
source_type = "PYTHON_SOURCES" if not test_sources else "TEST_SOURCES"
template = "add_python_package(\"python.%s\" ${PYTHON_INSTALL_PREFIX}/%s \"${%s}\" %s)"
template = 'add_python_package("python.%s" ${PYTHON_INSTALL_PREFIX}/%s "${%s}" %s)'

install = "False" if test_sources else "True"

return template % (module_name, relative_module_path, source_type, install)


def addInclude(filename):
with open(filename, "r") as include_file:
content = include_file.read()
return content


files, directories = findFilesAndDirectories(sys.argv[1])
module_path = findRelativeModulePath(sys.argv[1])

Expand All @@ -79,7 +83,3 @@ def addInclude(filename):
if "local.cmake" in files:
text_file.write("\n\n")
text_file.write(addInclude(join(sys.argv[1], "local.cmake")))




202 changes: 0 additions & 202 deletions install/install.py

This file was deleted.

44 changes: 20 additions & 24 deletions python/docs/examples/avg_pressure.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
# three different methods.
def avg_pressure(p, sw, pv, region, region_id, result):
if region:
p_pv = p*pv
p_hc_pv = p*pv*(1 - sw)
hc_pv = pv*(1 - sw)
p_pv = p * pv
p_hc_pv = p * pv * (1 - sw)
hc_pv = pv * (1 - sw)

total_pv = pv.sum( mask = region )
total_hc_pv = hc_pv.sum( mask = region )
total_pv = pv.sum(mask=region)
total_hc_pv = hc_pv.sum(mask=region)

p1 = p.sum( mask = region) / region.active_size( )
p1 = p.sum(mask=region) / region.active_size()

if total_pv > 0:
p2 = p_pv.sum( mask = region ) / total_pv
p2 = p_pv.sum(mask=region) / total_pv
else:
p2 = None

if total_hc_pv > 0:
p3 = p_hc_pv.sum( mask = region ) / total_hc_pv
p3 = p_hc_pv.sum(mask=region) / total_hc_pv
else:
p3 = None
else:
Expand All @@ -35,15 +35,14 @@ def avg_pressure(p, sw, pv, region, region_id, result):
p3 = None

if not region_id in result:
result[region_id] = [[],[],[]]

result[region_id] = [[], [], []]

result[region_id][0].append(p1)
result[region_id][1].append(p2)
result[region_id][2].append(p3)


#-----------------------------------------------------------------
# -----------------------------------------------------------------

if __name__ == "__main__":
case = sys.argv[1]
Expand All @@ -52,33 +51,30 @@ def avg_pressure(p, sw, pv, region, region_id, result):
init_file = EclFile("%s.INIT" % case)

# Create PORV keyword where all the inactive cells have been removed.
pv = grid.compressed_kw_copy( init_file["PORV"][0] )
pv = grid.compressed_kw_copy(init_file["PORV"][0])

# Extract an integer region keyword from the init file
region_kw = init_file["EQLNUM"][0]


sim_days = []
result = {}
for header in rst_file.headers():
line = {}
rst_block = rst_file.restart_view( report_step = header.get_report_step( ) )
rst_block = rst_file.restart_view(report_step=header.get_report_step())
p = rst_block["PRESSURE"][0]
sw = rst_block["SWAT"][0]

for region_id in range(region_kw.get_max() + 1):
region = EclRegion(grid, False)
region.select_equal(region_kw, region_id)
avg_pressure(p, sw, pv, region, region_id, result)

for region_id in range(region_kw.get_max( ) + 1):
region = EclRegion( grid, False )
region.select_equal( region_kw, region_id )
avg_pressure( p, sw, pv , region, region_id, result)

avg_pressure( p, sw, pv , EclRegion( grid, True ), "field", result)
sim_days.append( header.get_sim_days( ) )

avg_pressure(p, sw, pv, EclRegion(grid, True), "field", result)
sim_days.append(header.get_sim_days())

for key in result.keys():
plt.figure(1)
for index,p in enumerate(result[key]):
plt.plot( sim_days, p , label="Region:%s P%d" % (key, index + 1))
for index, p in enumerate(result[key]):
plt.plot(sim_days, p, label="Region:%s P%d" % (key, index + 1))
plt.legend()
plt.show()
Loading

0 comments on commit 783b439

Please sign in to comment.