-
Notifications
You must be signed in to change notification settings - Fork 10
Add fetch command to download expedition data based on space_time_region from schedule.yaml
#83
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
Changes from 13 commits
7ac5d4d
8c641cc
6b6b874
6743f1f
40d4d0d
3194056
aacbb38
5988c90
fe77ea1
3d7697e
fafc74f
ad97b93
46af584
e092658
bb776a6
870a2c2
8df718a
c691a47
5fbf812
391f5ef
17fef2b
672fa6a
51451cf
bc88360
f3a0dc9
3b5edc6
fb1effd
97b4d8d
bb8bacd
43f3329
368bd64
123ad3d
471d43a
ef1e6bc
3bb4e6a
737e34f
6b2eb20
60952d8
1854258
77d40ab
ac61cf1
61ab177
34bea16
a125a11
61a9c32
a2a61c8
777f505
f6908df
2a3c9ab
66a1bb9
3012812
4160437
fd060d7
d2a7bc8
18b86ec
524c650
ad995c3
afe6112
5669e41
bcfe01e
0ef7cf0
b830393
8d35d4b
9ffd8de
cfc50cc
7132766
8698d13
04d7c13
93576c8
a2290b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| from datetime import datetime | ||
| from pathlib import Path | ||
|
|
||
| import click | ||
| import copernicusmarine | ||
|
|
||
| from virtualship import utils | ||
| from virtualship.expedition.do_expedition import do_expedition | ||
| from virtualship.expedition.do_expedition import _get_schedule, do_expedition | ||
| from virtualship.utils import SCHEDULE, SHIP_CONFIG | ||
|
|
||
|
|
||
|
|
@@ -45,9 +47,76 @@ def init(path): | |
| "path", | ||
| type=click.Path(exists=True, file_okay=False, dir_okay=True, readable=True), | ||
| ) | ||
| def fetch(path): | ||
| """Entrypoint for the tool.""" | ||
| raise NotImplementedError("Not implemented yet.") | ||
| def fetch(expedition_dir: str | Path) -> None: | ||
| """Entrypoint for the tool to download data based on area of interest.""" | ||
VeckoTheGecko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if isinstance(expedition_dir, str): | ||
| expedition_dir = Path(expedition_dir) | ||
iuryt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Load schedule | ||
iuryt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| schedule = _get_schedule(expedition_dir) | ||
| if schedule is None: | ||
| print("Error: Schedule file not found.") | ||
| return | ||
VeckoTheGecko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Extract area_of_interest details from the schedule | ||
| spatial_range = schedule.area_of_interest.spatial_range | ||
| time_range = schedule.area_of_interest.time_range | ||
| start_datetime = datetime.strptime(time_range.start_time, "%Y-%m-%d %H:%M:%S") | ||
| end_datetime = datetime.strptime(time_range.end_time, "%Y-%m-%d %H:%M:%S") | ||
|
|
||
| # Prompt for user credentials | ||
| username = input("username: ") | ||
| password = input("password: ") | ||
VeckoTheGecko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Define all datasets to download, including bathymetry | ||
| download_dict = { | ||
| "Bathymetry": { | ||
| "dataset_id": "cmems_mod_glo_phy_my_0.083deg_static", | ||
| "variables": ["deptho"], | ||
| "output_filename": "bathymetry.nc", | ||
| "force_dataset_part": "bathy", | ||
| }, | ||
| "UVdata": { | ||
| "dataset_id": "cmems_mod_glo_phy-cur_anfc_0.083deg_PT6H-i", | ||
| "variables": ["uo", "vo"], | ||
| "output_filename": "default_uv.nc", | ||
| }, | ||
| "Sdata": { | ||
| "dataset_id": "cmems_mod_glo_phy-so_anfc_0.083deg_PT6H-i", | ||
| "variables": ["so"], | ||
| "output_filename": "default_s.nc", | ||
| }, | ||
| "Tdata": { | ||
| "dataset_id": "cmems_mod_glo_phy-thetao_anfc_0.083deg_PT6H-i", | ||
| "variables": ["thetao"], | ||
| "output_filename": "default_t.nc", | ||
| }, | ||
| } | ||
|
|
||
| # Iterate over all datasets and download each based on area_of_interest | ||
| for dataset in download_dict.values(): | ||
| copernicusmarine.subset( | ||
| dataset_id=dataset["dataset_id"], | ||
| variables=dataset["variables"], | ||
| minimum_longitude=spatial_range.min_longitude, | ||
| maximum_longitude=spatial_range.max_longitude, | ||
| minimum_latitude=spatial_range.min_latitude, | ||
| maximum_latitude=spatial_range.max_latitude, | ||
| start_datetime=start_datetime, | ||
| end_datetime=end_datetime, | ||
| minimum_depth=0.49402499198913574, | ||
| maximum_depth=5727.9169921875, | ||
|
||
| output_filename=dataset["output_filename"], | ||
| output_directory=expedition_dir, | ||
| username=username, | ||
| password=password, | ||
| force_download=True, | ||
| force_dataset_part=dataset.get( | ||
| "force_dataset_part" | ||
| ), # Only used if specified in dataset | ||
| ) | ||
|
|
||
| click.echo("Data download based on area of interest completed.") | ||
|
|
||
|
|
||
| @click.command(help="Do the expedition.") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| """AreaOfInterest class.""" | ||
VeckoTheGecko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| from dataclasses import dataclass | ||
| from datetime import datetime | ||
|
|
||
|
|
||
| @dataclass | ||
| class SpatialRange: | ||
| """Defines the geographic boundaries for an area of interest.""" | ||
|
|
||
| minimum_longitude: float | ||
| maximum_longitude: float | ||
| minimum_latitude: float | ||
| maximum_latitude: float | ||
|
|
||
|
|
||
| @dataclass | ||
| class TimeRange: | ||
| """Defines the temporal boundaries for an area of interest.""" | ||
|
|
||
| start_time: datetime | ||
| end_time: datetime | ||
|
|
||
|
|
||
| @dataclass | ||
| class AreaOfInterest: | ||
| """An area of interest with spatial and temporal boundaries.""" | ||
|
|
||
| spatial_range: SpatialRange | ||
| time_range: TimeRange | ||
Uh oh!
There was an error while loading. Please reload this page.