Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

These save functions have a lot in common. If you like consider creating an issue and attach this possible refactoring. #192

Open
kmilo9999 opened this issue Mar 11, 2024 · 0 comments

Comments

@kmilo9999
Copy link
Collaborator

          These save functions have a lot in common. If you like consider creating an issue and attach this possible refactoring.
def _generate_save_path_and_name(self, name=None, path=None, extension=".pdf"):
    name = re.sub("\.", "_", name) if name else DT.date.today().strftime("%Y%m%d_%I%M%p")
    savepath = (
        path
        if path
        else os.path.join(os.path.dirname(os.path.realpath("__file__")), "plot/")
    )
    if not os.path.exists(savepath):
        os.makedirs(savepath)
    full_name = (os.path.join(savepath, name)) + extension
    return full_name

def save(self, name=None, path=None, verbose=True):
    full_name = self._generate_save_path_and_name(name, path, ".pdf")
    self.fig.savefig(full_name, bbox_inches="tight", format="pdf", dpi=180)
    if verbose:
        print("save at: " + full_name)

def save_pup(self, name=None, path=None, verbose=True):
    full_name = self._generate_save_path_and_name(name, path, ".pdf")
    self.fig.savefig(full_name, bbox_inches="tight", format="pdf", dpi=300)
    if verbose:
        print("save at: ", full_name)

def save_light(self, name=None, path=None, verbose=True):
    full_name = self._generate_save_path_and_name(name, path, ".png")
    self.fig.savefig(full_name, bbox_inches="tight", format="png", dpi=180)
    if verbose:
        print("save with: ", name)

_Originally posted by @cpaniaguam in https://github.com/brown-ccv/icesat2waves/pull/131#discussion_r1516893298_
            
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant