HmbGen
HmbGen¶
A high-level interface intended to simplify the usage of the package for common scenarios. This uses other API elements that can also be used directly for more control on the settings or more advanced scenarios.
Here is a basic, schematic example of how to use this class:
# Create instance:
hmb_gen = HmbGen()
# Indicate parameters as needed:
hmb_gen.set_json_base_dir("json")
hmb_gen.set_global_attrs_uri("gs://bucket/globalAttributes.yaml")
hmb_gen.set_variable_attrs_uri("gs://bucket/variableAttributes.yaml")
hmb_gen.set_subset_to((0, 100))
hmb_gen.set_download_dir("download")
hmb_gen.set_output_dir("output")
hmb_gen.set_output_prefix("hmb_")
hmb_gen.set_add_quality_flag(True)
hmb_gen.set_gs_client(gs_client)
# Before processing, perform basic check of the parameters:
errors = hmb_gen.check_parameters()
if errors:
print(f"Errors: {errors}")
else:
result = hmb_gen.process_date("20220101")
if result:
print(f"Result: {result}")
hmb_gen.plot_date(
"20220101",
lat_lon_for_solpos=(37.7749, -122.4194),
title="HMB",
ylim=(0, 100),
cmlim=(0, 100),
dpi=300,
show=True,
)
Source code in pbp/simpleapi.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
|
__init__()
¶
Create a new object for HMB generation.
On the created instance, call the various set_*
methods to set the parameters,
check_parameters()
to verify the parameters, and
then call process_date()
to execute the process for a given date.
See source code for more details on the default parameter values.
Source code in pbp/simpleapi.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
set_json_base_dir(json_base_dir)
¶
Set the base directory where JSON files are located.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_base_dir |
str
|
The base directory where JSON files are located. |
required |
Source code in pbp/simpleapi.py
89 90 91 92 93 94 95 96 |
|
set_global_attrs_uri(global_attrs_uri)
¶
Set the URI for global attributes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
global_attrs_uri |
str
|
The URI for global attributes. |
required |
Source code in pbp/simpleapi.py
98 99 100 101 102 103 104 105 |
|
set_variable_attrs_uri(variable_attrs_uri)
¶
Set the URI for variable attributes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_attrs_uri |
str
|
The URI for variable attributes. |
required |
Source code in pbp/simpleapi.py
107 108 109 110 111 112 113 114 |
|
set_voltage_multiplier(voltage_multiplier)
¶
Set the voltage multiplier. By default, this is 1.0.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
voltage_multiplier |
float
|
The voltage multiplier. |
required |
Source code in pbp/simpleapi.py
116 117 118 119 120 121 122 123 |
|
set_sensitivity(sensitivity)
¶
Set Sensitivity flat value (a float), or URI of sensitivity file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sensitivity |
float | str
|
Sensitivity flat value (a float), or URI of sensitivity file. |
required |
Source code in pbp/simpleapi.py
125 126 127 128 129 130 131 132 |
|
set_subset_to(subset_to)
¶
Set the frequency subset to use for the PSD.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subset_to |
tuple[int, int]
|
Tuple of (lower, upper), with lower inclusive, upper exclusive. |
required |
Source code in pbp/simpleapi.py
134 135 136 137 138 139 140 141 |
|
set_download_dir(download_dir)
¶
Set the download directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
download_dir |
str
|
The download directory. |
required |
Source code in pbp/simpleapi.py
143 144 145 146 147 148 149 150 |
|
set_output_dir(output_dir)
¶
Set the output directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_dir |
str
|
The output directory. |
required |
Source code in pbp/simpleapi.py
152 153 154 155 156 157 158 159 |
|
set_output_prefix(output_prefix)
¶
Set the output prefix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_prefix |
str
|
The output prefix. |
required |
Source code in pbp/simpleapi.py
161 162 163 164 165 166 167 168 |
|
set_compress_netcdf(compress_netcdf)
¶
Set whether to compress the NetCDF file. This is done by default.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
compress_netcdf |
bool
|
Whether to compress the NetCDF file. |
required |
Source code in pbp/simpleapi.py
170 171 172 173 174 175 176 177 178 |
|
set_add_quality_flag(add_quality_flag)
¶
Set whether to add quality flag variable (with value fixed to 2 - "Not evaluated") to the NetCDF file. This is not done by default.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
add_quality_flag |
bool
|
Whether to add quality flag variable. |
required |
Source code in pbp/simpleapi.py
180 181 182 183 184 185 186 187 188 |
|
set_assume_downloaded_files(value)
¶
Set whether to skip downloading files that already exist in the download directory. This is not done by default.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
bool
|
If True, skip downloading files that already exist in the download directory. |
required |
Source code in pbp/simpleapi.py
190 191 192 193 194 195 196 197 198 199 |
|
set_retain_downloaded_files(value)
¶
Set whether to retain downloaded files after use. This is not done by default.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
bool
|
If True, do not remove downloaded files after use. |
required |
Source code in pbp/simpleapi.py
201 202 203 204 205 206 207 208 209 210 |
|
set_print_downloading_lines(value)
¶
Set whether to print "downloading
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
bool
|
If True, print "downloading |
required |
Source code in pbp/simpleapi.py
212 213 214 215 216 217 218 219 220 221 |
|
set_s3_client(s3_client)
¶
Set the S3 client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s3_client |
BaseClient
|
The S3 client. |
required |
Source code in pbp/simpleapi.py
223 224 225 226 227 228 229 230 231 232 |
|
set_gs_client(gs_client)
¶
Set the GS client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gs_client |
Client
|
The GS client. |
required |
Source code in pbp/simpleapi.py
234 235 236 237 238 239 240 241 242 243 |
|
check_parameters()
¶
Performs a basic check of the parameters, especially verifying that the required ones are given. Call this before performing any processing.
Returns:
Type | Description |
---|---|
str | None
|
None if no errors, otherwise a string with the errors. |
Source code in pbp/simpleapi.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
process_date(date)
¶
Generates NetCDF file with the result of processing all segments of the given day.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
date |
str
|
Date to process in YYYYMMDD format. |
required |
Returns:
Type | Description |
---|---|
ProcessDayResult | str
|
ProcessDayResult if segments were processed, otherwise a string with an error. |
Source code in pbp/simpleapi.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
|
plot_date(date, lat_lon_for_solpos, title, ylim, cmlim, dpi, show=False)
¶
Generate a summary plot for the given date. Make sure the NetCDF file for the given date has been generated first. The output will be saved as a JPEG file with name derived from the input date resulting in a sibling file to the NetCDF file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
date |
str
|
Date to plot in |
required |
lat_lon_for_solpos |
tuple[float, float]
|
Latitude and longitude for solar position calculation. |
required |
title |
str
|
Title for the plot. |
required |
ylim |
tuple[float, float]
|
Limits for the y-axis. |
required |
cmlim |
tuple[float, float]
|
Limits passed to |
required |
dpi |
int
|
DPI to use for the plot. |
required |
show |
bool
|
Whether to also show the plot. Defaults to |
False
|
Source code in pbp/simpleapi.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
|