Skip to content

Commit

Permalink
Some bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ajwdewit committed Jan 22, 2025
1 parent aab3245 commit 8cdfb4e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 32 deletions.
32 changes: 16 additions & 16 deletions agera5tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@
# Allard de Wit ([email protected])

import os, sys

__version__ = "2.1.0"
# This will be set to 1 only for commandline mode. Not when importing
# agera5tools in python.
os.environ["CMD_MODE"] = "0"
from pathlib import Path
import logging
import logging.config

import yaml
from dotmap import DotMap
import click

from . import util

__version__ = "2.1.0"

def setup_logging(config, has_filesystem):
"""sets up the logging system for both logging to file and to console.
Expand Down Expand Up @@ -96,6 +91,7 @@ def setup_logging(config, has_filesystem):
else:
logging.config.dictConfig(LOG_CONFIG_RTD)


def read_config(mk_paths=True):
"""Reads the YAML file with configuration for AgERA5tools
Expand All @@ -107,6 +103,9 @@ def read_config(mk_paths=True):
:return:a DotMap object with the configuration
"""
from .util import BoundingBox
import yaml
from dotmap import DotMap
import click

has_config = False
if "AGERA5TOOLS_CONFIG" in os.environ:
Expand Down Expand Up @@ -143,19 +142,20 @@ def read_config(mk_paths=True):

return c


has_filesystem = False if "READTHEDOCS" in os.environ else True
config = read_config(mk_paths=has_filesystem)
if config:
setup_logging(config, has_filesystem)

from . import util
from .dump_grid import dump_grid
from .dump_clip import dump, clip
from .extract_point import extract_point
from . import build
from . import init
from . import check
from . import mirror
if "READTHEDOCS" not in os.environ:
from . import util
from .dump_grid import dump_grid
from .dump_clip import dump, clip
from .extract_point import extract_point
from . import build
from . import init
from . import check
from . import mirror



Expand Down
1 change: 1 addition & 0 deletions agera5tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ def get_nc_filenames(varnames, year, month, day=None, check=True):

return nc_fnames


def build(year_month=None, to_database=True, to_csv=False):
"""Builds the AgERA5tools database.
Expand Down
22 changes: 8 additions & 14 deletions agera5tools/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,17 @@ def cmd_init():
help="Load AgERA5 data into the database")
@click.option("-c", "--to_csv", is_flag=True, flag_value=True,
help="Write AgERA5 data to compressed CSV files.")
@click.option("-p", "--to_parquet", is_flag=True, flag_value=True,
help="Write AgERA5 data to parquet files.")
def cmd_build(to_database, to_csv, to_parquet):
def cmd_build(to_database, to_csv):
"""Builds the AgERA5 database by bulk download from CDS
"""
print(f"Export to database: {to_database}")
print(f"Export to CSV: {to_csv}")
print(f"Export to Parquet: {to_parquet}")
if to_csv is False and to_database is False and to_parquet is False:
if to_csv is False and to_database is False:
msg = ("Warning: Only NetCDF files will be updated, no tabular output will be written, "
"use either --to_database, --to_csv or --to_parquet")
"use either --to_database, --to_csv")
click.echo(msg)

build(None, to_database, to_csv, to_parquet)
build(None, to_database, to_csv)
msg = "Done building database, use the `mirror` command to keep the DB up to date"
click.echo(msg)

Expand All @@ -184,20 +181,17 @@ def cmd_build(to_database, to_csv, to_parquet):
help="Load AgERA5 data into the database")
@click.option("-c", "--to_csv", is_flag=True, flag_value=True,
help="Write AgERA5 data to compressed CSV files.")
@click.option("-p", "--to_parquet", is_flag=True, flag_value=True,
help="Write AgERA5 data to parquet files.")
def cmd_buildym(year, month, to_database, to_csv, to_parquet):
def cmd_buildym(year, month, to_database, to_csv):
"""Builds the AgERA5 database by bulk download from CDS for given year/month only
"""
print(f"Export to database: {to_database}")
print(f"Export to CSV: {to_csv}")
print(f"Export to Parquet: {to_parquet}")
if to_csv is False and to_database is False and to_parquet is False:
if to_csv is False and to_database is False:
msg = ("Warning: Only NetCDF files will be updated, no tabular output will be written, "
"use either --to_database, --to_csv or --to_parquet")
"use either --to_database, --to_csv")
click.echo(msg)
year_month = [(year, month)]
build(year_month, to_database, to_csv, to_parquet)
build(year_month, to_database, to_csv)
msg = "Done building database, use the `mirror` command to keep the DB up to date"
click.echo(msg)

Expand Down
3 changes: 2 additions & 1 deletion agera5tools/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,6 @@ def mirror(to_csv=True, dry_run=False):

return days, days_failed


if __name__ == "__main__":
mirror()
mirror()
1 change: 0 additions & 1 deletion agera5tools/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def flask_get_agera5():
return get_JSON_response(get_agera5, params, "get_agera5")



def serve(port=8080):
server = wsgiserver.WSGIServer(app, port=port)
server.start()
Expand Down

0 comments on commit 8cdfb4e

Please sign in to comment.