diff --git a/README.md b/README.md index 55f76d6..d3b7a14 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,12 @@ For more information, see volcano-cooking --help ``` +> [!TIP] +> +> It is also possible to run the CLI as a python module. Try: `python -m volcano_cooking +> --help`, `python -m volcano_cooking.view_forcing --help` or `python -m +> volcano_cooking.sparse_to_lin --help`. + #### Option 0 (default, using NCL-script) ##### TL;DR diff --git a/src/volcano_cooking/__init__.py b/src/volcano_cooking/__init__.py index 44f01da..5c7e2e7 100644 --- a/src/volcano_cooking/__init__.py +++ b/src/volcano_cooking/__init__.py @@ -1,4 +1,5 @@ """Create source and forcing files used in the CESM2 climate model.""" + from importlib_metadata import version __version__ = version(__package__) diff --git a/src/volcano_cooking/__main__.py b/src/volcano_cooking/__main__.py index 7065bd4..345c71d 100644 --- a/src/volcano_cooking/__main__.py +++ b/src/volcano_cooking/__main__.py @@ -190,3 +190,7 @@ def get_forcing_file( ) else: sys.exit("Okay, I won't download it. Exiting gracefully.") + + +if __name__ == "__main__": + main() diff --git a/src/volcano_cooking/configurations/shift_eruption_to_date.py b/src/volcano_cooking/configurations/shift_eruption_to_date.py index fd6cd84..54b2173 100644 --- a/src/volcano_cooking/configurations/shift_eruption_to_date.py +++ b/src/volcano_cooking/configurations/shift_eruption_to_date.py @@ -7,7 +7,6 @@ generated in that file, before a second file is saved with the shifted eruption. """ - from typing import Optional, Tuple import numpy as np diff --git a/src/volcano_cooking/modules/convert/adjust_emissions_and_heights.py b/src/volcano_cooking/modules/convert/adjust_emissions_and_heights.py index 2367333..0323dc0 100644 --- a/src/volcano_cooking/modules/convert/adjust_emissions_and_heights.py +++ b/src/volcano_cooking/modules/convert/adjust_emissions_and_heights.py @@ -9,6 +9,7 @@ Modified from script provided by Herman Fæhn Fuglestvedt and using http://svn.code.sf.net/p/codescripts/code/trunk/ncl/emission/createVolcEruptV3.ncl """ + import os from typing import Tuple diff --git a/src/volcano_cooking/modules/create/create_data.py b/src/volcano_cooking/modules/create/create_data.py index e60dbca..be3ecfd 100644 --- a/src/volcano_cooking/modules/create/create_data.py +++ b/src/volcano_cooking/modules/create/create_data.py @@ -184,15 +184,15 @@ def make_dataset(self) -> None: self.my_frc["Total_Emission"] = self.my_frc.Total_Emission.assign_attrs( Units="Tg_of_SO2" ) - self.my_frc[ - "Maximum_Injection_Height" - ] = self.my_frc.Maximum_Injection_Height.assign_attrs( - Units="km_above_mean_sea_level" + self.my_frc["Maximum_Injection_Height"] = ( + self.my_frc.Maximum_Injection_Height.assign_attrs( + Units="km_above_mean_sea_level" + ) ) - self.my_frc[ - "Minimum_Injection_Height" - ] = self.my_frc.Minimum_Injection_Height.assign_attrs( - Units="km_above_mean_sea_level" + self.my_frc["Minimum_Injection_Height"] = ( + self.my_frc.Minimum_Injection_Height.assign_attrs( + Units="km_above_mean_sea_level" + ) ) def save_to_file(self) -> None: diff --git a/src/volcano_cooking/modules/create/create_dates.py b/src/volcano_cooking/modules/create/create_dates.py index 62e69d2..2ec3fc1 100644 --- a/src/volcano_cooking/modules/create/create_dates.py +++ b/src/volcano_cooking/modules/create/create_dates.py @@ -1,6 +1,5 @@ """Script to put any function that creates correctly formatted dates.""" - import datetime as dt from itertools import cycle from typing import List, Tuple, Union diff --git a/src/volcano_cooking/modules/create/rewrite_frc_file.py b/src/volcano_cooking/modules/create/rewrite_frc_file.py index 89c2731..2160233 100644 --- a/src/volcano_cooking/modules/create/rewrite_frc_file.py +++ b/src/volcano_cooking/modules/create/rewrite_frc_file.py @@ -13,6 +13,7 @@ and find a suitable altitude (perhaps from `volcano-cooking`). Then the values are set using the implementations from `volcano-cooking`. """ + import os from datetime import datetime @@ -159,9 +160,9 @@ def __set_global_attrs(self, file) -> None: + f"volcanoes, {start}-{end}" ) elif a == "data_creator": - self.my_frc.attrs[ - a - ] = "Eirik Rolland Enger, University of Tromsø, eirik.r.enger@uit.no" + self.my_frc.attrs[a] = ( + "Eirik Rolland Enger, University of Tromsø, eirik.r.enger@uit.no" + ) elif a == "data_doi": self.my_frc.attrs[a] = "No doi yet" elif a == "data_source_url": @@ -179,9 +180,9 @@ def __set_global_attrs(self, file) -> None: elif a == "cesm_contact": self.my_frc.attrs[a] = "None" elif a == "data_script": - self.my_frc.attrs[ - a - ] = "Generated with the 'volcano-cooking' CLI with the re-write option." + self.my_frc.attrs[a] = ( + "Generated with the 'volcano-cooking' CLI with the re-write option." + ) elif a == "data_summary": nd = ( 10000 * self.yoes.astype(np.float32) diff --git a/src/volcano_cooking/plotting/figure_standards.py b/src/volcano_cooking/plotting/figure_standards.py index a6523cd..d2162c5 100644 --- a/src/volcano_cooking/plotting/figure_standards.py +++ b/src/volcano_cooking/plotting/figure_standards.py @@ -190,13 +190,15 @@ def log_tick_format(axes: plt.Axes, which: str, base: float = 10) -> plt.Axes: f = getattr(axes, ax) f.set_major_formatter( ticker.FuncFormatter( - lambda x, _: "{:g}".format(x) - if np.log(x) / np.log(base) in [0, 1] - else r"$" - + str(base) - + "^{" - + "{:g}".format(np.log(x) / np.log(base)) - + r"}$" + lambda x, _: ( + "{:g}".format(x) + if np.log(x) / np.log(base) in [0, 1] + else r"$" + + str(base) + + "^{" + + "{:g}".format(np.log(x) / np.log(base)) + + r"}$" + ) ) ) return axes diff --git a/src/volcano_cooking/synthetic_volcanoes.py b/src/volcano_cooking/synthetic_volcanoes.py index 92a9908..a301412 100644 --- a/src/volcano_cooking/synthetic_volcanoes.py +++ b/src/volcano_cooking/synthetic_volcanoes.py @@ -7,6 +7,7 @@ The lat/lon location is also included, but considered unimportant and thus the same location is used for all volcanoes. """ + from typing import Optional import volcano_cooking.modules.create as create diff --git a/src/volcano_cooking/view_force.py b/src/volcano_cooking/view_force.py index a378ad5..4fc688c 100644 --- a/src/volcano_cooking/view_force.py +++ b/src/volcano_cooking/view_force.py @@ -64,3 +64,7 @@ def main( if style not in styles: sys.exit(f"Style '{style}' not available. Available styles: {styles}") v.view_forcing(in_file=filename, width=width, style=style, dark=dark, save=save) + + +if __name__ == "__main__": + main()