Skip to content

Commit

Permalink
Migrate to pure julia (#62)
Browse files Browse the repository at this point in the history
* migrate all 2D files to purejulia

* update test references

* remove PyCall dependencies in the 1D files

* automatic download of preprocessed data + remove DataFrames dependency

* try to remove Python from the CI

* remove remaining implicit dependencies to Python objects

* create get_rgi_paths

* fix various bugs

* remove absolute paths from get_rgi_paths to make the tests platform agnostic

* fix bugs with the climate_2D_step structure

* some cleaning

* bump version
  • Loading branch information
albangossard committed Jan 23, 2025
1 parent f1c763d commit 0604755
Show file tree
Hide file tree
Showing 25 changed files with 231 additions and 312 deletions.
64 changes: 32 additions & 32 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,30 @@ jobs:
# uses: actions/setup-python@v5
# with:
# python-version: ${{ matrix.python }}
- name: Create environment with micromamba 🐍🖤
uses: mamba-org/setup-micromamba@v1
with:
micromamba-version: '2.0.2-2'
environment-file: ./environment.yml
environment-name: oggm_env # it is recommendable to add both name and yml file.
init-shell: bash
cache-environment: false
cache-downloads: false
# If necessary, we can include .condarc to configure environment
# condarc-file: ./condarc.yml
- name: Test creation of environment with micromamba 🔧🐍🖤
run: |
which python
micromamba env export
# shell: bash -el {0}
- name: Update certifi
run: |
pip install --upgrade certifi
# shell: bash -el {0}
- name: Set ENV Variables for PyCall.jl 🐍 📞
run: |
echo "PYTHON=/Users/runner/micromamba/envs/oggm_env/bin/python" >> "$GITHUB_ENV"
# shell: bash -el {0}
# - name: Create environment with micromamba 🐍🖤
# uses: mamba-org/setup-micromamba@v1
# with:
# micromamba-version: '2.0.2-2'
# environment-file: ./environment.yml
# environment-name: oggm_env # it is recommendable to add both name and yml file.
# init-shell: bash
# cache-environment: false
# cache-downloads: false
# # If necessary, we can include .condarc to configure environment
# # condarc-file: ./condarc.yml
# - name: Test creation of environment with micromamba 🔧🐍🖤
# run: |
# which python
# micromamba env export
# # shell: bash -el {0}
# - name: Update certifi
# run: |
# pip install --upgrade certifi
# # shell: bash -el {0}
# - name: Set ENV Variables for PyCall.jl 🐍 📞
# run: |
# echo "PYTHON=/Users/runner/micromamba/envs/oggm_env/bin/python" >> "$GITHUB_ENV"
# # shell: bash -el {0}
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
Expand Down Expand Up @@ -90,9 +90,9 @@ jobs:
with:
cache-registries: "true"
cache-compiled: "true"
# - name: Build Julia packages in Ubuntu
# uses: julia-actions/julia-buildpkg@v1
# if: matrix.os == 'ubuntu-latest'
- name: Build Julia packages in Ubuntu
uses: julia-actions/julia-buildpkg@v1
if: matrix.os == 'ubuntu-latest'
# env:
# PYTHON : /Users/runner/micromamba/envs/oggm_env/bin/python
# # The SSL certificate path can be readed from the action "Check Julia SSL certifications"
Expand All @@ -105,9 +105,9 @@ jobs:
# PYTHON : /Users/runner/micromamba/envs/oggm_env/bin/python
# JULIA_SSL_CA_ROOTS_PATH: /Users/runner/hostedtoolcache/julia/1.11.1/x64/share/julia/cert.pem
# SSL_CERT_FILE: /Users/runner/hostedtoolcache/julia/1.11.1/x64/share/julia/cert.pem
# - name: Run tests in Ubuntu
# uses: julia-actions/julia-runtest@v1
# if: matrix.os == 'ubuntu-latest'
- name: Run tests in Ubuntu
uses: julia-actions/julia-runtest@v1
if: matrix.os == 'ubuntu-latest'
# env:
# PYTHON : /Users/runner/micromamba/envs/oggm_env/bin/python
# # JULIA_SSL_CA_ROOTS_PATH: /etc/ssl/certs/ca-certificates.crt
Expand All @@ -117,8 +117,8 @@ jobs:
if: matrix.os == 'macos-latest'
# env:
# PYTHON : /Users/runner/micromamba/envs/oggm_env/bin/python
# JULIA_SSL_CA_ROOTS_PATH: /Users/runner/hostedtoolcache/julia/1.11.1/x64/share/julia/cert.pem
# SSL_CERT_FILE: /Users/runner/hostedtoolcache/julia/1.11.1/x64/share/julia/cert.pem
# JULIA_SSL_CA_ROOTS_PATH: /Users/runner/hostedtoolcache/julia/1.11.1/x64/share/julia/cert.pem
# SSL_CERT_FILE: /Users/runner/hostedtoolcache/julia/1.11.1/x64/share/julia/cert.pem
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v4
with:
Expand Down
10 changes: 6 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
name = "Sleipnir"
uuid = "f5e6c550-199f-11ee-3608-394420200519"
uuid = "10baed72-45ec-4fdd-b59b-ebd9654d36be"
authors = ["Jordi Bolibar <jordi.bolibar@gmail.com>", "Facundo Sapienza <fsapienza@berkeley.edu>"]
version = "0.7.0"
version = "0.7.1"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
ComponentArrays = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
Expand All @@ -22,10 +21,12 @@ PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
Rasters = "a3a2b9e3-a471-40c9-b274-f788e487c689"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Tar = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
CSV = "0.10.15"
CodecZlib = "0.7.6"
Downloads = "1"
HDF5 = "0.17"
JLD2 = "0.4"
Expand All @@ -36,6 +37,7 @@ NCDatasets = "0.14.6"
Rasters = "0.13.0"
Revise = "3"
Statistics = "1"
Tar = "1.10.0"
julia = "1.9"

[extras]
Expand Down
Binary file modified data/missing_glaciers.jld2
Binary file not shown.
6 changes: 6 additions & 0 deletions src/Sleipnir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ using ComponentArrays
include("setup/ssl.jl")
using PythonCall, CondaPkg
using Rasters
using CSV
using JSON
using CodecZlib
using Tar
import NCDatasets

# ##############################################
# ############ PARAMETERS ###############
# ##############################################

cd(@__DIR__)
const global root_dir::String = dirname(Base.current_project())
const global prepro_dir::String = joinpath(homedir(), ".ODINN", "ODINN_prepro")

# ##############################################
# ########## SLEIPNIR LIBRARIES ##############
Expand Down
30 changes: 20 additions & 10 deletions src/glaciers/climate/Climate1D.jl
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@

@kwdef mutable struct Climate1Dstep{F <: AbstractFloat}
@kwdef mutable struct Climate1Dstep{F <: AbstractFloat}
temp::Vector{F}
PDD::Vector{F}
snow::Vector{F}
rain::Vector{F}
gradient::Ref{F}
avg_gradient::Ref{F}
gradient::F
avg_gradient::F
x::Vector{F}
y::Vector{F}
ref_hgt::Ref{F}
ref_hgt::F
end

@kwdef mutable struct Climate1D{F <: AbstractFloat}
raw_climate::Py # Raw climate dataset for the whole simulation
Base.:(==)(a::Climate1Dstep, b::Climate1Dstep) = a.temp == b.temp && a.PDD == b.PDD &&
a.snow == b.snow && a.rain == b.rain &&
a.gradient == b.gradient && a.avg_gradient == b.avg_gradient &&
a.x == b.x && a.y == b.y && a.ref_hgt == b.ref_hgt

@kwdef mutable struct Climate1D{F <: AbstractFloat}
raw_climate::RasterStack # Raw climate dataset for the whole simulation
# Buffers to avoid memory allocations
climate_raw_step::Ref{Py} # Raw climate trimmed for the current step
climate_step::Ref{Py} # Climate data for the current step
climate_raw_step::RasterStack # Raw climate trimmed for the current step
climate_step::Dict # Climate data for the current step
climate_2D_step::Climate2Dstep # 2D climate data for the current step to feed to the MB model
longterm_temps::Vector{F} # Longterm temperatures for the ice rheology
avg_temps::Ref{Py} # Intermediate buffer for computing average temperatures
avg_gradients::Ref{Py} # Intermediate buffer for computing average gradients
avg_temps::F # Intermediate buffer for computing average temperatures
avg_gradients::F # Intermediate buffer for computing average gradients
end

Base.:(==)(a::Climate1D, b::Climate1D) = a.raw_climate == b.raw_climate && a.climate_raw_step == b.climate_raw_step &&
a.climate_step == b.climate_step && a.climate_2D_step == b.climate_2D_step &&
a.longterm_temps == b.longterm_temps && a.avg_temps == b.avg_temps &&
a.avg_gradients == b.avg_gradients
28 changes: 19 additions & 9 deletions src/glaciers/climate/Climate2D.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@

export Climate2Dstep, Climate2D

@kwdef mutable struct Climate2Dstep{F <: AbstractFloat}
@kwdef mutable struct Climate2Dstep{F <: AbstractFloat}
temp::Matrix{F}
PDD::Matrix{F}
snow::Matrix{F}
rain::Matrix{F}
gradient::Ref{F}
avg_gradient::Ref{F}
gradient::F
avg_gradient::F
x::Vector{F}
y::Vector{F}
ref_hgt::Ref{F}
ref_hgt::F
end

@kwdef mutable struct Climate2D{F <: AbstractFloat}
Base.:(==)(a::Climate2Dstep, b::Climate2Dstep) = a.temp == b.temp && a.PDD == b.PDD &&
a.snow == b.snow && a.rain == b.rain &&
a.gradient == b.gradient && a.avg_gradient == b.avg_gradient &&
a.x == b.x && a.y == b.y && a.ref_hgt == b.ref_hgt

@kwdef mutable struct Climate2D{F <: AbstractFloat}
raw_climate::RasterStack # Raw climate dataset for the whole simulation
# Buffers to avoid memory allocations
climate_raw_step::Ref{RasterStack} # Raw climate trimmed for the current step
climate_step::Ref{RasterStack} # Climate data for the current step
climate_raw_step::RasterStack # Raw climate trimmed for the current step
climate_step::Dict # Climate data for the current step
climate_2D_step::Climate2Dstep # 2D climate data for the current step to feed to the MB model
longterm_temps::Vector{F} # Longterm temperatures for the ice rheology
avg_temps::Ref{RasterStack} # Intermediate buffer for computing average temperatures
avg_gradients::Ref{RasterStack} # Intermediate buffer for computing average gradients
avg_temps::F # Intermediate buffer for computing average temperatures
avg_gradients::F # Intermediate buffer for computing average gradients
end

Base.:(==)(a::Climate2D, b::Climate2D) = a.raw_climate == b.raw_climate && a.climate_raw_step == b.climate_raw_step &&
a.climate_step == b.climate_step && a.climate_2D_step == b.climate_2D_step &&
a.longterm_temps == b.longterm_temps && a.avg_temps == b.avg_temps &&
a.avg_gradients == b.avg_gradients
Loading

0 comments on commit 0604755

Please sign in to comment.