Skip to content

Commit a4fde24

Browse files
committed
fix bugs and revise for ICRN
1 parent 61e1c0e commit a4fde24

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

downscaled_climate_data/assets/county_measures.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import dask_geopandas as dgpd
44
from shapely.geometry import Point
55
from dask.distributed import Client
6-
6+
import time
77
import s3fs
88

99
from htcdaskgateway import HTCGateway
@@ -13,7 +13,7 @@
1313

1414
load_dotenv() # take environment variables from .env.
1515

16-
os.environ['CONDOR_BIN_DIR'] = "/opt/conda/envs/pangeo/bin"
16+
os.environ['CONDOR_BIN_DIR'] = "/u/bengal1/.conda/envs/downscaled_climate_data/bin"
1717
gateway = HTCGateway(address="https://dask.software-dev.ncsa.illinois.edu",
1818
proxy_address=8786,
1919
auth = BasicAuth(
@@ -22,7 +22,7 @@
2222
)
2323
cluster = gateway.new_cluster(image="bengal1/pangeo-ncsa:dev",
2424
container_image="/u/bengal1/condor/pangeo.sif")
25-
cluster.scale(200)
25+
cluster.scale(80)
2626
client = cluster.get_client()
2727
print(cluster.dashboard_link)
2828

@@ -40,15 +40,20 @@
4040
})
4141

4242
try:
43+
start_time = time.time()
44+
45+
era5_processing_start = time.time()
4346
era5 = era5_processing({'2m_temperature',
4447
'total_precipitation',
4548
"sfcWind",
46-
"relative_humidity",
4749
"vapor_pressure",
4850
"surface_pressure"},
4951
2024, 2025, 'analysis_ready')
50-
df = era5.to_dask_dataframe()
51-
52+
print(f"era processing {time.time() - era5_processing_start:.2f} seconds")
53+
54+
to_tabular_start = time.time()
55+
df = era5.rename("era5").to_dask_dataframe()
56+
5257
era5_gdf = dgpd.from_dask_dataframe(
5358
df,
5459
geometry=dgpd.points_from_xy(df, 'lon', 'lat')) \
@@ -60,6 +65,14 @@
6065
filesystem=fs,
6166
write_metadata_file=True,
6267
schema="infer")
68+
print(f"To Tabular {time.time() - to_tabular_start:.2f} seconds")
69+
print(f"TOTAL TIME {time.time() - start_time:.2f} seconds")
70+
71+
info = client.scheduler_info()
72+
num_workers = len(info['workers'])
73+
print(f"Number of workers: {num_workers}")
74+
75+
6376

6477
finally:
6578
cluster.close()

downscaled_climate_data/calculations/calculations.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def stats(dataset):
2929

3030

3131

32-
def heat_index(RH, t2m):
32+
def heat_index(dataset):
3333
"""
3434
https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml
3535
@@ -42,6 +42,8 @@ def heat_index(RH, t2m):
4242
hi_alone (DataArray) - Heat index array (in K)
4343
4444
"""
45+
t2m = dataset['2m_temperature']
46+
RH = dataset['relative_humidity']
4547
# Convert to Fahrenheit
4648
T_F = ((t2m - 273.15) * 1.8) + 32
4749

@@ -113,7 +115,7 @@ def wind_tot(uwind, vwind):
113115

114116
return wind_mag, wind_dir
115117

116-
def wind_mag(uwind, vwind):
118+
def wind_mag(dataset):
117119
"""
118120
Calculates wind magnitude and angle
119121
@@ -124,6 +126,8 @@ def wind_mag(uwind, vwind):
124126
wind_mag (DataArray) - Wind magnitude (m/s)
125127
126128
"""
129+
uwind = dataset['10m_u_component_of_wind']
130+
vwind = dataset['10m_v_component_of_wind']
127131
return np.sqrt(vwind**2 + uwind**2)
128132

129133

downscaled_climate_data/processors/era5_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def era5_processing(variables:set[str], year_start:int, year_end:int, dataset:st
7272
for variable in variables:
7373
if variable in calc_dict:
7474
analyis_variables.update(calc_dict[variable]['analysis_variables'])
75-
calculations.update(calc_dict[variable]['calculator'])
75+
calculations.add(calc_dict[variable]['calculator'])
7676
else:
7777
analyis_variables.add(variable)
7878

0 commit comments

Comments
 (0)