Skip to content

Commit

Permalink
Update precommit
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiggi committed Dec 10, 2024
1 parent c20e7e1 commit 7f802eb
Show file tree
Hide file tree
Showing 22 changed files with 108 additions and 121 deletions.
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
identity and expression, level of experience, education, socioeconomic status,
nationality, personal appearance, race, caste, color, religion, or sexual
identity and orientation.

Expand Down
5 changes: 1 addition & 4 deletions disdrodb/api/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ def check_url(url: str) -> bool:
``True`` if url well formatted, ``False`` if not well formatted.
"""
regex = r"^(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$" # noqa: E501

if re.match(regex, url):
return True
return False
return re.match(regex, url)


def check_path_is_a_directory(dir_path, path_name=""):
Expand Down
1 change: 1 addition & 0 deletions disdrodb/cli/disdrodb_run_l1.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from typing import Optional

import click

from disdrodb.utils.cli import (
click_base_dir_option,
click_processing_options,
Expand Down
1 change: 1 addition & 0 deletions disdrodb/cli/disdrodb_run_l1_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from typing import Optional

import click

from disdrodb.utils.cli import (
click_base_dir_option,
click_processing_options,
Expand Down
1 change: 1 addition & 0 deletions disdrodb/cli/disdrodb_run_l2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from typing import Optional

import click

from disdrodb.utils.cli import (
click_base_dir_option,
click_processing_options,
Expand Down
1 change: 1 addition & 0 deletions disdrodb/cli/disdrodb_run_l2e_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from typing import Optional

import click

from disdrodb.utils.cli import (
click_base_dir_option,
click_processing_options,
Expand Down
1 change: 1 addition & 0 deletions disdrodb/cli/disdrodb_run_l2m.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from typing import Optional

import click

from disdrodb.utils.cli import (
click_base_dir_option,
click_processing_options,
Expand Down
1 change: 1 addition & 0 deletions disdrodb/cli/disdrodb_run_l2m_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from typing import Optional

import click

from disdrodb.utils.cli import (
click_base_dir_option,
click_processing_options,
Expand Down
4 changes: 1 addition & 3 deletions disdrodb/data_transfer/download_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@ def download_station(

def _is_valid_disdrodb_data_url(disdrodb_data_url):
"""Check if it is a valid disdrodb_data_url."""
if isinstance(disdrodb_data_url, str) and len(disdrodb_data_url) > 10:
return True
return False
return isinstance(disdrodb_data_url, str) and len(disdrodb_data_url) > 10


def _has_disdrodb_data_url(metadata_filepath):
Expand Down
4 changes: 1 addition & 3 deletions disdrodb/l0/template_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,7 @@ def str_has_decimal_digits(string: str) -> bool:
bool
True if string has digits.
"""
if len(string.split(".")) == 2:
return True
return False
return len(string.split(".")) == 2


def get_decimal_ndigits(string: str) -> int:
Expand Down
4 changes: 2 additions & 2 deletions disdrodb/l1/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@


import xarray as xr
from disdrodb.utils.attrs import set_attrs
from disdrodb.utils.encoding import set_encodings

from disdrodb.l1.encoding_attrs import get_attrs_dict, get_encoding_dict
from disdrodb.l1.fall_velocity import get_raindrop_fall_velocity
from disdrodb.l1.filters import define_spectrum_mask, filter_diameter_bins, filter_velocity_bins
from disdrodb.l1.resampling import add_sample_interval
from disdrodb.l1_env.routines import load_env_dataset
from disdrodb.l2.empirical_dsd import get_drop_average_velocity, get_min_max_diameter # TODO: maybe move out of L2
from disdrodb.utils.attrs import set_attrs
from disdrodb.utils.encoding import set_encodings
from disdrodb.utils.time import infer_sample_interval, regularize_timesteps


Expand Down
3 changes: 1 addition & 2 deletions disdrodb/l1/routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
define_logs_dir,
)
from disdrodb.configs import get_base_dir
from disdrodb.l1.processing import generate_l1
from disdrodb.utils.decorator import delayed_if_parallel, single_threaded_if_parallel

# Logger
Expand All @@ -49,8 +50,6 @@
)
from disdrodb.utils.writer import write_product

from disdrodb.l1.processing import generate_l1

logger = logging.getLogger(__name__)


Expand Down
1 change: 1 addition & 0 deletions disdrodb/l2/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import numpy as np
import pandas as pd
import xarray as xr

from disdrodb.api.info import get_start_end_time_from_filepaths


Expand Down
28 changes: 10 additions & 18 deletions disdrodb/l2/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import numpy as np
import xarray as xr
from disdrodb.utils.attrs import set_attrs
from disdrodb.utils.encoding import set_encodings

from disdrodb.l1.encoding_attrs import get_attrs_dict, get_encoding_dict
from disdrodb.l1.fall_velocity import get_raindrop_fall_velocity
Expand All @@ -46,9 +44,11 @@
get_std_volume_drop_diameter,
get_total_number_concentration,
)
from disdrodb.psd.fitting import compute_gof_stats
from disdrodb.psd import create_psd, estimate_model_parameters
from disdrodb.psd.fitting import compute_gof_stats
from disdrodb.scattering import get_radar_parameters
from disdrodb.utils.attrs import set_attrs
from disdrodb.utils.encoding import set_encodings


def define_diameter_array(diameter_min=0, diameter_max=10, diameter_spacing=0.05):
Expand Down Expand Up @@ -430,7 +430,7 @@ def generate_l2_empirical(ds, ds_env=None):
drop_volume = drop_counts * get_drop_volume(diameter) # (np.pi/6 * diameter**3 * drop_counts)
drop_total_volume = drop_volume.sum(dim="diameter_bin_center")
drop_relative_volume_ratio = drop_volume / drop_total_volume

# Compute kinetic energy variables
# --> TODO: implement from_dsd (using drop_concentration!)
min_drop_kinetic_energy, max_drop_kinetic_energy = get_min_max_drop_kinetic_energy(
Expand All @@ -457,8 +457,8 @@ def generate_l2_empirical(ds, ds_env=None):
rain_accumulation=rain_accumulation,
water_density=water_density,
)
#----------------------------------------------------------------------------

# ----------------------------------------------------------------------------
# Compute integral parameters
ds_l2 = compute_integral_parameters(
drop_number_concentration=drop_number_concentration,
Expand Down Expand Up @@ -490,10 +490,9 @@ def generate_l2_empirical(ds, ds_env=None):
ds_l2["KEmax"] = max_drop_kinetic_energy
ds_l2["E"] = rainfall_kinetic_energy
ds_l2["KE"] = kinetic_energy_density_flux

# ----------------------------------------------------------------------------



# ----------------------------------------------------------------------------.
# Remove timesteps where rain rate is 0
ds_l2 = ds_l2.isel(time=ds_l2["R"] > 0)
Expand Down Expand Up @@ -679,12 +678,7 @@ def generate_l2_model(
#### L2 Radar Parameters


def generate_l2_radar(ds,
radar_band=None,
canting_angle_std=7,
diameter_max=8,
axis_ratio="Thurai2007",
parallel=True):
def generate_l2_radar(ds, radar_band=None, canting_angle_std=7, diameter_max=8, axis_ratio="Thurai2007", parallel=True):
"""Simulate polarimetric radar variables from empirical drop number concentration or the estimated PSD.
Parameters
Expand Down Expand Up @@ -718,7 +712,7 @@ def generate_l2_radar(ds,
axis_ratio=axis_ratio,
parallel=parallel,
)

#### ----------------------------------------------------------------------------.
#### Add encodings and attributes
# Add variables attributes
Expand All @@ -731,5 +725,3 @@ def generate_l2_radar(ds,

# Return dataset
return ds_radar


125 changes: 62 additions & 63 deletions disdrodb/l2/processing_options.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
import re


# TODO: Write to YAML

config = {
'global_settings': {
'time_integration': ["10S", "30S", "1MIN", "5MIN", "10MIN", "15MIN", "30MIN", "1H", "ROLL5MIN", "ROLL10MIN"],
"global_settings": {
"time_integration": ["10S", "30S", "1MIN", "5MIN", "10MIN", "15MIN", "30MIN", "1H", "ROLL5MIN", "ROLL10MIN"],
# L2M options
'l2m_options': {
'fall_velocity_method': 'Beard1976',
'diameter_min': 0,
'diameter_max': 8,
'diameter_spacing': 0.05,
},
"l2m_options": {
"fall_velocity_method": "Beard1976",
"diameter_min": 0,
"diameter_max": 8,
"diameter_spacing": 0.05,
},
# PSD models fitting options
'psd_models': {
"psd_models": {
# 'gamma': {
# 'probability_method': 'cdf',
# 'likelihood': 'multinomial',
# 'truncated_likelihood': True,
# 'optimizer': 'Nelder-Mead',
# "add_gof_metrics": True
# },
'normalized_gamma': {
'optimizer': 'Nelder-Mead',
'order': 2,
"add_gof_metrics": True
"normalized_gamma": {
"optimizer": "Nelder-Mead",
"order": 2,
"add_gof_metrics": True,
},
# 'fixed': {
# 'psd_model': 'NormalizedGammaPSD',
Expand All @@ -36,79 +35,80 @@
# },
},
# Radar options
'radar_simulation_enabled': True,
'radar_simulation_options': {
'radar_band': ['S', 'C', 'X', 'Ku', 'Ka', 'W'],
'canting_angle_std': 7,
'diameter_max': 8,
'axis_ratio': 'Thurai2007',
"radar_simulation_enabled": True,
"radar_simulation_options": {
"radar_band": ["S", "C", "X", "Ku", "Ka", "W"],
"canting_angle_std": 7,
"diameter_max": 8,
"axis_ratio": "Thurai2007",
},
},
"specific_settings": {
'10S': {
"radar_simulation_enabled": False
},
'30S': {
"radar_simulation_enabled": False
},
'10MIN': {
"radar_simulation_enabled": False
},
'15MIN': {
"radar_simulation_enabled": False
},
'30MIN': {
"radar_simulation_enabled": False
},
'1H': {
"radar_simulation_enabled": False
},
'ROLL10MIN': {
"radar_simulation_enabled": False
},
}
"10S": {
"radar_simulation_enabled": False,
},
"30S": {
"radar_simulation_enabled": False,
},
"10MIN": {
"radar_simulation_enabled": False,
},
"15MIN": {
"radar_simulation_enabled": False,
},
"30MIN": {
"radar_simulation_enabled": False,
},
"1H": {
"radar_simulation_enabled": False,
},
"ROLL10MIN": {
"radar_simulation_enabled": False,
},
},
}


def get_l2_processing_options():
# TODO: Implement validation !
l2_options_dict = {}
"""Retrieve L2 processing options."""
# TODO: Implement validation !
l2_options_dict = {}
for tt in config["global_settings"]["time_integration"]:
l2_options_dict[tt] = config["global_settings"].copy()
l2_options_dict[tt] = config["global_settings"].copy()
_ = l2_options_dict[tt].pop("time_integration", None)
for tt, product_options in config["specific_settings"].items():
l2_options_dict[tt].update(product_options)
return l2_options_dict


def get_resampling_information(sample_interval_acronym):
def get_resampling_information(sample_interval_acronym):
"""
Extract resampling information from the sample interval acronym.
Parameters
----------
sample_interval_acronym: str
A string representing the sample interval: e.g., "1H30MIN", "ROLL1H30MIN".
Returns
-------
sample_interval_seconds, rolling: tuple
Sample_interval in seconds and whether rolling is enabled.
"""
Extract resampling information from the sample interval acronym.
Parameters
----------
sample_interval_acronym: str
A string representing the sample interval: e.g., "1H30MIN", "ROLL1H30MIN".
Returns
-------
sample_interval_seconds, rolling: tuple
Sample_interval in seconds and whether rolling is enabled.
"""
rolling = sample_interval_acronym.startswith("ROLL")
if rolling:
sample_interval_acronym = sample_interval_acronym[4:] # Remove "ROLL"

# Regular expression to match duration components
pattern = r"(\d+)([DHMIN]+)"
matches = re.findall(pattern, sample_interval_acronym)

# Conversion factors for each unit
unit_to_seconds = {
"D": 86400, # Seconds in a day
"H": 3600, # Seconds in an hour
"MIN": 60, # Seconds in a minute
"S": 1 # Seconds in a second
"H": 3600, # Seconds in an hour
"MIN": 60, # Seconds in a minute
"S": 1, # Seconds in a second
}

# Parse matches and calculate total seconds
Expand All @@ -118,4 +118,3 @@ def get_resampling_information(sample_interval_acronym):
if unit in unit_to_seconds:
sample_interval += value * unit_to_seconds[unit]
return sample_interval, rolling

Loading

0 comments on commit 7f802eb

Please sign in to comment.