From ace0beffe83ea096f217f1e79dd7aa1ebc63a957 Mon Sep 17 00:00:00 2001 From: Brandon Clayton <bclayton@usgs.gov> Date: Fri, 12 Mar 2021 09:43:05 -0700 Subject: [PATCH] cleanup --- .../nshmp/netcdf/converters/convert.py | 26 ++++++------------- .../nshmp/netcdf/converters/preprocess.py | 9 +++---- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/main/python/gov/usgs/earthquake/nshmp/netcdf/converters/convert.py b/src/main/python/gov/usgs/earthquake/nshmp/netcdf/converters/convert.py index c89f392..3580b03 100644 --- a/src/main/python/gov/usgs/earthquake/nshmp/netcdf/converters/convert.py +++ b/src/main/python/gov/usgs/earthquake/nshmp/netcdf/converters/convert.py @@ -7,25 +7,22 @@ from dataclasses import dataclass from datetime import datetime from pathlib import Path from typing import Union -from rich.progress import ( - BarColumn, - Progress, - TimeElapsedColumn, -) import netCDF4 as netcdf import numpy as np +from rich.progress import BarColumn, Progress, TimeElapsedColumn + from ..application_inputs import ApplicationInputs from ..database.database_info import NetcdfInfo, NetcdfMetadata, ScienceBaseMetadata from ..gmm.imt import Imt from ..gmm.site_class import SiteClass +from ..nshm import Nshm from ..utils.console import console from ..utils.netcdf_dimensions import NetcdfDimensions from ..utils.netcdf_keys import NetcdfKeys from ..utils.netcdf_parameters import NetcdfParameters from ..utils.netcdf_utils import NetcdfUtils -from ..nshm import Nshm _ROOT_ATTRIBUTES: dict = { @@ -48,7 +45,7 @@ class Convert: nshm = self.metadata.database_info.nshm region = self.metadata.model_region - if (nshm != Nshm.NSHM_2018A): + if nshm != Nshm.NSHM_2018A: raise ValueError(f"NSHM [{self.metadata.database_info.nshm.value}] not supported") console.print(f"\n[blue]Converting {nshm.label}") @@ -84,7 +81,7 @@ class Convert: "[progress.description]{task.description}", BarColumn(), "[progress.percentage]{task.percentage:>3.0f}%", - TimeElapsedColumn() + TimeElapsedColumn(), ) self._write_netcdf_file() self._root_group.close() @@ -167,10 +164,7 @@ class Convert: console.print(f"\n Removing ASCII files in ({path})", style="yellow") shutil.rmtree(path) - def _get_hazard_data( - self, - hazard_netcdf_var: netcdf.Variable - ): + def _get_hazard_data(self, hazard_netcdf_var: netcdf.Variable): futures: list[Future] = [] status_msg = f"[bold green]Converting {self.metadata.database_info.nshm.label} files" @@ -286,18 +280,14 @@ class Convert: longitude, self._get_longitude_index(longitude=longitude) ) - data_array[ - latitude_index, longitude_index, : - ] = values + data_array[latitude_index, longitude_index, :] = values # self._data_array[ # site_class_index, imt_index, latitude_index, longitude_index, : # ] = values imt_mask_array[latitude_index, longitude_index] = 1 self._site_class_mask_array += imt_mask_array - hazard_netcdf_var[ - site_class_index, imt_index, :, :, : - ] = data_array + hazard_netcdf_var[site_class_index, imt_index, :, :, :] = data_array def _set_imt_indices(self) -> dict[Imt, int]: imt_indices: dict[Imt, int] = dict() diff --git a/src/main/python/gov/usgs/earthquake/nshmp/netcdf/converters/preprocess.py b/src/main/python/gov/usgs/earthquake/nshmp/netcdf/converters/preprocess.py index d7fbdbc..a449ab6 100644 --- a/src/main/python/gov/usgs/earthquake/nshmp/netcdf/converters/preprocess.py +++ b/src/main/python/gov/usgs/earthquake/nshmp/netcdf/converters/preprocess.py @@ -2,11 +2,8 @@ from concurrent.futures import Future, ThreadPoolExecutor from pathlib import Path import numpy as np -from rich.progress import ( - BarColumn, - Progress, - TimeElapsedColumn, -) + +from rich.progress import BarColumn, Progress, TimeElapsedColumn from ..database.database_info import DatabaseInfo, DataInfo, NetcdfInfo, NetcdfMetadata from ..geo.location import Locations @@ -43,7 +40,7 @@ class Preprocess: "[progress.description]{task.description}", BarColumn(), "[progress.percentage]{task.percentage:>3.0f}%", - TimeElapsedColumn() + TimeElapsedColumn(), ) with progress: -- GitLab