Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed May 23, 2023
1 parent e0331c9 commit 51eea6a
Show file tree
Hide file tree
Showing 26 changed files with 64 additions and 68 deletions.
1 change: 1 addition & 0 deletions dev/0_OLD/0_old_directories.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
# GPM/version/<RS/NRT>/<PRODUCT>
# Search files without internet connection


# -----------------------------------------------------------------------------.
###############################
### File directory queries ####
Expand Down
1 change: 1 addition & 0 deletions dev/0_OLD/gpm_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from gpm_api.PMW.GMI import create_GMI
from gpm_api.IMERG.IMERG import create_IMERG


################
### Classes ####
################
Expand Down
1 change: 0 additions & 1 deletion dev/dev_plot_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@
# Create figure
for product, variables in plot_product_var_dict.items():
for variable in variables:

ds = dict_product[product]
# Crop dataset
ds = ds.gpm_api.crop(bbox)
Expand Down
4 changes: 2 additions & 2 deletions gpm_api/accessor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
@author: ghiggi
"""
from .methods import GPM_Dataset_Accessor, GPM_DataArray_Accessor
from .methods import GPM_DataArray_Accessor, GPM_Dataset_Accessor

__all__ = ["GPM_Dataset_Accessor", "GPM_DataArray_Accessor"]
__all__ = ["GPM_Dataset_Accessor", "GPM_DataArray_Accessor"]
1 change: 0 additions & 1 deletion gpm_api/dataset/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ def _add_proj_coords_attrs(ds, crs) -> xr.Dataset:

# If available, add attributes
if x_dim is not None and y_dim is not None:

# Retrieve existing coordinate attributes
src_x_coord_attrs = dict(ds[x_dim].attrs)
src_y_coord_attrs = dict(ds[y_dim].attrs)
Expand Down
1 change: 0 additions & 1 deletion gpm_api/dataset/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ def _get_granule_info(filepath, scan_mode, variables, groups):
"""Retrieve coordinates, attributes and valid variables and groups from the HDF file."""
# Open HDF5 file
with h5py.File(filepath, "r", locking=False, swmr=SWMR) as hdf:

# Get coordinates
coords = get_coords(hdf, scan_mode)

Expand Down
6 changes: 3 additions & 3 deletions gpm_api/io/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ def check_time(time):
if np.issubdtype(time.dtype, np.datetime64):
if time.size == 1:
time = time.astype("datetime64[s]").tolist()
else:
else:
raise ValueError("Expecting a single timestep!")
else:
else:
raise ValueError("The numpy array does not have a np.datetime64 dtype!")

# If np.datetime64, convert to datetime.datetime
if isinstance(time, np.datetime64):
time = time.astype("datetime64[s]").tolist()
Expand Down
1 change: 0 additions & 1 deletion gpm_api/io/directories.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ def get_pps_directory(product, product_type, date, version):
##------------------------------------------------------------------------.
#### RS data
elif product_type == "RS":

## Specify servers
url_server_text = "https://arthurhouhttps.pps.eosdis.nasa.gov/text"
url_data_server = "ftps://arthurhouftps.pps.eosdis.nasa.gov"
Expand Down
2 changes: 1 addition & 1 deletion gpm_api/io/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
# - credientials: <...>
# --> "--header='Authorization: Basic Z2lvbmF0YS5naGlnZ2lAZXBmbC5jaDpnaW9uYXRhLmdoaWdnaUBlcGZsLmNo' "


##----------------------------------------------------------------------------.
#############################
#### Single file command ####
Expand Down Expand Up @@ -276,7 +277,6 @@ def _download_files(
progress_bar=True,
verbose=False,
):

if transfer_tool == "curl":
list_cmd = [
curl_cmd(src_path, dst_path, username, username)
Expand Down
1 change: 0 additions & 1 deletion gpm_api/io/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@


def _parse_GPM_fname(fname):

# Retrieve information from filename
p = Parser(NASA_FNAME_PATTERN)
info_dict = p.parse(fname)
Expand Down
2 changes: 2 additions & 0 deletions gpm_api/io/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
@author: ghiggi
"""


# ----------------------------------------------------------------------------.
#################################
### File Pattern dictionary ####
Expand Down
1 change: 0 additions & 1 deletion gpm_api/io/scan_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@


def available_scan_modes(product, version):

##---------------------------------------------.
#### TRMM Radar
if product in ["1B-PR"]:
Expand Down
1 change: 1 addition & 0 deletions gpm_api/overpass/TODO_GPM_OVERPASS.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
n_threads=10,
)


####--------------------------------------------------------------------------.
#### Compute overpass tables
def generate_chunk_slices(chunks, shape):
Expand Down
1 change: 1 addition & 0 deletions gpm_api/overpass/TODO_OVERPASS_STATS.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
products = GPM_PMW_2A_GPROF_RS_products()
product_type = "RS"


####--------------------------------------------------------------------------.
#### Define statistics to compute
def _overpass_stats(df):
Expand Down
1 change: 1 addition & 0 deletions gpm_api/patch/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# Note
# - label_xarray_object available as ds.gpm_api.label_object


####--------------------------------------------------------------------------.
#####################
#### Area labels ####
Expand Down
1 change: 0 additions & 1 deletion gpm_api/patch/labels_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ def get_labeled_object_patches(

# Extract patch around the label
for label_id in labels_id[0:n_patches]:

# Get label bounding box slices
list_slices = _get_labels_bbox_slices(label_arr == label_id)

Expand Down
1 change: 1 addition & 0 deletions gpm_api/patch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def split_large_objects_slices(objects_slices, patch_size):
#### Patch Extraction ####
##########################


# get_patch_slices_around_point
def get_patch_slices_around(row, col, patch_size, image_shape):
if len(patch_size) != len(image_shape):
Expand Down
1 change: 1 addition & 0 deletions gpm_api/scripts/download_daily_gpm_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
warnings.filterwarnings("ignore")
sys.tracebacklimit = 0 # avoid full traceback error if occur


# -------------------------------------------------------------------------.
# Click Command Line Interface decorator
@click.command()
Expand Down
1 change: 1 addition & 0 deletions gpm_api/scripts/download_monthly_gpm_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
warnings.filterwarnings("ignore")
sys.tracebacklimit = 0 # avoid full traceback error if occur


# -------------------------------------------------------------------------.
# Click Command Line Interface decorator
@click.command()
Expand Down
1 change: 1 addition & 0 deletions gpm_api/utils/utils_HDF5.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def h5dump(filepath, group="/", dataset_attrs=True, group_attrs=True):
# for item in x.keys():
# print_hdf5_shape(x[item])


# -----------------------------------------------------------------------------.
def hdf5_objects_names(hdf):
l_objs = []
Expand Down
94 changes: 45 additions & 49 deletions gpm_api/utils/utils_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
PRECIP_VALID_UNITS = ("mm/h", "mm", "dBZ")

####--------------------------------------------------------------------------.
#### CMAP DICTIONARY
#### CMAP DICTIONARY

CMAP_DICT = {
"IMERG_Solid": {
Expand Down Expand Up @@ -115,11 +115,11 @@
"type": "name",
"color_list": [
"lightblue", # Clear Sky
"darkblue", # Liquid
"lightgreen", # SC Liquid
"orange", # Mixed
'white', # Ice
'darkgray', # Unknown
"darkblue", # Liquid
"lightgreen", # SC Liquid
"orange", # Mixed
"white", # Ice
"darkgray", # Unknown
],
},
"GOES_BinaryCloudMask": {
Expand Down Expand Up @@ -196,7 +196,7 @@
}

####--------------------------------------------------------------------------.
#### GPM COLOR DICTIONARY
#### GPM COLOR DICTIONARY


COLOR_DICT = {
Expand Down Expand Up @@ -467,8 +467,8 @@
"precipitationCal",
"precipitationUncal",
"IRprecipitation",
# GEO RRQPE
"RRQPE"
# GEO RRQPE
"RRQPE",
]

for var in precip_variables:
Expand All @@ -478,7 +478,7 @@
COLOR_DICT["Tc"] = COLOR_DICT["Brightness_Temperature"]

####--------------------------------------------------------------------------.
#### GOES DICTIONARY
#### GOES DICTIONARY


GOES_DICT = {
Expand All @@ -488,7 +488,7 @@
"cmap": "viridis",
"cmap_type": "Colormap",
"vmin": 0,
"vmax": 50,
"vmax": 50,
"extend": "max",
"extendfrac": 0.05,
"label": "Cloud Optical Depth at 640 nm [-]",
Expand Down Expand Up @@ -542,22 +542,22 @@
"bad_alpha": 0.5,
"cmap": "GOES_CloudPhase",
"cmap_type": "Categorical",
"labels": ['Clear Sky', 'Liquid', 'SC Liquid', 'Mixed', 'Ice', 'Unknown'],
"labels": ["Clear Sky", "Liquid", "SC Liquid", "Mixed", "Ice", "Unknown"],
},
"CM": {
"bad_color": "gray",
"bad_alpha": 0.5,
"cmap": "GOES_BinaryCloudMask",
"cmap_type": "Categorical",
"labels": ['Clear Sky', 'Cloudy'],
"labels": ["Clear Sky", "Cloudy"],
},
}
COLOR_DICT.update(GOES_DICT)
COLOR_DICT.update(GOES_DICT)

# ABI Reflectance channels (C01-C06)
reflectance_channels = ["C" + str(i).zfill(2) for i in range(1, 7)]
reflectance_channels = ["C" + str(i).zfill(2) for i in range(1, 7)]

for channel in reflectance_channels:
for channel in reflectance_channels:
GOES_DICT[channel] = {
"bad_color": "gray",
"bad_alpha": 0.5,
Expand All @@ -569,11 +569,11 @@
"extendfrac": 0.05,
"label": "Reflectance [%]",
}


# ABI BT channels (C07-C17)
bt_channels = ["C" + str(i).zfill(2) for i in range(7, 17)]
for channel in bt_channels:
bt_channels = ["C" + str(i).zfill(2) for i in range(7, 17)]
for channel in bt_channels:
GOES_DICT[channel] = {
"bad_color": "gray",
"bad_alpha": 0.5,
Expand All @@ -587,9 +587,6 @@
}





####--------------------------------------------------------------------------.
#### Final color dictionary

Expand Down Expand Up @@ -687,16 +684,16 @@ def get_colormap_setting(cbar_settings_name):
# raise ValueError("{cbar_settings_name} cbar_settings does not exist.")

# --------------------------------------------------------------------------.
# Get cmap info
# Get cmap info
cmap_type = color_dict["cmap_type"]
cmap_name = color_dict["cmap"]
clevs = color_dict.get("levels", None)
vmin = color_dict.get("vmin", None)
vmax = color_dict.get("vmax", None)

# Initialize cbar_kwargs
cbar_kwargs = {}
cbar_kwargs = {}

# ------------------------------------------------------------------------.
if cmap_type == "LinearSegmented":
# TODO: Check level is a list > 2, length + 1 than color_list
Expand All @@ -706,37 +703,37 @@ def get_colormap_setting(cbar_settings_name):

# Get colormap
cmap = mpl.colors.LinearSegmentedColormap.from_list("cmap", color_list, len(clevs) - 1)

# ------------------------------------------------------------------------.
elif cmap_type == "Categorical":
# Get color list
color_list = CMAP_DICT[cmap_name]["color_list"]
# Get class labels

# Get class labels
labels = color_dict.get("labels", None)
# Check validity
if labels is None:

# Check validity
if labels is None:
raise ValueError(f"If cmap_type is {cmap_type}, 'labels' list is required.")
if not isinstance(labels, list):
raise ValueError("'labels' must be a list.")
if not isinstance(labels, list):
raise ValueError("'labels' must be a list.")
if len(color_list) != len(labels):
raise ValueError("'labels' must have same length as the 'color_list'.")
# Define colormap and colorbar settings
raise ValueError("'labels' must have same length as the 'color_list'.")

# Define colormap and colorbar settings
nlabels = len(labels)
cmap = mpl.colors.ListedColormap(color_list)
# Define norms
norm_bins = np.arange(-1, nlabels)+.5

# Define norms
norm_bins = np.arange(-1, nlabels) + 0.5
norm = mpl.colors.BoundaryNorm(norm_bins, nlabels)
# Update cbar_kwargs

# Update cbar_kwargs
fmt = mpl.ticker.FuncFormatter(lambda x, pos: labels[norm(x)])
tickz = norm_bins[:-1]+ .5
tickz = norm_bins[:-1] + 0.5
cbar_kwargs["format"] = fmt
cbar_kwargs["ticks"] = tickz

# ------------------------------------------------------------------------.
# TODO: implement other cmap options
elif cmap_type == "Colormap":
Expand Down Expand Up @@ -819,7 +816,7 @@ def get_colormap_setting(cbar_settings_name):
"shrink": color_dict.get("ticklocation", 1),
}
default_cbar_kwargs.update(cbar_kwargs)

# format
# 'orientation':'horizontal'
# 'aspect':40,
Expand Down Expand Up @@ -860,10 +857,9 @@ def get_colorbar_settings(name, plot_kwargs={}, cbar_kwargs={}):
except:
default_plot_kwargs = {}
default_cbar_kwargs = {}

# If the default is a categorical colormap
# --> TODO: Set all to none


# If the default is a categorical colormap
# --> TODO: Set all to none

# If the default is a segmented colormap (with ticks and ticklabels)
if default_cbar_kwargs.get("ticks", None) is not None:
Expand Down
Loading

0 comments on commit 51eea6a

Please sign in to comment.