Created
March 10, 2020 23:38
-
-
Save phargogh/a1443cc0b5c9f4af9e85a7c0025ba5a6 to your computer and use it in GitHub Desktop.
Getting linetracing to work with cython
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/setup.py b/setup.py | |
index 46be1b36..67b5a1df 100644 | |
--- a/setup.py | |
+++ b/setup.py | |
@@ -96,6 +96,8 @@ setup( | |
Extension( | |
name="natcap.invest.sdr.sdr_core", | |
sources=['src/natcap/invest/sdr/sdr_core.pyx'], | |
+ define_macros=[('CYTHON_TRACE', '1')], | |
+ compiler_directives={'linetrace': True}, | |
include_dirs=[numpy.get_include()], | |
language="c++"), | |
Extension( | |
diff --git a/src/natcap/invest/sdr/sdr_core.pyx b/src/natcap/invest/sdr/sdr_core.pyx | |
index e2993749..a2569746 100644 | |
--- a/src/natcap/invest/sdr/sdr_core.pyx | |
+++ b/src/natcap/invest/sdr/sdr_core.pyx | |
@@ -1,5 +1,6 @@ | |
# cython: profile=False | |
# cython: language_level=3 | |
+# cython: linetrace=True | |
import logging | |
import os | |
@@ -571,6 +572,7 @@ def calculate_sediment_deposition( | |
sediment_deposition_raster.close() | |
[email protected](True) | |
def calculate_average_aspect( | |
mfd_flow_direction_path, target_average_aspect_path): | |
"""Calculate the Average Proportional Flow from MFD. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run this from within an activated virtual environment. | |
import logging | |
logging.basicConfig(level=logging.DEBUG) | |
import line_profiler | |
from natcap.invest.sdr import sdr_core | |
def doit(): | |
profile = line_profiler.LineProfiler(sdr_core.calculate_average_aspect) | |
profile.runcall( | |
sdr_core.calculate_average_aspect, | |
r'C:\Users\jdouglass\Downloads\2020-03-09-sdr-test-runs\testing-4\intermediate_outputs\flow_direction_gura.tif', | |
'avg_aspect.tif') | |
profile.print_stats() | |
if __name__ == '__main__': | |
doit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment