Skip to content

Commit ebad029

Browse files
authored
Merge pull request #26 from rcjackson/view_images
Edit: Codebook and ability to copy hand labels from one dataframe to another.
2 parents df1fe42 + 3ef028a commit ebad029

4 files changed

Lines changed: 56 additions & 3 deletions

File tree

CODEBOOK.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ The purpose of this section is to label radar imagery for warm-season precipitat
2222
| Field | Units | Description |
2323
|--------------------------|-------|-------------------------------------|
2424
| *reflectivity* | dBZ | Intensity of returned radar signal |
25+
| n_gates_50dBZ | percent | The percentage of gates greater than 50 dBZ |
2526

2627

2728
### 2.2 Image Format
@@ -42,8 +43,8 @@ Each image or region-of-interest must be assigned exactly one primary class.
4243
| Label | Description |
4344
|------------------------|-----------------------------------------------------------------------------|
4445
| No Precipitation | No significant return; background noise only. The image will only have blue and black colors.|
45-
| Stratiform Precipitation | The image must have no pink colors. Green, yellow and red colors are present in a widespread blob. |
46-
| Isolated Convection | The image must have regions of dark red and pink colors. These dark red and pink regions must be separated by regions of black and blue, with no connection to other dark red and pink regions through yellow regions. Over half of the image must be blue or black. |
46+
| Stratiform Precipitation | The image must have no pink colors. Green, yellow and red colors are present in a widespread blob. The percentage of gates greater than 50 dBZ must not exceed 0.02 percent. If it does exceed 0.02 percent, then classify as a mesoscale convective system. |
47+
| Isolated Convection | The image must have regions of dark red and pink colors. These dark red and pink regions must be separated by regions of black and blue, with no connection to other dark red and pink regions through yellow regions. Over half of the image must be blue or black. The perentages of gates with reflectivity greater than 30 dBZ must not exceed 10 percent. If it does exceed 30 percent, then classify as a mesoscale convective system. |
4748
| Mesoscale Convective System | A string or connected cluster of dark red and pink colors must be present in the image. This string can take on a curved structure. There can be more than one such string or cluster in the image. The dark red and pink colors in the clusters must be connected by yellow regions. |
4849
| Ambiguous / Uncertain | Cannot be classified with confidence. |
4950

lars/nepho/inference.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ async def label_radar_data(radar_df, model, categories=None, guidelines=None,
174174
for category, description in categories.items():
175175
prompt += f"{category}: {description}; "
176176
prompt += f"The reflectivity values range from {vmin} dBZ as indicated by the blue colors to {vmax} dBZ as indicated by the red colors."
177+
for key in radar_df.columns:
178+
if key.startswith("pct_gates_") and key.endswith("dbz"):
179+
threshold = key[len("pct_gates_"):-len("dbz")]
180+
prompt += f" The percentage of gates with relfectivity above {threshold} dBZ is provided as {key} in the data."
181+
if key.startswith("n_gates_") and key.endswith("dbz"):
182+
threshold = key[len("n_gates_"):-len("dbz")]
183+
prompt += f" The number of gates with relfectivity above {threshold} dBZ is provided as {key} in the data."
184+
177185
if guidelines:
178186
prompt += " When classifying, follow these annotator guidelines: "
179187
prompt += " ".join(guidelines)

lars/preprocessing/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
from .radar_preprocessing import preprocess_radar_data # noqa: F401
2-
from .labels import load_labels, save_labels, change_file_path # noqa: F401
2+
from .labels import load_labels, save_labels, change_file_path, copy_labels # noqa: F401

lars/preprocessing/labels.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,50 @@ def load_labels(label_file):
3636
"""
3737
return pd.read_csv(label_file)
3838

39+
def copy_labels(source_df, target_df, match_on='time', label_column='label'):
40+
"""
41+
Copy labels from a source DataFrame to a target DataFrame.
42+
43+
Matches rows either on the time index or on the file name (basename only,
44+
so the directory portion of the path does not need to match).
45+
46+
Parameters
47+
----------
48+
source_df (pd.DataFrame): DataFrame containing the labels to copy from.
49+
target_df (pd.DataFrame): DataFrame to copy the labels into.
50+
match_on (str): Either 'time' (match on the DataFrame index) or
51+
'file_path' (match on the basename of the 'file_path' column).
52+
label_column (str): Name of the column containing labels. Default 'label'.
53+
54+
Returns
55+
-------
56+
pd.DataFrame
57+
A copy of ``target_df`` with labels filled in from ``source_df`` where
58+
a match was found. Rows with no match keep their existing label value.
59+
"""
60+
if match_on not in ('time', 'file_path'):
61+
raise ValueError("match_on must be either 'time' or 'file_path'")
62+
63+
target_df = target_df.copy()
64+
65+
if match_on == 'time':
66+
lookup = source_df[label_column]
67+
new_labels = target_df.index.map(lookup)
68+
else:
69+
source_keys = source_df['file_path'].apply(os.path.basename)
70+
lookup = pd.Series(source_df[label_column].values, index=source_keys)
71+
target_keys = target_df['file_path'].apply(os.path.basename)
72+
new_labels = target_keys.map(lookup)
73+
74+
new_labels = pd.Series(new_labels, index=target_df.index)
75+
if label_column in target_df.columns:
76+
target_df[label_column] = new_labels.where(new_labels.notna(),
77+
target_df[label_column])
78+
else:
79+
target_df[label_column] = new_labels
80+
return target_df
81+
82+
3983
def save_labels(label_df, output_file):
4084
"""
4185
Save labels to a CSV file.

0 commit comments

Comments
 (0)