FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 0854b215 authored by L. Bower's avatar L. Bower
Browse files

not-zipping nc files created from NAME anymore

parent 47eb3ce3
No related branches found
No related tags found
No related merge requests found
import datetime
import os
import sys
import cftime
from os.path import basename
import zipfile
from zipfile import ZipFile
import cftime
import iris.util
from iris.cube import CubeList, Cube
def save_and_zip_cube(cube: iris.cube.Cube,
sanitised_field_name: str,
year_string: str,
month_string: str,
output_path: str):
def save_cube(cube: iris.cube.Cube,
sanitised_field_name: str,
year_string: str,
month_string: str,
output_path: str):
os.makedirs(output_path, exist_ok = True)
......@@ -24,13 +20,13 @@ def save_and_zip_cube(cube: iris.cube.Cube,
print("writing {}".format(nc_file_path))
iris.save(cube, nc_file_path)
nc_zip_file_path = "{}.zip".format(nc_file_path)
print("zipping to {}".format(nc_zip_file_path))
with ZipFile(nc_zip_file_path, 'w', zipfile.ZIP_DEFLATED) as zip:
zip.write(nc_file_path, basename(nc_file_path))
print("deleting {}".format(nc_file_path))
os.remove(nc_file_path)
# nc_zip_file_path = "{}.zip".format(nc_file_path)
# print("zipping to {}".format(nc_zip_file_path))
# with ZipFile(nc_zip_file_path, 'w', zipfile.ZIP_DEFLATED) as zip:
# zip.write(nc_file_path, basename(nc_file_path))
#
# print("deleting {}".format(nc_file_path))
# os.remove(nc_file_path)
def process_met_office_NAME(name_file_wildcard: str, out_path: str):
......@@ -67,17 +63,19 @@ def process_met_office_NAME(name_file_wildcard: str, out_path: str):
sample_date = time_coord.units.num2date(time_coord.points[0])
year_string = cftime.datetime.strftime(sample_date, "%Y")
month_string = cftime.datetime.strftime(sample_date, "%m")
# year_string = cftime.real_datetime.strftime(sample_date, "%Y")
# month_string = cftime.real_datetime.strftime(sample_date, "%m")
# get rid of funny characters, for filename
sanitised_field_name = field_name.replace("(", "")
sanitised_field_name = sanitised_field_name.replace(")", "")
sanitised_field_name = sanitised_field_name.replace("/", "_")
save_and_zip_cube(cube_for_month,
sanitised_field_name,
year_string,
month_string,
out_path)
save_cube(cube_for_month,
sanitised_field_name,
year_string,
month_string,
out_path)
if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment