-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e85fd39
commit de7bdc5
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import numpy as np | ||
import pandas as pd | ||
import xarray as xr | ||
import plotly.express as px | ||
|
||
# Open zarr file | ||
ds = xr.open_zarr('/Data/data24/ISIMIP3b/InputData/climate/atmosphere/bias-adjusted/global/daily/historical/GFDL-ESM4/zarr/tasmin') | ||
|
||
# Convert daily data to monthly | ||
monthly_ds = ds.resample(T="1M").mean() | ||
|
||
# Compute the average tasmin for each month across all years | ||
annual_monthly_avg = monthly_ds.groupby("T.month").mean(dim="T") | ||
|
||
# Prepare the data for the CSV (too big to print in terminal) | ||
data = {'month': [], 'tasmin': []} | ||
for month in range(1, 13): | ||
month_data = annual_monthly_avg.sel(month=month) | ||
tasmin_value = month_data['tasmin'].mean(dim=["X", "Y"]).values # Get the mean tasmin value | ||
data['month'].append(month) | ||
data['tasmin'].append(tasmin_value) | ||
|
||
# Create a DataFrame for the spatial data for this month | ||
df = month_data['tasmin'].to_dataframe().reset_index() | ||
|
||
# Sort latitudes in ascending order if necessary - for if map is flipped | ||
df = df.sort_values(by='Y') | ||
|
||
# Create the map | ||
fig = px.imshow( | ||
df.pivot(index='Y', columns='X', values='tasmin'), | ||
labels={'color': 'Kelvins'}, | ||
title=f'Tasmin for Month {month}', | ||
origin='lower' # Set the origin to lower to flip the y-axis | ||
) | ||
|
||
|
||
# Save the map as an HTML file - access through port 8000 | ||
fig.write_html(f'/home/sz3116/python-maprooms/pepsico/resources/map_month_{month}.html') | ||
|
||
|
||
print("done") |