Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/linting_and_testing.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,9 +46,8 @@ jobs:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
conda-remove-defaults: "true"

- name: Install dependencies for windows python 3.9 and 3.10
if: ${{ matrix.os == 'windows-latest' && (matrix.python-version == '3.9' || matrix.python-version == '3.10') }}
run: |
Expand DownExpand Up@@ -77,4 +76,4 @@ jobs:

- name: Run tests
run: |
conda run -n test pytest -v
conda run -n test pytest -v
50 changes: 50 additions & 0 deletions map2loop/logging.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -66,3 +66,53 @@ def set_level(level: str):
logger = logging.getLogger(name)
logger.setLevel(level)
logger.info(f"Logging level set to {level}")


logger = getLogger(__name__)
logger.info("Imported map2loop.logging module")


def setLogging(level="info", handler=None):
"""Set the logging parameters for log file or custom handler.

Parameters
----------
level : str, optional
Logging level to set, by default "info"
Valid options: 'info', 'warning', 'error', 'debug'
handler : logging.Handler, optional
A logging handler to use instead of the default StreamHandler, by default None

Examples
--------
>>> from map2loop.logging import setLogging
>>> setLogging('debug')
>>> setLogging('info', logging.FileHandler('loop.log'))
"""
levels = get_levels()
level_value = levels.get(level, logging.WARNING)

# Create default handler if none provided
if handler is None:
handler = logging.StreamHandler()

formatter = logging.Formatter(
"%(levelname)s: %(asctime)s: %(filename)s:%(lineno)d -- %(message)s"
)
handler.setFormatter(formatter)
handler.setLevel(level_value)

# Replace handlers in all known loggers
for name in loggers:
logger = logging.getLogger(name)
logger.handlers = []
logger.addHandler(handler)
logger.setLevel(level_value)

# Also apply to main module logger
main_logger = logging.getLogger(__name__)
main_logger.handlers = []
main_logger.addHandler(handler)
main_logger.setLevel(level_value)

main_logger.info(f"Set logging to {level}")
5 changes: 5 additions & 0 deletions map2loop/project.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -614,6 +614,11 @@ def calculate_stratigraphic_order(self, take_best=False):
self.sorter.structure_data = self.map_data.get_map_data(Datatype.STRUCTURE)
if hasattr(self.sorter, 'dtm_data') and self.sorter.dtm_data is None:
self.sorter.dtm_data = self.map_data.get_map_data(Datatype.DTM)
if hasattr(self.sorter, 'min_age_column') and self.sorter.min_age_column is None:
self.sorter.min_age_column = self.stratigraphic_column.get_min_age_column()
if hasattr(self.sorter, 'max_age_column') and self.sorter.max_age_column is None:
self.sorter.max_age_column = self.stratigraphic_column.get_max_age_column()

self.stratigraphic_column.column = self.sorter.sort(
self.stratigraphic_column.stratigraphicUnits,
)
Expand Down
3 changes: 2 additions & 1 deletion map2loop/sampler.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -52,7 +52,8 @@ def sample(
pandas.DataFrame: data frame containing samples
"""
pass

def __call__(self, **kwargs):
return self.sample(**kwargs)

class SamplerDecimator(Sampler):
"""
Expand Down
Loading
Loading