Mercurial > repos > ecology > copernicusmarine
comparison argo_getdata.py @ 0:4de886e6300d draft
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/ocean commit a7e53c429cf93485aba692b928defe6ee01633d6
author | ecology |
---|---|
date | Tue, 22 Oct 2024 15:55:13 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4de886e6300d |
---|---|
1 # author: Marie Jossé | |
2 | |
3 # Python script | |
4 | |
5 ############################# | |
6 # Argo data access # | |
7 ############################# | |
8 | |
9 # Packages : argopy | |
10 | |
11 | |
12 # Load arguments | |
13 import argparse | |
14 import sys | |
15 | |
16 import argopy | |
17 | |
18 command_line_args = sys.argv[1:] | |
19 | |
20 | |
21 parser = argparse.ArgumentParser(description="Retrieve argo Data") | |
22 # Add arguments | |
23 | |
24 parser.add_argument("--user", type=str, | |
25 help="User mode : standard, expert or research") | |
26 parser.add_argument("--cardinal_1", type=float, help="Longitude min") | |
27 parser.add_argument("--cardinal_2", type=float, help="Longitude max") | |
28 parser.add_argument("--cardinal_3", type=float, help="Latitude min") | |
29 parser.add_argument("--cardinal_4", type=float, help="Latitude max") | |
30 parser.add_argument("--pressure_1", type=float, help="Pressure min") | |
31 parser.add_argument("--pressure_2", type=float, help="Pressure max") | |
32 parser.add_argument("--date_1", type=str, help="Starting date") | |
33 parser.add_argument("--date_2", type=str, help="Ending date.") | |
34 parser.add_argument("--wmo", type=str, help="WMO: argo's identifier") | |
35 parser.add_argument("--profile", type=str, help="Number of profiles") | |
36 parser.add_argument("--params", type=str, help="List of bgc parameters") | |
37 parser.add_argument("--measured", type=str, help="List of bgc parameters") | |
38 parser.add_argument("--output_argo", type=str, help="Output data from argo") | |
39 | |
40 args = parser.parse_args(command_line_args) | |
41 | |
42 | |
43 # Parse the command line arguments | |
44 | |
45 print(args) | |
46 # Import data | |
47 | |
48 user = args.user | |
49 cardinal_1 = args.cardinal_1 | |
50 cardinal_2 = args.cardinal_2 | |
51 cardinal_3 = args.cardinal_3 | |
52 cardinal_4 = args.cardinal_4 | |
53 pressure_1 = args.pressure_1 | |
54 pressure_2 = args.pressure_2 | |
55 date_1 = args.date_1 | |
56 date_2 = args.date_2 | |
57 wmo = args.wmo | |
58 if wmo is not None: | |
59 wmo = list(map(int, wmo.split(","))) | |
60 profile = args.profile | |
61 if profile is not None: | |
62 profile = list(map(int, profile.split(","))) | |
63 params = args.params | |
64 if params is not None: | |
65 params = params.split(",") | |
66 if len(params) == 83: | |
67 params = "all" | |
68 measured = args.measured | |
69 if measured is not None: | |
70 measured = measured.split(",") | |
71 | |
72 # Let’s import the argopy data fetcher: | |
73 | |
74 ###################### | |
75 # User mode # | |
76 ###################### | |
77 # By default, | |
78 # all argopy data fetchers are set to work with a standard user mode. | |
79 # To change that | |
80 | |
81 argopy.set_options(mode=user) | |
82 | |
83 ###################### | |
84 # Fetching Argo data # | |
85 ###################### | |
86 # Data selection # | |
87 | |
88 # To access Argo data with a DataFetcher, | |
89 # you need to define how to select your data of interest. | |
90 # argopy provides 3 different data selection methods: | |
91 | |
92 argo_data = argopy.DataFetcher() | |
93 | |
94 # 🗺 For a space/time domain # | |
95 | |
96 if (cardinal_1 is not None): | |
97 mode = "region" | |
98 argo_data = argo_data.region([cardinal_1, cardinal_2, | |
99 cardinal_3, cardinal_4, | |
100 pressure_1, pressure_2, | |
101 date_1, date_2]) | |
102 | |
103 # ⚓ For one or more profiles # | |
104 # Use the fetcher access point argopy.DataFetcher.profile() | |
105 # to specify the float WMO platform number | |
106 # and the profile cycle number(s) to retrieve profiles for. | |
107 elif (wmo is not None and profile is not None): | |
108 argo_data = argo_data.profile(wmo, profile) | |
109 # can also be argo_data = argo_data.profile(6902755, [3, 12]) | |
110 mode = "profile" | |
111 | |
112 # 🤖 For one or more floats # | |
113 # If you know the Argo float unique identifier number called a WMO number | |
114 # you can use the fetcher access point DataFetcher.float() | |
115 # to specify one or more float WMO platform numbers to select. | |
116 else: | |
117 argo_data = argo_data.float(wmo) | |
118 # can also be argo_data = argo_data.float([6902746, 6902755]) | |
119 mode = "float" | |
120 | |
121 # Data sources # | |
122 # Let’s start with standard import: | |
123 # argopy.reset_options() | |
124 # Specify data source erddap, gdac or argovis | |
125 | |
126 # if (ftp != "") : | |
127 # argopy.set_options(src = "gdac", ftp = ftp) | |
128 # else : | |
129 # argopy.set_options(src = "erddap") | |
130 | |
131 # With remote, online data sources, | |
132 # it may happens that the data server is experiencing down time. | |
133 print(argopy.status()) | |
134 | |
135 # Dataset # | |
136 # Argo data are distributed as a single dataset. | |
137 # It is referenced at https://doi.org/10.17882/42182. | |
138 # But they are several Argo missions with specific files and parameters | |
139 # that need special handling by argopy, namely: | |
140 # - the core Argo Mission: from floats that measure temperature, | |
141 # salinity, pressure down to 2000m, | |
142 # - the Deep Argo Mission: from floats that measure temperature, | |
143 # salinity, pressure down to 6000m, | |
144 # - and the BGC-Argo Mission: from floats that measure temperature, | |
145 # salinity, pressure and oxygen, pH, nitrate, chlorophyll, | |
146 # backscatter, irradiance down to 2000m. | |
147 # You can choose between phy or bgc | |
148 if (params is None): | |
149 argopy.set_options(dataset="phy") | |
150 else: | |
151 argopy.set_options(dataset="bgc") | |
152 if (measured != ['None'] and measured is not None): | |
153 argo_data = argopy.DataFetcher(params=params, measured=measured) | |
154 if (mode == "region"): | |
155 argo_data = argo_data.region([cardinal_1, cardinal_2, | |
156 cardinal_3, cardinal_4, | |
157 pressure_1, pressure_2, | |
158 date_1, date_2]) | |
159 elif (mode == "profile"): | |
160 argo_data = argo_data.profile(wmo, profile) | |
161 else: | |
162 argo_data = argo_data.float(wmo) | |
163 else: | |
164 argo_data = argopy.DataFetcher(params=params, measured=None) | |
165 if (mode == "region"): | |
166 argo_data = argo_data.region([cardinal_1, cardinal_2, | |
167 cardinal_3, cardinal_4, | |
168 pressure_1, pressure_2, | |
169 date_1, date_2]) | |
170 elif (mode == "profile"): | |
171 argo_data = argo_data.profile(wmo, profile) | |
172 else: | |
173 argo_data = argo_data.float(wmo) | |
174 | |
175 # Data fetching # | |
176 # To fetch (i.e. access, download, format) Argo data, | |
177 # argopy provides the DataFetcher class. | |
178 # Several DataFetcher arguments exist to help you select the dataset, | |
179 # the data source and the user mode the most suited for your applications; | |
180 # and also to improve performances. | |
181 | |
182 # You define the selection of data you want to fetch | |
183 # with one of the DataFetcher methods: region, float or profile. | |
184 # 2 lines to download Argo data: import and fetch ! | |
185 | |
186 argo_data = argo_data.load().data | |
187 argo_data.to_netcdf("argo_data.nc") | |
188 | |
189 # argo_metadata = argo_data.to_index() | |
190 | |
191 print(argo_data) |