CDIPpy API reference
cdippy.cdipnc
Active
Bases: CDIPnc
Loads an "active" (predeploy, moored, offsite, recovered) rt nc file for the given station and deployment.
E.g. a = Active('100', 6, 'predeploy') # The predeploy data for stn 100 dep 6.
Source code in cdippy/cdipnc.py
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 |
|
__init__(stn: str, deployment: int, active_state_key: str, data_dir: str = None, org: str = None)
PARAMETERS
stn : str Can be in 2, 3 or 5 char format e.g. 28, 028, 028p2 active_state_key : str Values: predeploy|moored|offsite|recovered deployment : int [optional] Supply this to access specific station deployment data. Must be >= 1. data_dir : str [optional] Either a full path to a directory containing a local directory hierarchy of nc files. E.g. '/project/WNC' or a url to a THREDDS server.
Source code in cdippy/cdipnc.py
895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 |
|
ActiveXY
Bases: Archive
Loads an "active" (predeploy, moored, offsite, recovered) xy nc file for the given station and deployment.
Source code in cdippy/cdipnc.py
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 |
|
__init__(stn, deployment, dataset, data_dir=None, org=None)
PARAMETERS ---------- dataset : str Active dataset name. Values are: predeploy|moored|offsite|recovered. For other parameters see CDIPnc.set_dataset_info.
Source code in cdippy/cdipnc.py
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 |
|
Archive
Bases: CDIPnc
Loads an archive (deployment) file for a given station and deployment.
Source code in cdippy/cdipnc.py
944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 |
|
__init__(stn, deployment=None, data_dir=None, org=None)
For parameters see CDIPnc.set_dataset_info.
Source code in cdippy/cdipnc.py
947 948 949 950 951 952 |
|
get_request()
Overrides the base class method to handle xyz data requests.
Source code in cdippy/cdipnc.py
984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 |
|
get_xyz_timestamp(xyzIndex: int) -> int
Returns the timestamp corresponding to the given xyz array index.
Source code in cdippy/cdipnc.py
972 973 974 975 976 977 978 979 980 981 982 |
|
CDIPnc
A base class used by the class StnData for retrieving data from CDIP netCDF (nc) files located either locally or remotely.
Files accessed remotely are served by CDIP's THREDDS server. Files accessed locally need to be located within a specific directory hierarchy.
For each CDIP nc file "type" such as historic.nc or archive.nc, there is a corresponding sub-class, e.g. Historic or Archive. Although the constructors of these classes can be used to access data, StnData is recommended because it seamlessly combines records across multiple files.
Source code in cdippy/cdipnc.py
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 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 |
|
__get_indices(times: list, start_stamp: int, end_stamp: int) -> tuple
Returns start and end indices to include any times that are equal to start_stamp or end_stamp.
Source code in cdippy/cdipnc.py
370 371 372 373 374 375 |
|
__init__(data_dir: str = None, deployment: int = None)
PARAMETERS
data_dir : str [optional] Either a full path to a directory containing a local directory hierarchy of nc files. E.g. '/project/WNC' or a url to a THREDDS server. deployment : int [optional] Supply this to access specific station deployment data. Must be >= 1.
Source code in cdippy/cdipnc.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
__make_masked_array(nc_var: str, s_idx: int, e_idx: int) -> np.ma.masked_array
Returns a numpy masked array for a given nc variable and indices.
e_idx is appropriate for python arrays. I.e. one more than last index.
Source code in cdippy/cdipnc.py
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 |
|
get_coverage_end() -> datetime
Returns the end time of the nc file data coverage.
Source code in cdippy/cdipnc.py
366 367 368 |
|
get_coverage_start() -> datetime
Returns the start time of the nc file data coverage.
Source code in cdippy/cdipnc.py
362 363 364 |
|
get_dataset_urls() -> dict
Returns a dict of two lists of urls (or paths) to all CDIP station datasets.
The top level keys are 'realtime' and 'historic'. The urls are retrieved by either descending into the THREDDS catalog.xml or recursively walking through data_dir sub directories.
For applications that need to use the data from multiple deployment files for a station, stndata:get_nc_files will load those files efficiently.
Source code in cdippy/cdipnc.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 |
|
get_date_modified() -> datetime
Returns the time the nc file was last modified.
Source code in cdippy/cdipnc.py
358 359 360 |
|
get_flag_meanings(flag_name: str) -> list
Returns flag category values and meanings given a flag_name.
Source code in cdippy/cdipnc.py
346 347 348 |
|
get_flag_values(flag_name: str) -> list
Returns flag category values and meanings given a flag_name.
Source code in cdippy/cdipnc.py
350 351 352 353 354 355 356 |
|
get_pub_set(name: str) -> str
Returns either 'public', 'nonpub' or 'all'.
Maintains backwards compatibility with prior pub_set names.
Source code in cdippy/cdipnc.py
327 328 329 330 331 332 333 334 335 |
|
get_request() -> dict
Returns the data specified using set_request_info.
RETURNS
A dictionary containing keys of the requested variables each of which is a numpy masked array of data values. In addition, the time values are returned as well. For example, if waveHs was requested, the dictionary will look like this:
Source code in cdippy/cdipnc.py
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 |
|
get_var(var_name: str)
Checks if a variable exists then returns a pointer to it.
Source code in cdippy/cdipnc.py
411 412 413 414 415 |
|
get_var_prefix(var_name: str) -> str
Returns 'wave' part of the string 'waveHs'.
Source code in cdippy/cdipnc.py
337 338 339 340 341 342 343 344 |
|
make_pub_mask(anc_name: str, s_idx: int, e_idx: int) -> np.ndarray
Returns an np.ndarray of bools given pub_set and ancillary var
Source code in cdippy/cdipnc.py
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 |
|
metaStationName() -> str
Returns the metaStationName.
Source code in cdippy/cdipnc.py
405 406 407 408 409 |
|
set_dataset_info(stn: str, org: str, dataset_name: str, deployment: int = None) -> None
Sets self.stn, org, filename, url and loads self.nc. The key to understanding all of this is that we are ultimately setting url, which can be an actual path to the nc file or a url to THREDDS DoDS service.
PARAMETERS
stn : str Can be in 3char (e.g. 028) or 5char (e.g. 028p2) format for org=cdip org: str (Organization) Values are: cdip|ww3|external dataset_name : str Values: realtime|historic|archive|realtimexy|archivexy| predeploy|moored|offsite|recovered deployment : int [optional] Supply this to access specific station deployment data. Must be >= 1.
Paths are
**Active deployment directories are PREDEPLOY (p0), MOORED (p1), OFFSITE (p2) and RECOVERED (p3) pX = p0|p1|p2|p3; deployment = dXX e.g. d01
Urls are
http://thredds.cdip.ucsd/thredds/dodsC/
Note: Since adding dataset_name, we no longer need the 5char stn id for org=cdip datasets. The p_val will be 'p1' for every dataset except active datasets in buoy states predeploy (p0), offsite (p2) and recovered (p3).
Source code in cdippy/cdipnc.py
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 |
|
set_request_info(start: datetime = None, end: datetime = None, vrs: list = ['waveHs'], pub_set: str = 'public', apply_mask: bool = True) -> None
Initializes data request information for get_request.
PARAMETERS
start : str or datetime [optional] : default Jan 1, 1975 Start time of data request (UTC). If provided as a string must be in the format Y-m-d H:M:S where Y is 4 chars and all others are 2 chars. Ex. '2020-03-30 19:32:56'. end : str or datetime [optional] : default now End time of data request (UTC). If not supplied defaults to now. vrs : list [optional] : default ['waveHs'] A list of the names of variables to retrieve. They all must start with the same prefix, e.g. ['waveHs', 'waveTp', 'waveDp'] pub_set: str [optional] values = public|nonpub|all Filters data based on data quality flags. apply_mask: bool [optional] default True Removes values from the masked array that have a mask value of True. Ex. If nonpub data is requested and apply_mask is False, the returned array will contain both public and nonpublic data (although public data records will have the mask value set to True). If apply_mask is set to True, only nonpub records will be returned.
Source code in cdippy/cdipnc.py
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 |
|
set_timespan(start, end)
Sets request timespan
Source code in cdippy/cdipnc.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
Historic
Bases: CDIPnc
Loads the historic nc file for a given station.
Source code in cdippy/cdipnc.py
931 932 933 934 935 936 937 938 |
|
__init__(stn, data_dir=None, org=None)
For parameters see CDIPnc.set_dataset_info.
Source code in cdippy/cdipnc.py
934 935 936 937 938 |
|
Latest
Bases: CDIPnc
Loads the latest_3day.nc and has methods for retrieving the data.
Source code in cdippy/cdipnc.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 |
|
__has_a_number(arr)
Test if there is at least one number in the array
Source code in cdippy/cdipnc.py
880 881 882 883 884 885 |
|
__init__(data_dir: str = None)
PARAMETERS
data_dir : str [optional] Either a full path to a directory containing a local directory hierarchy of nc files. E.g. '/project/WNC' or a url to a THREDDS server.
Source code in cdippy/cdipnc.py
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 |
|
get_latest(pub_set: str = 'public', meta_vars: list = None, params: list = None, array_format=True) -> list
By default, array_format = True, it will return a dictionary of numpy masked arrays of the latest requested parameters as well as metadata information.
If array_format = False, it returns a list of dicts. Each dict will contain latest station data and metadata.
Parameter data values that are masked or non-existant are set to np.nan. Time values (e.g. 'waveTime') for the wave data if masked or non-existant are set to None.
Both meta_vars and params if None (or not included in the argument list) will return default sets of meta_vars and parameters. If meta_vars and params are set just those will be returned.
Source code in cdippy/cdipnc.py
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 |
|
metaDeployLabels() -> list
Returns a list of metaDeployLabels.
Source code in cdippy/cdipnc.py
644 645 646 647 648 649 650 651 |
|
metaDeployNumbers() -> list
Returns a list of metaDeployNumbers.
Source code in cdippy/cdipnc.py
653 654 655 656 657 658 659 660 |
|
metaLatitudes() -> list
Returns a list of station latitudes, e.g. [23.4,...].
Source code in cdippy/cdipnc.py
671 672 673 674 675 676 677 678 |
|
metaLongitudes() -> list
Returns a list of station longitudes, e.g. [23.4,...].
Source code in cdippy/cdipnc.py
680 681 682 683 684 685 686 687 |
|
metaSiteLabels() -> list
Sets and returns self.labels, a list of station labels, e.g. ['100p1',...].
Source code in cdippy/cdipnc.py
636 637 638 639 640 641 642 |
|
metaStationNames() -> list
Get list of latest station names.
Source code in cdippy/cdipnc.py
627 628 629 630 631 632 633 634 |
|
metaWMOids() -> list
Returns a list of WMO ids, e.g. ['46225',...].
Source code in cdippy/cdipnc.py
662 663 664 665 666 667 668 669 |
|
metaWaterDepths() -> list
Returns a list of station water depths.
Source code in cdippy/cdipnc.py
689 690 691 692 693 694 695 696 |
|
Realtime
Bases: CDIPnc
Loads the realtime nc file for the given station.
Source code in cdippy/cdipnc.py
922 923 924 925 926 927 928 |
|
__init__(stn: str, data_dir: str = None, org: str = None)
For parameters: See CDIPnc.set_dataset_info.
Source code in cdippy/cdipnc.py
925 926 927 928 |
|
RealtimeXY
Bases: Archive
Loads the realtime xy nc file for the given station.
Source code in cdippy/cdipnc.py
1034 1035 1036 1037 1038 1039 1040 |
|
__init__(stn, data_dir=None, org=None)
For parameters see CDIPnc.set_dataset_info.
Source code in cdippy/cdipnc.py
1037 1038 1039 1040 |
|
cdippy.nchashes
NcHashes
A class that checks for changes to datasets since by reading the online list of historic netCDF file hashes.
Source code in cdippy/nchashes.py
5 6 7 8 9 10 11 12 13 14 15 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 |
|
compare_hash_tables() -> list
Compare the current in-memory list of files, loaded by load_hash_table
to the list saved in HASH.pkl and return a list of stations that are new or have changed.
Returns: |
|
---|
Source code in cdippy/nchashes.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
cdippy.ncstats
NcStats
Bases: StnData
Produces data availability statistics for a given station.
This class provides methods to
- Return counts for the entire station record, intended for use by web applications.
- Save availability counts (e.g., xyz counts) for individual NetCDF files. Updates to totals are calculated by re-summarizing any files that have changed and aggregating all files to produce new totals.
Source code in cdippy/ncstats.py
6 7 8 9 10 11 12 13 14 15 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 |
|
__init__(stn: str, data_dir: str = None)
Initializes an NcStats instance.
Parameters: |
|
---|
Source code in cdippy/ncstats.py
18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
by_month_count(cat_var, dim: str) -> pd.DataFrame
Counts observations by month for a given flag variable.
Parameters: |
|
---|
Returns: |
|
---|
Source code in cdippy/ncstats.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
deployment_summary() -> dict
Generates deployment summary statistics.
Returns: |
|
---|
Source code in cdippy/ncstats.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
flag_counts(QC_flags: list = None) -> dict
Computes counts of flag variables for the entire station record.
Parameters: |
|
---|
Returns: |
|
---|
Source code in cdippy/ncstats.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
load_file(nc_filename: str)
Loads a specific NetCDF file into the instance.
Parameters: |
|
---|
Sets
self.nc: Loaded NetCDF file object.
Source code in cdippy/ncstats.py
82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
load_nc_files(types: list = ['realtime', 'historic', 'archive']) -> dict
Loads NetCDF files for the station.
Parameters: |
|
---|
Returns: |
|
---|
Source code in cdippy/ncstats.py
70 71 72 73 74 75 76 77 78 79 80 |
|
make_stats() -> dict
Computes station-level statistics.
Returns: |
|
---|
Source code in cdippy/ncstats.py
32 33 34 35 36 37 38 39 40 41 42 43 |
|
nc_file_summary(nc_filename: str) -> dict
Computes a summary for a given NetCDF file.
Parameters: |
|
---|
Returns: |
|
---|
Source code in cdippy/ncstats.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
total_count(cat_var) -> pd.DataFrame
Counts totals for a given categorical flag variable.
Parameters: |
|
---|
Returns: |
|
---|
Source code in cdippy/ncstats.py
149 150 151 152 153 154 155 156 157 158 |
|
cdippy.ndbc
Methods for working with NDBC
get_stn_info(wmo_id)
Work in progress, querying ndbc sos service.
Source code in cdippy/ndbc.py
19 20 21 22 23 24 25 |
|
get_wmo_id(stn, store=True, filepath='.')
Queries cdip wmo id table for a given station. Drops pickle file locally.
Source code in cdippy/ndbc.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
cdippy.plotting
make_annual_hs_boxplot(stn: str, year: int) -> Figure
Create a boxplot of annual significant wave heights for a station.
Parameters: |
|
---|
Returns: |
|
---|
Source code in cdippy/plotting.py
5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
make_compendium_plot(stns: str, start: str, end: str, params: str, x_inch: int) -> Figure
CDIP's classic compendium plot for multiple stations and parameters.
Parameters: |
|
---|
Returns: |
|
---|
Source code in cdippy/plotting.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
make_sst_climatology_plot(stn: str, x_inch: int = None, y_inch: int = None) -> Figure
Create a plot of yearly climatology of sea surface temperature at a station for all years of available data.
Parameters: |
|
---|
Returns: |
|
---|
Source code in cdippy/plotting.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
cdippy.spectra
Author: Sarah Heim. (Some of which is a port of Corey Olfe's code)
This code was originally taken from the cdip_mobile site.
Spectra
Bases: object
Source code in cdippy/spectra.py
15 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 |
|
__init__()
initializing Spectra. Meant for using methods to create array of Spectrum subClass objects
:ivar specArr: array of Spectrum subClass objects
Source code in cdippy/spectra.py
16 17 18 19 20 21 22 |
|
__str__()
Spectra is an array of Spectrum(s)
Source code in cdippy/spectra.py
28 29 30 |
|
get_bandSize()
returns the size (number of freq/bands) of the spectrum in spectra
Source code in cdippy/spectra.py
40 41 42 43 44 45 |
|
get_spectraNum()
return the number of objects (spectrum) in the specArr
Source code in cdippy/spectra.py
24 25 26 |
|
get_spectraType()
returns the type of Class of the first object in specArr, all should be the same i.e. Spectrum_64band
Source code in cdippy/spectra.py
32 33 34 35 36 37 38 |
|
redist_specArr(objName)
Will redistribute spectrum if necessary (if different type)
:var int objName: name of the subClass to redistribute to. .i.e. Spectrum_9band
Source code in cdippy/spectra.py
120 121 122 123 124 125 126 127 128 |
|
set_spectrumArr_fromQuery(dataDict)
specArr is empty. Create Spectrum objects and put in specArr
:var dataDict: dictionary (output from cdippy.stndata query)
Source code in cdippy/spectra.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
specArr_ToDict()
Output the specArr as a dictionary with keys like waveA1Value, waveEnergyDensity etc.
Source code in cdippy/spectra.py
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 |
|
whichSpecClass(length)
Return the type subClass of Spectrum is appropriate according length passed i.e. Spectrum_64band :var int lenght: length/count of the number of frequencies
Source code in cdippy/spectra.py
47 48 49 50 51 52 53 54 55 56 57 58 |
|
Spectrum
Bases: object
Source code in cdippy/spectra.py
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 |
|
calc_Hs(energy)
returns the square root of energy x 4
Source code in cdippy/spectra.py
214 215 216 |
|
freq_cutoffs()
returns array of tuples of all the (low,high) frequencies; a.k.a.bots/tops
Source code in cdippy/spectra.py
166 167 168 169 170 171 172 173 174 |
|
get_Energy()
units:meters**2 per bandwidth. sum(get_energy) is Total Energy
Source code in cdippy/spectra.py
194 195 196 197 |
|
get_SigWaveHt()
units: meters
Source code in cdippy/spectra.py
199 200 201 202 |
|
ma_to_list(marray)
:var str marray: string name of attribute that contains a masked array
Source code in cdippy/spectra.py
188 189 190 191 192 |
|
peri_cutoffs()
returns array of tuples of all the (low,high) periods
Source code in cdippy/spectra.py
181 182 183 |
|
recip(f)
returns INTEGER of reciprocal of number. Specifically for converting frequency (float) to period(integer)
Source code in cdippy/spectra.py
176 177 178 179 |
|
redistribute_sp(specInstClass)
translation of Corey's redistribute_sp code: c Subroutine that redistributes a spectrum into a new spectral layout.
:var specInstClass: the class to redistribute to can be instance or name of Class
Source code in cdippy/spectra.py
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 |
|
set_FreqBands(num, sz)
Makes array of frequencies :var int num: frequency or bandwith? :var int sz: size, number of bands
Source code in cdippy/spectra.py
156 157 158 159 160 161 162 163 |
|
set_specAtts(query, i)
Set spectra attributes from cdippy.stndata query
:var mArr query: multi-dimentional array returned from cdippy.stndata :var int i: index
Source code in cdippy/spectra.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
total_Hs()
square root of Total Energy x 4
Source code in cdippy/spectra.py
218 219 220 221 |
|
cdippy.stndata
StnData
Bases: CDIPnc
Returns data and metadata for the specified station.
This class merges data from multiple CDIP netCDF files to produce a single dictionary with keys of the requested variables. Each key corresponds to a numpy masked array.
METHODS
get_series(start, end, vrs) Returns data for a station given start date, end date and a list of variables. get_parameters(start, end) Calls get_series with vrs set to parameter variables. get_spectra(start, end) Calls get_series with vrs set to spectrum variables. get_xyz Calls get_series with vrs set to xyz variables. get_stn_meta Returns all station meta variables. get_nc_files Returns a dictionary of all this station's netCDF files. get_target_times Returns a 2-tuple of timestamps, an interval corresponding to n records to the right or left of target_timestamp.
Source code in cdippy/stndata.py
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 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 |
|
__aggregate_dicts(dict1: dict, dict2: dict) -> dict
Returns a dict of data combined from two dictionaries. Dict1 has oldest data. All the other __merge methods end up using this method.
This method also redistributes 100 band spectra to 64 band format if 1) both formats are present in dict1 and dict2 or 2) the force_64bands option is True.
Source code in cdippy/stndata.py
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 |
|
__init__(stn: str, data_dir: str = None, org: str = None, deploy_num: int = None)
PARAMETERS
stn : str Can be in 2, 3 or 5 char format e.g. 28, 028, 028p2 data_dir : str [optional] Either a full path to a directory containing a local directory hierarchy of nc files. E.g. '/project/WNC' or a url to a THREDDS server. org: str (Organization) Values are: cdip|ww3|external deploy_num : int [optional] Supply this to access specific station deployment data. Must be >= 1.
Source code in cdippy/stndata.py
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 |
|
__merge_active_request(nc_class_type: str = 'rt')
Returns data for a given request across active datasets.
When deploy_num is supplied all files (active and archive) are checked for data.
Source code in cdippy/stndata.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
|
__merge_request()
Returns data for given request across realtime and historic files
Source code in cdippy/stndata.py
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
|
__merge_xyz_request()
Merge xyz data from realtime and archive nc files.
Source code in cdippy/stndata.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
|
get_nc_files(types: list = nc_file_types) -> dict
Returns dict of netCDF4 objects of a station's netcdf files
Source code in cdippy/stndata.py
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
|
get_parameters(start: datetime = None, end: datetime = None, pub_set: str = 'public', apply_mask=True, target_records=0) -> dict
Calls get_series to return wave parameters.
Source code in cdippy/stndata.py
165 166 167 168 169 170 171 172 173 174 175 176 |
|
get_series(start: datetime = None, end: datetime = None, vrs: list = None, pub_set: str = None, apply_mask: bool = None, target_records: int = 0, force_64bands: bool = False) -> dict
Returns a dict of data between start and end dates with specified quality.
PARAMETERS
start : str or datetime [optional] : default Jan 1, 1975 Start time of data request (UTC). If provided as a string must be in the format Y-m-d H:M:S where Y is 4 chars and all others are 2 chars. Ex. '2020-03-30 19:32:56'. end : str or datetime [optional] : default now End time of data request (UTC). If not supplied defaults to now. vrs : list [optional] : default ['waveHs'] A list of the names of variables to retrieve. They all must start with the same prefix, e.g. ['waveHs', 'waveTp', 'waveDp'] pub_set: str [optional] values = public|nonpub|all Filters data based on data quality flags. apply_mask: bool [optional] default True Removes values from the masked array that have a mask value of True. Ex. If nonpub data is requested and apply_mask is False, the returned array will contain both public and nonpublic data (although public data records will have the mask value set to True). If apply_mask is set to True, only nonpub records will be returned. target_records: int [optional] If start is specified and end is None, this will specify the number of additional records to return closest to start. force_64bands: bool [optional] For the case in which all spectra returned are mk4 100 band format, force the conversion to 64bands. Mixed formats are always returned in mk3 64 band format.
Source code in cdippy/stndata.py
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 |
|
get_spectra(start: datetime = None, end: datetime = None, pub_set: str = 'public', apply_mask: bool = True, target_records: int = 0, force_64bands: bool = False) -> dict
Calls get_series to return spectral data.
Source code in cdippy/stndata.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
get_stn_meta() -> dict
Returns a dict of station meta data.
Source code in cdippy/stndata.py
153 154 155 156 157 158 159 160 161 162 163 |
|
get_target_timespan(target_timestamp: int, num_target_records: int, time_var: str) -> tuple
Returns a timespan containing the n closest records to the target_timestamp.
PARAMETERS
target_timestamp : int A unix timestamp which is the target time about which the closest n records will be returned. n : int The number of records to return that are closest to the target timestamp. time_var : str The name of the time dimension variable to use. E.g. waveTime.
RETURNS
A 2-tuple of timestamps corresponding to i and i+n (where n may be negative) which will be the timestamps for the n records closest to the target_timestamp.
Source code in cdippy/stndata.py
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 |
|
get_xyz(start: datetime = None, end: datetime = None, pub_set: str = 'public') -> dict
Calls get_series to return displacement data.
Source code in cdippy/stndata.py
178 179 180 181 182 |
|
remove_duplicates(data_dict: dict) -> dict
Duplicate records may exist after merge_ routines. This removes them.
Source code in cdippy/stndata.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
|