|
| 1 | +import glob |
| 2 | +import io |
| 3 | +import os |
| 4 | +import shutil |
| 5 | +import sys |
| 6 | +import zipfile |
| 7 | +from datetime import datetime |
| 8 | + |
| 9 | +import requests |
| 10 | +import utils |
| 11 | + |
| 12 | +model_path = utils.get_model_path(sys.argv, "young2018") |
| 13 | +zip_path = "Young_etal_2018_GeoscienceFrontiers_GPlatesPlateMotionModel" |
| 14 | + |
| 15 | +info_fp = open(f"{model_path}/info.txt", "w+") |
| 16 | +info_fp.write(f"{datetime.now()}\n") |
| 17 | + |
| 18 | +# download the model zip file |
| 19 | +zip_url = "https://www.earthbyte.org/webdav/ftp/Data_Collections/Young_etal_2018_GeoscienceFrontiers/Young_etal_2018_GeoscienceFrontiers_GPlatesPlateMotionModel.zip" |
| 20 | +info_fp.write(f"Download zip file from {zip_url}\n") |
| 21 | +r = requests.get(zip_url, allow_redirects=True, verify=True) |
| 22 | +if r.status_code in [200]: |
| 23 | + z = zipfile.ZipFile(io.BytesIO(r.content)) |
| 24 | + z.extractall(f"{model_path}/") |
| 25 | + |
| 26 | + |
| 27 | +# zip Rotations |
| 28 | +files = glob.glob(f"{model_path}/{zip_path}/*.rot") |
| 29 | +utils.zip_files(files, f"{model_path}/Rotations.zip", "Rotations", info_fp) |
| 30 | + |
| 31 | + |
| 32 | +# zip StaticPolygons |
| 33 | +files = glob.glob(f"{model_path}/{zip_path}/StaticPolygons/*") |
| 34 | +utils.zip_files(files, f"{model_path}/StaticPolygons.zip", "StaticPolygons", info_fp) |
| 35 | + |
| 36 | +# zip Coastlines |
| 37 | +files = glob.glob(f"{model_path}/{zip_path}/Coastlines/*") |
| 38 | +utils.zip_files(files, f"{model_path}/Coastlines.zip", "Coastlines", info_fp) |
| 39 | + |
| 40 | + |
| 41 | +# zip Topologies |
| 42 | +files = [ |
| 43 | + f"{model_path}/{zip_path}/Global_Mesozoic-Cenozoic_plate_boundaries_Young_et_al.gpml", |
| 44 | + f"{model_path}/{zip_path}/Global_Paleozoic_plate_boundaries_Young_et_al.gpml", |
| 45 | + f"{model_path}/{zip_path}/TopologyBuildingBlocks_Young_et_al.gpml", |
| 46 | +] |
| 47 | +utils.zip_files(files, f"{model_path}/Topologies.zip", "Topologies", info_fp) |
| 48 | + |
| 49 | + |
| 50 | +# zip ContinentalPolygons |
| 51 | +files = glob.glob(f"{model_path}/{zip_path}/ContinentalPolygons/*") |
| 52 | +utils.zip_files( |
| 53 | + files, f"{model_path}/ContinentalPolygons.zip", "ContinentalPolygons", info_fp |
| 54 | +) |
| 55 | + |
| 56 | + |
| 57 | +shutil.rmtree(f"{model_path}/{zip_path}") |
| 58 | +os.remove(f"{model_path}/License.txt") |
| 59 | + |
| 60 | +info_fp.close() |
0 commit comments