diff --git a/dev/0_OLD/0_old_directories.py b/dev/0_OLD/0_old_directories.py index e16a8b41..10c15072 100644 --- a/dev/0_OLD/0_old_directories.py +++ b/dev/0_OLD/0_old_directories.py @@ -40,6 +40,7 @@ # GPM/version// # Search files without internet connection + # -----------------------------------------------------------------------------. ############################### ### File directory queries #### diff --git a/dev/0_OLD/gpm_class.py b/dev/0_OLD/gpm_class.py index 58468e23..0e6ee879 100644 --- a/dev/0_OLD/gpm_class.py +++ b/dev/0_OLD/gpm_class.py @@ -21,6 +21,7 @@ from gpm_api.PMW.GMI import create_GMI from gpm_api.IMERG.IMERG import create_IMERG + ################ ### Classes #### ################ diff --git a/dev/dev_plot_products.py b/dev/dev_plot_products.py index 5988c03a..d0e573f6 100644 --- a/dev/dev_plot_products.py +++ b/dev/dev_plot_products.py @@ -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) diff --git a/gpm_api/accessor/__init__.py b/gpm_api/accessor/__init__.py index 9493ada9..49172475 100644 --- a/gpm_api/accessor/__init__.py +++ b/gpm_api/accessor/__init__.py @@ -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"] \ No newline at end of file +__all__ = ["GPM_Dataset_Accessor", "GPM_DataArray_Accessor"] diff --git a/gpm_api/dataset/crs.py b/gpm_api/dataset/crs.py index b54a5071..286862a3 100644 --- a/gpm_api/dataset/crs.py +++ b/gpm_api/dataset/crs.py @@ -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) diff --git a/gpm_api/dataset/reader.py b/gpm_api/dataset/reader.py index 5087d830..8237bf7f 100644 --- a/gpm_api/dataset/reader.py +++ b/gpm_api/dataset/reader.py @@ -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) diff --git a/gpm_api/io/checks.py b/gpm_api/io/checks.py index 30021588..598945f6 100644 --- a/gpm_api/io/checks.py +++ b/gpm_api/io/checks.py @@ -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() diff --git a/gpm_api/io/directories.py b/gpm_api/io/directories.py index b592252a..6491c686 100644 --- a/gpm_api/io/directories.py +++ b/gpm_api/io/directories.py @@ -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" diff --git a/gpm_api/io/download.py b/gpm_api/io/download.py index 2182ee9f..530ad31e 100644 --- a/gpm_api/io/download.py +++ b/gpm_api/io/download.py @@ -44,6 +44,7 @@ # - credientials: <...> # --> "--header='Authorization: Basic Z2lvbmF0YS5naGlnZ2lAZXBmbC5jaDpnaW9uYXRhLmdoaWdnaUBlcGZsLmNo' " + ##----------------------------------------------------------------------------. ############################# #### Single file command #### @@ -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) diff --git a/gpm_api/io/info.py b/gpm_api/io/info.py index 22fdefdc..6cee3494 100644 --- a/gpm_api/io/info.py +++ b/gpm_api/io/info.py @@ -30,7 +30,6 @@ def _parse_GPM_fname(fname): - # Retrieve information from filename p = Parser(NASA_FNAME_PATTERN) info_dict = p.parse(fname) diff --git a/gpm_api/io/patterns.py b/gpm_api/io/patterns.py index d3a552c2..e8dd8e45 100644 --- a/gpm_api/io/patterns.py +++ b/gpm_api/io/patterns.py @@ -4,6 +4,8 @@ @author: ghiggi """ + + # ----------------------------------------------------------------------------. ################################# ### File Pattern dictionary #### diff --git a/gpm_api/io/scan_modes.py b/gpm_api/io/scan_modes.py index 399ad22c..52ecdea1 100644 --- a/gpm_api/io/scan_modes.py +++ b/gpm_api/io/scan_modes.py @@ -12,7 +12,6 @@ def available_scan_modes(product, version): - ##---------------------------------------------. #### TRMM Radar if product in ["1B-PR"]: diff --git a/gpm_api/overpass/TODO_GPM_OVERPASS.py b/gpm_api/overpass/TODO_GPM_OVERPASS.py index 2ada6ca8..60faaf99 100644 --- a/gpm_api/overpass/TODO_GPM_OVERPASS.py +++ b/gpm_api/overpass/TODO_GPM_OVERPASS.py @@ -44,6 +44,7 @@ n_threads=10, ) + ####--------------------------------------------------------------------------. #### Compute overpass tables def generate_chunk_slices(chunks, shape): diff --git a/gpm_api/overpass/TODO_OVERPASS_STATS.py b/gpm_api/overpass/TODO_OVERPASS_STATS.py index 28d51545..168fb2ed 100644 --- a/gpm_api/overpass/TODO_OVERPASS_STATS.py +++ b/gpm_api/overpass/TODO_OVERPASS_STATS.py @@ -30,6 +30,7 @@ products = GPM_PMW_2A_GPROF_RS_products() product_type = "RS" + ####--------------------------------------------------------------------------. #### Define statistics to compute def _overpass_stats(df): diff --git a/gpm_api/patch/labels.py b/gpm_api/patch/labels.py index 5b1f8136..f2237f6b 100644 --- a/gpm_api/patch/labels.py +++ b/gpm_api/patch/labels.py @@ -25,6 +25,7 @@ # Note # - label_xarray_object available as ds.gpm_api.label_object + ####--------------------------------------------------------------------------. ##################### #### Area labels #### diff --git a/gpm_api/patch/labels_patch.py b/gpm_api/patch/labels_patch.py index 8cf3ccc8..6964c53a 100644 --- a/gpm_api/patch/labels_patch.py +++ b/gpm_api/patch/labels_patch.py @@ -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) diff --git a/gpm_api/patch/utils.py b/gpm_api/patch/utils.py index 17a9d058..97a0e3f6 100644 --- a/gpm_api/patch/utils.py +++ b/gpm_api/patch/utils.py @@ -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): diff --git a/gpm_api/scripts/download_daily_gpm_data.py b/gpm_api/scripts/download_daily_gpm_data.py index 66b91f6b..52baa4b1 100644 --- a/gpm_api/scripts/download_daily_gpm_data.py +++ b/gpm_api/scripts/download_daily_gpm_data.py @@ -14,6 +14,7 @@ warnings.filterwarnings("ignore") sys.tracebacklimit = 0 # avoid full traceback error if occur + # -------------------------------------------------------------------------. # Click Command Line Interface decorator @click.command() diff --git a/gpm_api/scripts/download_monthly_gpm_data.py b/gpm_api/scripts/download_monthly_gpm_data.py index 5cc5beab..7d0623ac 100644 --- a/gpm_api/scripts/download_monthly_gpm_data.py +++ b/gpm_api/scripts/download_monthly_gpm_data.py @@ -14,6 +14,7 @@ warnings.filterwarnings("ignore") sys.tracebacklimit = 0 # avoid full traceback error if occur + # -------------------------------------------------------------------------. # Click Command Line Interface decorator @click.command() diff --git a/gpm_api/utils/utils_HDF5.py b/gpm_api/utils/utils_HDF5.py index 1719d181..9596bb27 100644 --- a/gpm_api/utils/utils_HDF5.py +++ b/gpm_api/utils/utils_HDF5.py @@ -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 = [] diff --git a/gpm_api/utils/utils_cmap.py b/gpm_api/utils/utils_cmap.py index 85045f5d..db820172 100644 --- a/gpm_api/utils/utils_cmap.py +++ b/gpm_api/utils/utils_cmap.py @@ -78,7 +78,7 @@ PRECIP_VALID_UNITS = ("mm/h", "mm", "dBZ") ####--------------------------------------------------------------------------. -#### CMAP DICTIONARY +#### CMAP DICTIONARY CMAP_DICT = { "IMERG_Solid": { @@ -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": { @@ -196,7 +196,7 @@ } ####--------------------------------------------------------------------------. -#### GPM COLOR DICTIONARY +#### GPM COLOR DICTIONARY COLOR_DICT = { @@ -467,8 +467,8 @@ "precipitationCal", "precipitationUncal", "IRprecipitation", - # GEO RRQPE - "RRQPE" + # GEO RRQPE + "RRQPE", ] for var in precip_variables: @@ -478,7 +478,7 @@ COLOR_DICT["Tc"] = COLOR_DICT["Brightness_Temperature"] ####--------------------------------------------------------------------------. -#### GOES DICTIONARY +#### GOES DICTIONARY GOES_DICT = { @@ -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 [-]", @@ -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, @@ -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, @@ -587,9 +587,6 @@ } - - - ####--------------------------------------------------------------------------. #### Final color dictionary @@ -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 @@ -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": @@ -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, @@ -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: diff --git a/gpm_api/visualization/OLD_comparison.py b/gpm_api/visualization/OLD_comparison.py index 19f3105b..0e1e8a3b 100644 --- a/gpm_api/visualization/OLD_comparison.py +++ b/gpm_api/visualization/OLD_comparison.py @@ -20,7 +20,6 @@ def compare_products( version=7, product_type="RS", ): - #### Preprocess bbox # - Enlarge so to be sure to include all data when cropping # TODO: Robustify to deal when close to the antimeridian diff --git a/gpm_api/visualization/labels.py b/gpm_api/visualization/labels.py index d38dd493..81f002ab 100644 --- a/gpm_api/visualization/labels.py +++ b/gpm_api/visualization/labels.py @@ -96,7 +96,6 @@ def plot_label_patches( fig_kwargs={}, **plot_kwargs, ): - # Check plot_kwargs keys if "cbar_kwargs" in plot_kwargs: raise ValueError("'cbar_kwargs' can not be specified when plotting labels.") diff --git a/gpm_api/visualization/orbit.py b/gpm_api/visualization/orbit.py index 00ae917c..dcb24227 100644 --- a/gpm_api/visualization/orbit.py +++ b/gpm_api/visualization/orbit.py @@ -108,7 +108,6 @@ def wrapper(*args, **kwargs): # - Call the function over each slice for i, slc in enumerate(list_slices): - # Retrive contiguous data array tmp_da = da.isel(along_track=slc) diff --git a/gpm_api/visualization/plot.py b/gpm_api/visualization/plot.py index a8b53e73..709340c7 100644 --- a/gpm_api/visualization/plot.py +++ b/gpm_api/visualization/plot.py @@ -6,14 +6,12 @@ """ import cartopy import cartopy.crs as ccrs -import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np from matplotlib.collections import PolyCollection from mpl_toolkits.axes_grid1 import make_axes_locatable from scipy.ndimage import binary_dilation - ### TODO: Add xarray + cartopy (xr_carto) (xr_mpl) # _plot_cartopy_xr_imshow # _plot_cartopy_xr_pcolormesh @@ -330,7 +328,6 @@ def plot_map( cbar_kwargs={}, **plot_kwargs, ): - from gpm_api.utils.geospatial import is_grid, is_orbit from .grid import plot_grid_map diff --git a/tutorials/example_patches.py b/tutorials/example_patches.py index 091426f3..4645a9fc 100644 --- a/tutorials/example_patches.py +++ b/tutorials/example_patches.py @@ -5,7 +5,9 @@ @author: ghiggi """ import datetime + import numpy as np + import gpm_api from gpm_api.patch.labels import xr_get_areas_labels