Utilities for working with the outputs of the ECCO Modeling Utilities software.
Project description
emu-utilities
ECCO Modeling Utilities (EMU) - Utilities: utilities for the utilities!
This package provides functions for loading the outputs of the ECCO Modeling Utilities (EMU) into xarray data structures. This package includes support for outputs from the following EMU tools:
- Adjoint Gradients: Sensitivity of objective functions to control variables
- Attribution: Decomposed contributions of different forcing components
- Convolution: Time-lagged correlations between forcing and response
- Forward Gradients: Response of the model to perturbations
- Sampling: Time series extraction at specific locations
This package is very early in development, so use with caution and please reach out or submit an issue if you notice any problems.
Usage
Installation
Currently only cloning locally is supported:
git clone https://github.com/andrew-s28/emu-utilities.git
Basic Import
from emu_utilities import adjoint_gradient, attribution, convolution, forward_gradient, sampling, tracer
Loading Adjoint Gradient Data
# Load adjoint gradient data from EMU output folder
ds_adj = adjoint_gradient.load_adjoint_gradient("emu_adj_6_6_2_45_585_1")
# Print dataset to see available variables
print(ds_adj)
Loading Attribution Data
# Load attribution data from EMU output folder
ds_atr = attribution.load_attribution("emu_atrb_m_3_mask3d.-170.0_-120.0_-5.0_5.0_10.0_0.0_1")
# Plot time series comparing reference run and wind stress attribution run
plt.figure(figsize=(10, 6))
plt.plot(ds_atr.time, ds_atr.reference_run, label="Reference Run")
plt.plot(ds_atr.time, ds_atr.wind_stress, label="Wind Stress")
plt.legend()
plt.show()
Loading Convolution Data
Convolution outputs both 1d (spatial sum) and 2d (maximum lag) datasets which have to be loaded in differently. Several helper methods can then be used to compute the explained variance from either the 1d or 2d datasets.
# Load 1d convolution data from EMU output folder
ds_conv = convolution.load_1d_conv_gradient("emu_conv_6_6_2_45_585_1_26")
# Calculate and plot explained variance at a specific lag as a function of control variable
convolution.ctrl_variance(ds_conv, lag=10).plot.scatter()
# Calculate and plot explained variance of all controls at a specific lag
convolution.lagged_variance(ds_conv, variable="sum").plot.scatter()
# Load 2d convolution data from EMU output folder
ds_conv = convolution.load_2d_conv_gradient("emu_conv_6_6_2_45_585_1_26")
# Calculate explained variance as a function of space
ds_sp_var = convolution.spatial_variance(ds, "sum")
Loading Forward Gradient Data
# Load forward gradient data from EMU output folder
ds_fgd = forward_gradient.load_forward_gradient("emu_fgrd_7_15_743_5_-1.00E-01")
# Print dataset to explore available variables
print(ds_fgd)
Loading Sample Data
# Load sample data from EMU output folder
ds_smp = sampling.load_sample("emu_samp_m_2_45_585_1")
# Plot time series of THETA
plt.figure(figsize=(10, 4))
plt.plot(ds_smp.time, ds_smp.THETA)
plt.title("THETA Time Series")
plt.xlabel("Time")
plt.ylabel("THETA")
plt.show()
Loading Tracer Data
# Load tracer data from EMU output folder
ds_trc = tracer.load_tracer_gradient("emu_trc_35_365_trc3d.-170.0_-120.0_-5.0_5.0_10.0_0.0")
Resampling to Regular Lat-Lon Grid
EMU outputs are on the LLC-90 native ECCO grid. Any methods used to interpolate the central ECCO v4r4 state estimate fields to a regular lat-lon grid can be used here. A convinience method is included in this package, based on code from ecco_v4_py.
from emu_utilities.resample import resample_ds
# Load adjoint gradient data
ds_adj = adjoint_gradient.load_adjoint_gradient("path/to/emu_adj_file")
# Define target grid parameters
new_grid_delta_lat = 1 # Grid spacing in latitude (degrees)
new_grid_delta_lon = 1 # Grid spacing in longitude (degrees)
new_grid_min_lat = -90
new_grid_max_lat = 90
new_grid_min_lon = -180
new_grid_max_lon = 180
# Auto-magically resamples every variable in the dataset with the correct coordinates!
ds_adj_resampled = resample_ds(
ds_adj
new_grid_min_lat,
new_grid_max_lat,
new_grid_delta_lat,
new_grid_min_lon,
new_grid_max_lon,
new_grid_delta_lon,
fill_value=np.nan,
mapping_method="nearest_neighbor",
)
# Plot resampled data
plt.figure(figsize=(12, 6))
plt.pcolormesh(ds_adj_resampled["lon"], ds_adj_resampled["lat"], ds_adj_resampled["tauu"], cmap="viridis")
plt.colorbar(label="tauu")
plt.title("Resampled Zonal Wind Stress Sensitivity")
plt.xlabel("Longitude")
plt.ylabel("Latitude")
plt.show()
Visualizing Forward Gradient Data
# Resample SSH data to lat-lon grid
lon_c, lat_c, _, _, ssh_latlon = resample_to_latlon(
ds_fgd.xc,
ds_fgd.yc,
ds_fgd.ssh,
new_grid_min_lat,
new_grid_max_lat,
new_grid_delta_lat,
new_grid_min_lon,
new_grid_max_lon,
new_grid_delta_lon,
fill_value=np.nan,
mapping_method="nearest_neighbor",
)
# Plot SSH (multiplied by 1000 to convert to mm)
plt.figure(figsize=(12, 6))
plt.pcolormesh(lon_c[0], lat_c[:, 0], ssh_latlon[0]*1e3, shading='gouraud', cmap='RdBu_r')
plt.colorbar(label='SSH (mm)')
plt.title('Sea Surface Height')
plt.xlabel('Longitude')
plt.ylabel('Latitude')
plt.show()
Contributing
As this package is in early development, contributions are welcome! Here's how you can help:
- Report bugs by opening an issue
- Suggest enhancements or new features
- Submit pull requests with improvements
If you're interested in contributing, please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/your-feature) - Commit your changes (
git commit -m 'Add your feature') - Push to the branch (
git push origin feature/your-feature) - Open a Pull Request
License
This package is licensed under the MIT License.
This package uses code adapted from the ecco_v4_py package (MIT License) within the emu_utilities.resample module; a copy of that license can be found in that module file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file emu_utilities-0.1.0.tar.gz.
File metadata
- Download URL: emu_utilities-0.1.0.tar.gz
- Upload date:
- Size: 3.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ceaf83ac451568fd185a312c19db8e3f6eef36898d08435f254d38fc213f5fb
|
|
| MD5 |
48fc3f056c6e1f7aeaac129598ae484f
|
|
| BLAKE2b-256 |
86d7900afd018b06ec86c891bfcec11cead238aae1d6530fd4a1325b0c1678d8
|
Provenance
The following attestation bundles were made for emu_utilities-0.1.0.tar.gz:
Publisher:
build-publish-to-pypi.yaml on andrew-s28/emu-utilities
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
emu_utilities-0.1.0.tar.gz -
Subject digest:
8ceaf83ac451568fd185a312c19db8e3f6eef36898d08435f254d38fc213f5fb - Sigstore transparency entry: 233585732
- Sigstore integration time:
-
Permalink:
andrew-s28/emu-utilities@eb7413facce21aad64ffeeb0ece1ba3ea292704f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/andrew-s28
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-publish-to-pypi.yaml@eb7413facce21aad64ffeeb0ece1ba3ea292704f -
Trigger Event:
release
-
Statement type:
File details
Details for the file emu_utilities-0.1.0-py3-none-any.whl.
File metadata
- Download URL: emu_utilities-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.4 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3be06ed9a633f16f1c14b72a9fa2bbf48c55708314041f589d9899992597d468
|
|
| MD5 |
934c5f7e473c1bbebe5918d1b39d5130
|
|
| BLAKE2b-256 |
472ac339260b8a6c664a6d2015a94cdf01aaa8c16935b136e4c275ae87c57b8b
|
Provenance
The following attestation bundles were made for emu_utilities-0.1.0-py3-none-any.whl:
Publisher:
build-publish-to-pypi.yaml on andrew-s28/emu-utilities
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
emu_utilities-0.1.0-py3-none-any.whl -
Subject digest:
3be06ed9a633f16f1c14b72a9fa2bbf48c55708314041f589d9899992597d468 - Sigstore transparency entry: 233585735
- Sigstore integration time:
-
Permalink:
andrew-s28/emu-utilities@eb7413facce21aad64ffeeb0ece1ba3ea292704f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/andrew-s28
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-publish-to-pypi.yaml@eb7413facce21aad64ffeeb0ece1ba3ea292704f -
Trigger Event:
release
-
Statement type: