-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
--version
option to the programs
- Loading branch information
Showing
10 changed files
with
71 additions
and
54 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,14 @@ | ||
import os | ||
|
||
import xarray as xr | ||
|
||
from pbp.logging_helper import PbpLogger | ||
|
||
|
||
def save_dataset_to_netcdf(logger: PbpLogger, ds: xr.Dataset, filename: str) -> bool: | ||
logger.info(f" - saving dataset to: {filename}") | ||
try: | ||
ds.to_netcdf( | ||
filename, | ||
engine="h5netcdf", | ||
encoding={ | ||
"effort": {"_FillValue": None}, | ||
"frequency": {"_FillValue": None}, | ||
"sensitivity": {"_FillValue": None}, | ||
}, | ||
) | ||
return True | ||
except Exception as e: # pylint: disable=broad-exception-caught | ||
error = f"Unable to save {filename}: {e}" | ||
logger.error(error) | ||
print(error) | ||
return False | ||
|
||
|
||
def save_dataset_to_csv(logger: PbpLogger, ds: xr.Dataset, filename: str): | ||
logger.info(f" - saving dataset to: {filename}") | ||
def get_pbp_version() -> str: | ||
try: | ||
ds.to_pandas().to_csv(filename, float_format="%.1f") | ||
except Exception as e: # pylint: disable=broad-exception-caught | ||
logger.error(f"Unable to save {filename}: {e}") | ||
|
||
|
||
def get_cpus_to_use(num_cpus: int) -> int: | ||
cpu_count: int = os.cpu_count() or 1 | ||
if num_cpus <= 0 or num_cpus > cpu_count: | ||
num_cpus = cpu_count | ||
return num_cpus | ||
|
||
|
||
class PBPException(Exception): | ||
""" | ||
Placeholder for a more specific exception. | ||
""" | ||
|
||
def __init__(self, msg: str): | ||
super().__init__(f"PBPException({msg})") | ||
import importlib.metadata | ||
|
||
return importlib.metadata.version("mbari-pbp") | ||
except Exception: # pylint: disable=broad-exception-caught | ||
try: | ||
from poetry.core.factory import Factory | ||
|
||
factory = Factory() | ||
poetry = factory.create_poetry() | ||
return poetry.package.version.text | ||
except Exception: # pylint: disable=broad-exception-caught | ||
return "version not found" |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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