Skip to content

Commit

Permalink
print -> logger (LorenFrankLab#730)
Browse files Browse the repository at this point in the history
* print -> logger

* Changelog + notebook note on logger

* Fix typo
  • Loading branch information
CBroz1 authored Dec 21, 2023
1 parent 237cc2d commit daf671e
Show file tree
Hide file tree
Showing 60 changed files with 614 additions and 500 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Refactor restriction use in `delete_downstream_merge` #703
- Add `cautious_delete` to Mixin class, initial implementation. #711
- Add `deprecation_factory` to facilitate table migration. #717
- Add Spyglass logger. #730

### Pipelines

Expand Down
24 changes: 14 additions & 10 deletions notebooks/00_Setup.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"1. [Python 3.9](https://wiki.python.org/moin/BeginnersGuide/Download).\n",
"2. [mamba](https://mamba.readthedocs.io/en/latest/installation.html) as a\n",
" replacement for conda. Spyglass installation is significantly faster with\n",
" mamba. \n",
" mamba.\n",
" ```bash\n",
" wget \"https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh\"\n",
" bash Miniforge3-$(uname)-$(uname -m).sh\n",
Expand Down Expand Up @@ -133,7 +133,7 @@
"```\n",
"\n",
"Members of the lab can run the `dj_config.py` helper script to generate a config\n",
"like the one below. \n",
"like the one below.\n",
"\n",
"```bash\n",
"cd spyglass\n",
Expand All @@ -148,17 +148,16 @@
"[docs](https://lorenfranklab.github.io/spyglass/0.4/installation/) for more\n",
"information on subdirectories.\n",
"\n",
"A different `output_filename` will save different files: \n",
"A different `output_filename` will save different files:\n",
"\n",
"- `dj_local_conf.json`: Recommended. Used for tutorials. A file in the current\n",
" directory DataJoint will automatically recognize when a Python session is\n",
" launched from this directory.\n",
"- `.datajoint_config.json` or no input: A file in the user's home directory \n",
"- `.datajoint_config.json` or no input: A file in the user's home directory\n",
" that will be referenced whenever no local version (see above) is present.\n",
"- Anything else: A custom name that will need to be loaded (e.g.,\n",
" `dj.load('x')`) for each python session.\n",
"\n",
"\n",
"The config will be a `json` file like the following.\n",
"\n",
"```json\n",
Expand All @@ -170,6 +169,7 @@
" \"database.use_tls\": true,\n",
" \"enable_python_native_blobs\": true,\n",
" \"filepath_checksum_size_limit\": 1 * 1024**3,\n",
" \"loglevel\": \"INFO\",\n",
" \"stores\": {\n",
" \"raw\": {\n",
" \"protocol\": \"file\",\n",
Expand All @@ -190,14 +190,18 @@
"}\n",
"```\n",
"\n",
"Spyglass will use the log level present in your DataJoint config to decide the\n",
"appropriate logging level for this session. To change the messages you see,\n",
"select from one of [these options](https://docs.python.org/3/library/logging.html#levels).\n",
"\n",
"If you see an error saying `Could not find SPYGLASS_BASE_DIR`, try loading your\n",
"config before importing Spyglass.\n",
"\n",
"```python\n",
"import datajoint as dj\n",
"dj.load('/path/to/config')\n",
"import spyglass\n",
"```"
"```\n"
]
},
{
Expand Down Expand Up @@ -226,8 +230,8 @@
" ```\n",
"\n",
"_Note_: For this demo, MySQL version won't matter. Some\n",
" [database management](https://lorenfranklab.github.io/spyglass/latest/misc/database_management/#mysql-version)\n",
" features of Spyglass, however, expect MySQL >= 8.\n",
"[database management](https://lorenfranklab.github.io/spyglass/latest/misc/database_management/#mysql-version)\n",
"features of Spyglass, however, expect MySQL >= 8.\n",
"\n",
"- When run, this is referred to as a 'Docker container'\n",
"- Next start the container with a couple additional pieces of info...\n",
Expand Down Expand Up @@ -277,7 +281,7 @@
"source": [
"### Loading the config\n",
"\n",
"We can check that the paths are correctly set up by loading the config from \n",
"We can check that the paths are correctly set up by loading the config from\n",
"the main Spyglass directory.\n"
]
},
Expand Down Expand Up @@ -471,7 +475,7 @@
"id": "13fd64af",
"metadata": {},
"source": [
"# Up Next"
"# Up Next\n"
]
},
{
Expand Down
13 changes: 9 additions & 4 deletions notebooks/py_scripts/00_Setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@
# - Anything else: A custom name that will need to be loaded (e.g.,
# `dj.load('x')`) for each python session.
#
#
# The config will be a `json` file like the following.
#
# ```json
Expand All @@ -147,6 +146,7 @@
# "database.use_tls": true,
# "enable_python_native_blobs": true,
# "filepath_checksum_size_limit": 1 * 1024**3,
# "loglevel": "INFO",
# "stores": {
# "raw": {
# "protocol": "file",
Expand All @@ -167,6 +167,10 @@
# }
# ```
#
# Spyglass will use the log level present in your DataJoint config to decide the
# appropriate logging level for this session. To change the messages you see,
# select from one of [these options](https://docs.python.org/3/library/logging.html#levels).
#
# If you see an error saying `Could not find SPYGLASS_BASE_DIR`, try loading your
# config before importing Spyglass.
#
Expand All @@ -175,6 +179,7 @@
# dj.load('/path/to/config')
# import spyglass
# ```
#

# ### Running your own database
#
Expand All @@ -192,8 +197,8 @@
# ```
#
# _Note_: For this demo, MySQL version won't matter. Some
# [database management](https://lorenfranklab.github.io/spyglass/latest/misc/database_management/#mysql-version)
# features of Spyglass, however, expect MySQL >= 8.
# [database management](https://lorenfranklab.github.io/spyglass/latest/misc/database_management/#mysql-version)
# features of Spyglass, however, expect MySQL >= 8.
#
# - When run, this is referred to as a 'Docker container'
# - Next start the container with a couple additional pieces of info...
Expand Down Expand Up @@ -244,7 +249,6 @@

# +
import os

import datajoint as dj

if os.path.basename(os.getcwd()) == "notebooks":
Expand All @@ -270,6 +274,7 @@
# -

# # Up Next
#

# Next, we'll try [inserting data](./01_Insert_Data.ipynb)
#
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dependencies = [
"numpy<1.24",
"ipympl",
"tqdm",
"pubnub<6.4.0",
"pubnub<6.4.0", # TODO: remove this when sortingview is updated
"pynwb>=2.2.0,<3",
"hdmf>=3.4.6",
"datajoint>=0.13.6",
Expand Down
26 changes: 13 additions & 13 deletions src/spyglass/common/common_behav.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from spyglass.common.common_session import Session # noqa: F401
from spyglass.common.common_task import TaskEpoch
from spyglass.settings import video_dir
from spyglass.utils.dj_mixin import SpyglassMixin
from spyglass.utils import SpyglassMixin, logger
from spyglass.utils.nwb_helper_fn import (
get_all_spatial_series,
get_data_interface,
Expand Down Expand Up @@ -174,7 +174,7 @@ def fetch1_dataframe(self):
id_rp = [(n["id"], n["raw_position"]) for n in self.fetch_nwb()]

if len(set(rp.interval for _, rp in id_rp)) > 1:
print("WARNING: loading DataFrame with multiple intervals.")
logger.warn("Loading DataFrame with multiple intervals.")

df_list = [
pd.DataFrame(
Expand Down Expand Up @@ -270,7 +270,7 @@ def make(self, key):
"associated_files"
) or nwbf.processing.get("associated files")
if associated_files is None:
print(
logger.info(
"Unable to import StateScriptFile: no processing module named "
+ '"associated_files" found in {nwb_file_name}.'
)
Expand All @@ -280,7 +280,7 @@ def make(self, key):
if not isinstance(
associated_file_obj, ndx_franklab_novela.AssociatedFiles
):
print(
logger.info(
f"Data interface {associated_file_obj.name} within "
+ '"associated_files" processing module is not '
+ "of expected type ndx_franklab_novela.AssociatedFiles\n"
Expand All @@ -293,7 +293,7 @@ def make(self, key):

epoch_list = associated_file_obj.task_epochs.split(",")
# only insert if this is the statescript file
print(associated_file_obj.description)
logger.info(associated_file_obj.description)
if (
"statescript".upper() in associated_file_obj.description.upper()
or "state_script".upper()
Expand All @@ -306,7 +306,7 @@ def make(self, key):
key["file_object_id"] = associated_file_obj.object_id
self.insert1(key)
else:
print("not a statescript file")
logger.info("not a statescript file")


@schema
Expand Down Expand Up @@ -347,7 +347,7 @@ def _no_transaction_make(self, key, verbose=True):
)

if videos is None:
print(f"No video data interface found in {nwb_file_name}\n")
logger.warn(f"No video data interface found in {nwb_file_name}\n")
return
else:
videos = videos.time_series
Expand Down Expand Up @@ -388,7 +388,7 @@ def _no_transaction_make(self, key, verbose=True):
is_found = True

if not is_found and verbose:
print(
logger.info(
f"No video found corresponding to file {nwb_file_name}, "
+ f"epoch {interval_list_name}"
)
Expand Down Expand Up @@ -471,7 +471,7 @@ def _no_transaction_make(self, key):

# Skip populating if no pos interval list names
if len(pos_intervals) == 0:
print(f"NO POS INTERVALS FOR {key}; {no_pop_msg}")
logger.error(f"NO POS INTERVALS FOR {key}; {no_pop_msg}")
return

valid_times = (IntervalList & key).fetch1("valid_times")
Expand Down Expand Up @@ -508,7 +508,7 @@ def _no_transaction_make(self, key):

# Check that each pos interval was matched to only one epoch
if len(matching_pos_intervals) != 1:
print(
logger.error(
f"Found {len(matching_pos_intervals)} pos intervals for {key}; "
+ f"{no_pop_msg}\n{matching_pos_intervals}"
)
Expand All @@ -517,7 +517,7 @@ def _no_transaction_make(self, key):
# Insert into table
key["position_interval_name"] = matching_pos_intervals[0]
self.insert1(key, allow_direct_insert=True)
print(
logger.info(
"Populated PosIntervalMap for "
+ f'{nwb_file_name}, {key["interval_list_name"]}'
)
Expand Down Expand Up @@ -569,7 +569,7 @@ def convert_epoch_interval_name_to_position_interval_name(
)

if len(pos_query) == 0:
print(f"No position intervals found for {key}")
logger.info(f"No position intervals found for {key}")
return []

if len(pos_query) == 1:
Expand All @@ -596,7 +596,7 @@ def get_interval_list_name_from_epoch(nwb_file_name: str, epoch: int) -> str:
).fetch("interval_list_name")

if len(interval_names) != 1:
print(
logger.info(
f"Found {len(interval_names)} interval list names found for "
+ f"{nwb_file_name} epoch {epoch}"
)
Expand Down
Loading

0 comments on commit daf671e

Please sign in to comment.