Skip to content

Commit

Permalink
Merge pull request #35 from MeteoSwiss-APN/shape-file-feat
Browse files Browse the repository at this point in the history
Bug fix merge files
  • Loading branch information
Karko93 authored Dec 22, 2023
2 parents 43645c4 + da9617e commit d27a626
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/pyflexplot/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,10 @@ def merge_shape_files(
merged_files: List[str] = []
n = 0
for i, group in enumerate(grouped_file_paths):
merged = f"""{dest_dir}{relpath(paths_organizer.merge(group), start=tmp_dir)}"""
tmp_zip_name = f"{dest_dir}temp_shape{i}.zip"
merged = (
f"""{dest_dir}/{relpath(paths_organizer.merge(group), start=tmp_dir)}"""
)
tmp_zip_name = f"{dest_dir}/temp_shape{i}.zip"
if not dry_run:
with zipfile.ZipFile(tmp_zip_name, "w") as main_zip:
for file in group:
Expand Down
49 changes: 49 additions & 0 deletions src/pyflexplot/data/presets/opr/ifs-hres/all_shp.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# PyFlexPlot setup file to create deterministic IFS-HRES-EU plots

[_base]
# Data source: tsa:/scratch/ruestefa/shared/test/pyflexplot/
infile = "data/ifs-hres/grid_conc_1000_20200818000000_bushehr_2spec.nc"
model = "IFS-HRES"
lang = "de"
outfile_time_format = "%Y%m%dT%H%M"
combine_species = false

[_base._concentration]
plot_variable = "concentration"
level = 0

[_base._concentration._integr]
integrate = true
time = -1

[_base._tot_deposition]
plot_variable = "tot_deposition"
integrate = true

[_base._affected_area]
plot_variable = "affected_area"
integrate = true
level = 0
time = -1
combine_species = true

[_base._concentration."_png+"]
outfile = "concentration_site-{release_site}_species-{species_id}_domain-{domain}_lang-{lang}_ts-{time_step}.shp"
[_base._concentration._integr."_png+"]
outfile = "integrated_concentration_site-{release_site}_species-{species_id}_domain-{domain}_lang-{lang}_ts-{time_step}.shp"
[_base._tot_deposition."_png+"]
outfile = "deposition_tot_site-{release_site}_species-{species_id}_domain-{domain}_lang-{lang}_ts-{time_step}.shp"
[_base._affected_area."_png+"]
outfile = "affected_area_site-{release_site}_species-{species_id}_domain-{domain}_lang-{lang}_ts-{time_step}.shp"

[_base._concentration."_multipanel_time+"]
outfile = "concentration_site-{release_site}_species-{species_id}_domain-{domain}_lang-{lang}_ts-{time_step}.shp"
plot_type = "multipanel"
multipanel_param = "time"
time = [2, 4, 8, -1]

["**".full]
domain = "cloud"

["**".zoom]
domain = "release_site"
4 changes: 1 addition & 3 deletions src/pyflexplot/save_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,7 @@ def save(self, filename: str, plot: BoxedPlot, data: FieldGroup) -> None:

def _move_shape_file_to_zip(self, base_file_dir: str, zip_file: zipfile.ZipFile):
"""Move the generated shapefile components into a ZIP archive."""
extensions = [".shp", ".shx", ".dbf"]
if "_domain" not in base_file_dir:
extensions += [".shp.xml"]
extensions = [".shp", ".shx", ".dbf", ".shp.xml"]
for ext in extensions:
file_to_copy = f"{base_file_dir}{ext}"
with open(file_to_copy, "rb") as file_in_zip:
Expand Down
2 changes: 1 addition & 1 deletion src/srutils/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def group_related(self, paths: Sequence[str]) -> list[list[str]]:
if rx_numbered.search(path):
# Numbered, so not the first
continue
path_base = path.split(self._dup_sep)[0]
path_base = path.rstrip(self._suffix)
paths.remove(path)
grouped_file_paths.append([path])
rx_related = re.compile(
Expand Down
2 changes: 1 addition & 1 deletion tools/setup_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DEFAULT_ENV_NAME="pyflexplot"

# Default options
ENV_NAME="${DEFAULT_ENV_NAME}"
PYVERSION=3.10
PYVERSION=3.11
PINNED=true
EXPORT=false
CONDA=conda
Expand Down

0 comments on commit d27a626

Please sign in to comment.