Skip to content

Commit

Permalink
print -> logger
Browse files Browse the repository at this point in the history
  • Loading branch information
CBroz1 committed Dec 21, 2023
1 parent 237cc2d commit 63eec83
Show file tree
Hide file tree
Showing 57 changed files with 589 additions and 486 deletions.
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
34 changes: 16 additions & 18 deletions src/spyglass/common/common_device.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import datajoint as dj
import ndx_franklab_novela

from spyglass.common.errors import PopulateException
from spyglass.utils.dj_mixin import SpyglassMixin

from ..utils.nwb_helper_fn import get_nwb_file
from .errors import PopulateException
from spyglass.utils.logging import logger
from spyglass.utils.nwb_helper_fn import get_nwb_file

schema = dj.schema("common_device")

Expand All @@ -14,7 +14,6 @@ class DataAcquisitionDeviceSystem(SpyglassMixin, dj.Manual):
definition = """
# Known data acquisition device system names.
data_acquisition_device_system: varchar(80)
---
"""


Expand All @@ -23,7 +22,6 @@ class DataAcquisitionDeviceAmplifier(SpyglassMixin, dj.Manual):
definition = """
# Known data acquisition device amplifier names.
data_acquisition_device_amplifier: varchar(80)
---
"""


Expand Down Expand Up @@ -84,12 +82,12 @@ def insert_from_nwbfile(cls, nwbf, config):
cls._add_device(new_device_dict)

if ndx_devices:
print(
logger.info(
"Inserted or referenced data acquisition device(s): "
+ f"{ndx_devices.keys()}"
)
else:
print("No conforming data acquisition device metadata found.")
logger.warn("No conforming data acquisition device metadata found.")

@classmethod
def get_all_device_names(cls, nwbf, config) -> tuple:
Expand Down Expand Up @@ -158,7 +156,7 @@ def _add_device(cls, new_device_dict):
).tolist()
if name not in all_values:
# no entry with the same name exists, prompt user to add a new entry
print(
logger.info(
f"\nData acquisition device '{name}' was not found in the "
f"database. The current values are: {all_values}. "
"Please ensure that the device you want to add does not already"
Expand Down Expand Up @@ -216,7 +214,7 @@ def _add_system(cls, system):
"data_acquisition_device_system"
).tolist()
if system not in all_values:
print(
logger.info(
f"\nData acquisition device system '{system}' was not found in"
f" the database. The current values are: {all_values}. "
"Please ensure that the system you want to add does not already"
Expand Down Expand Up @@ -267,7 +265,7 @@ def _add_amplifier(cls, amplifier):
"data_acquisition_device_amplifier"
).tolist()
if amplifier not in all_values:
print(
logger.info(
f"\nData acquisition device amplifier '{amplifier}' was not "
f"found in the database. The current values are: {all_values}. "
"Please ensure that the amplifier you want to add does not "
Expand Down Expand Up @@ -337,9 +335,9 @@ def insert_from_nwbfile(cls, nwbf):
cls.insert1(device_dict, skip_duplicates=True)
device_name_list.append(device_dict["camera_name"])
if device_name_list:
print(f"Inserted camera devices {device_name_list}")
logger.info(f"Inserted camera devices {device_name_list}")
else:
print("No conforming camera device metadata found.")
logger.warn("No conforming camera device metadata found.")
return device_name_list


Expand Down Expand Up @@ -442,7 +440,7 @@ def insert_from_nwbfile(cls, nwbf, config):
# the ones in the database
query = Probe & {"probe_id": new_probe_dict["probe_id"]}
if len(query) > 0:
print(
logger.info(
f"Probe ID '{new_probe_dict['probe_id']}' already exists in"
" the database. Spyglass will use that and not create a new"
" Probe, Shanks, or Electrodes."
Expand All @@ -457,9 +455,9 @@ def insert_from_nwbfile(cls, nwbf, config):
cls.Electrode.insert1(electrode, skip_duplicates=True)

if all_probes_types:
print(f"Inserted probes {all_probes_types}")
logger.info(f"Inserted probes {all_probes_types}")
else:
print("No conforming probe metadata found.")
logger.warn("No conforming probe metadata found.")

return all_probes_types

Expand Down Expand Up @@ -579,7 +577,7 @@ def _add_probe_type(cls, new_probe_type_dict):
probe_type = new_probe_type_dict["probe_type"]
all_values = ProbeType.fetch("probe_type").tolist()
if probe_type not in all_values:
print(
logger.info(
f"\nProbe type '{probe_type}' was not found in the database. "
f"The current values are: {all_values}. "
"Please ensure that the probe type you want to add does not "
Expand Down Expand Up @@ -663,7 +661,7 @@ def create_from_nwbfile(

query = ProbeType & {"probe_type": probe_type}
if len(query) == 0:
print(
logger.warn(
f"No ProbeType found with probe_type '{probe_type}'. Aborting."
)
return
Expand Down Expand Up @@ -727,7 +725,7 @@ def create_from_nwbfile(
]

if not device_found:
print(
logger.warn(
"No electrodes in the NWB file were associated with a device "
+ f"named '{nwb_device_name}'."
)
Expand Down
15 changes: 7 additions & 8 deletions src/spyglass/common/common_dio.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import pandas as pd
import pynwb

from spyglass.utils.dj_mixin import SpyglassMixin

from ..utils.nwb_helper_fn import get_data_interface, get_nwb_file
from .common_ephys import Raw
from .common_interval import IntervalList
from .common_nwbfile import Nwbfile
from .common_session import Session # noqa: F401
from spyglass.common.common_ephys import Raw
from spyglass.common.common_interval import IntervalList
from spyglass.common.common_nwbfile import Nwbfile
from spyglass.common.common_session import Session # noqa: F401
from spyglass.utils import SpyglassMixin, logger
from spyglass.utils.nwb_helper_fn import get_data_interface, get_nwb_file

schema = dj.schema("common_dio")

Expand All @@ -36,7 +35,7 @@ def make(self, key):
nwbf, "behavioral_events", pynwb.behavior.BehavioralEvents
)
if behav_events is None:
print(
logger.warn(
"No conforming behavioral events data interface found in "
+ f"{nwb_file_name}\n"
)
Expand Down
Loading

0 comments on commit 63eec83

Please sign in to comment.