Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #53

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
462 changes: 373 additions & 89 deletions easymore/easymore.py

Large diffs are not rendered by default.

159 changes: 96 additions & 63 deletions examples/00_test_example.ipynb

Large diffs are not rendered by default.

47 changes: 28 additions & 19 deletions examples/01_ERA5_Regular_Lat_Lon.ipynb

Large diffs are not rendered by default.

88 changes: 62 additions & 26 deletions examples/02_ERA5_Regular_Lat_Lon_NaN.ipynb

Large diffs are not rendered by default.

106 changes: 83 additions & 23 deletions examples/03_WRF_Rotated_Lat_Lon.ipynb

Large diffs are not rendered by default.

155 changes: 93 additions & 62 deletions examples/05_irregular_shapes.ipynb

Large diffs are not rendered by default.

327 changes: 327 additions & 0 deletions examples/10_Calendar_365.ipynb

Large diffs are not rendered by default.

Binary file modified examples/data/Alberta_population/census_2016_DA_Canada.nc
Binary file not shown.
Binary file added examples/data/Source_nc_CanRCM4/CanRCM4_prcp.nc
Binary file not shown.
Binary file modified examples/data/Source_nc_ERA5/ERA5_NA_19790101.ncNaN
Binary file not shown.
Binary file modified examples/data/Source_nc_ERA5/ERA5_NA_19790102.ncNaN
Binary file not shown.
Binary file modified examples/data/Source_nc_ERA5/ERA5_NA_19790103.ncNaN
Binary file not shown.
48 changes: 48 additions & 0 deletions examples/parallel/ERA5_Regular_Lat_Lon_parallel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import multiprocessing
import os
import glob
from easymore.easymore import easymore

def easymore_config():
esmr = easymore() # initial the easymore
#esmr.read_config_dict('config.txt') # read the configuration file
esmr.case_name = "ERA5_capitals_north_america"
esmr.temp_dir = "../temporary/"
esmr.target_shp = "../data/target_shapefiles/Capitals_point.shp"
esmr.source_nc = "../data/Source_nc_ERA5/ERA5_NA_*.nc"
esmr.var_names = ["airtemp"]
esmr.var_lon = "longitude"
esmr.var_lat = "latitude"
esmr.var_time = "time"
esmr.output_dir = "../output/"
return esmr

def process_nc(nc_name):
print("Processing", nc_name)
print(str(os.getpid()))

esmr = easymore_config()
esmr.only_create_remap_csv = False # back to false/default in case if it reamins true (de)
esmr.source_nc = nc_name # update the file name
esmr.remap_csv = esmr.temp_dir+esmr.case_name +'_remapping.csv' # pass the remapping file name to skip remapping craetion
esmr.nc_remapper() # create remap file

if __name__ == '__main__':

# initialise easymore and read configuration from the file
esmr = easymore_config()
esmr.only_create_remap_csv = True # only crate the remapping file

# get the nc file names
nc_names = sorted(glob.glob(esmr.source_nc))
# Create a multiprocessing.Pool with the desired number of processes
num_processes = multiprocessing.cpu_count() # Use the number of available CPU cores
num_processes = min(len(nc_names), num_processes) # limit the worker if number of files is smaller
pool = multiprocessing.Pool(processes=num_processes) # assign the number of workers

# Use pool.map() to parallelize the for loop
pool.map(process_nc, nc_names)

# Close the pool to free up resources
pool.close()
pool.join()
24 changes: 24 additions & 0 deletions examples/parallel/SLURM_job.submit
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
#SBATCH --account=rpp-kshook
#SBATCH --ntasks=4
#SBATCH --mem-per-cpu=2G
#SBATCH --time=00:30:00 # time (DD-HH:MM)
#SBATCH --job-name=easymore_era5_remapping
#SBATCH --error=easymore_era5_remapping

# load needed modules
module load StdEnv/2020 gcc/9.3.0 openmpi/4.0.3
module load gdal/3.5.1 libspatialindex/1.8.5
module load python/3.8.10 scipy-stack/2022a mpi4py/3.0.3

# create virtual env inside the job
virtualenv --no-download $SLURM_TMPDIR/env
source $SLURM_TMPDIR/env/bin/activate
pip install --no-index --upgrade pip
pip install --no-index easymore

# OR use your locally created virtual env in home directory (created as explained on log in node; above)
# source ~/easymore-env/bin/activate # when this is uncommneted, then commnet above (virtualenv ...)

# run python script that include easymore remapper
python ERA5_Regular_Lat_Lon_parallel.py
11 changes: 11 additions & 0 deletions examples/parallel/config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"case_name" : "ERA5_capitals_north_america",
"temp_dir" : "./../temporary/",
"target_shp" : "./../data/target_shapefiles/Capitals_point.shp",
"source_nc" : "./../data/Source_nc_ERA5/ERA5_NA_*.nc",
"var_names" : ["airtemp"],
"var_lon" : "longitude",
"var_lat" : "latitude",
"var_time" : "time",
"output_dir" : "./../output/"
}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

setup(
name='easymore',
version='1.0.0',
version='1.1.0',
license='GPLv3',
author=('Shervan Gharari'),
author_email = '[email protected]',
Expand Down