NCSource
¶
Classes:
-
NCSource–The NCSource object manages weather data from a generic set of netCDF4 file sources
NCSource
¶
NCSource(
source,
bounds=None,
index_pad=0,
time_name="time",
lat_name="lat",
lon_name="lon",
tz=None,
_max_lon_diff=0.6,
_max_lat_diff=0.6,
verbose=True,
forward_fill=True,
flip_lat=False,
flip_lon=False,
time_offset_minutes=None,
time_index_from=None,
)
Bases: object
The NCSource object manages weather data from a generic set of netCDF4 file sources
If furthermore allows access a number of common functionalities and constants which are often encountered when simulating renewable energy technologies
Note:
Various constants can be set for a given weather source which can impact later simulation workflows. Note that not all weather sources will have all of these constants available. Also more may be implemented besides (so be sure to check the DocString for the source you intend to use).
These constants include:
MAX_LON_DIFFERENCE
The maximum longitude difference to accept between a grid cell and the coordinates you would
like to extract data for
MAX_LAT_DIFFERENCE
The maximum latitude difference to accept between a grid cell and the coordinates you would
like to extract data for
WIND_SPEED_HEIGHT_FOR_WIND_ENERGY
The suggested altitude of wind speed data to use for wind-energy simulations
WIND_SPEED_HEIGHT_FOR_SOLAR_ENERGY
The suggested altitude of wind speed data to use for wind-energy simulations
LONG_RUN_AVERAGE_WINDSPEED
A path to a raster file with the long-time average wind speed in each grid cell
* Can be used in wind energy simulations
* Calculated at the height specified in `WIND_SPEED_HEIGHT_FOR_WIND_ENERGY`
* Time range included in the long run averaging depends on the data source
LONG_RUN_AVERAGE_WINDDIR
A path to a raster file with the long-time average wind direction in each grid cell
* Can be used in wind energy simulations
* Calculated at the height specified in `WIND_SPEED_HEIGHT_FOR_WIND_ENERGY`
* Time range included in the long run averaging depends on the data source
LONG_RUN_AVERAGE_GHI
A path to a raster file with the long-time average global horizontal irradiance
in each grid cell
* Can be used in solar energy simulations
* Calculated at the surface
* Time range included in the long run averaging depends on the data source
LONG_RUN_AVERAGE_DNI
A path to a raster file with the long-time average direct normal irradiance
in each grid cell
* Can be used in solar energy simulations
* Calculated at the surface
* Time range included in the long run averaging depends on the data source
See Also
reskit.weather.MerraSource reskit.weather.SarahSource reskit.weather.Era5Source
Initialize a generic netCDF4 file source
Note:
Generally not intended for normal use. Look into MerraSource, CordexSource, or CosmoSource
Parameters:
-
(path¶str or list of strings) –The path to the main data file(s) to load
If multiple files are given, or if a directory of netCDF4 files is given, then it is assumed that all files ending with the extension '.nc' or '.nc4' should be managed by this object. * Be sure that all the netCDF4 files given share the same time and spatial dimensions!
-
(bounds¶Anything acceptable to geokit.Extent.load(), default:None) –The boundaries of the data which is needed * Usage of this will help with memory management * If None, the full dataset is loaded in memory * The actual extent of the loaded data depends on the source's available data
-
(index_pad¶int, default:0) –The padding to apply to the boundaries * Useful in case of interpolation * Units are in longitudinal degrees
-
(time_name¶str, default:'time') –The name of the time parameter in the netCDF4 dataset
-
(lat_name¶str, default:'lat') –The name of the latitude parameter in the netCDF4 dataset
-
(lon_name¶str, default:'lon') –The name of the longitude parameter in the netCDF4 dataset
-
(tz¶str, default:None) –Applies the indicated timezone onto the time axis * For example, use "GMT" for unadjusted time
-
(verbose¶bool, default:True) –If True, then status outputs are printed when searching for and reading weather data
-
(forward_fill¶bool, default:True) –If True, then missing data in the weather file is forward-filled * Generally, there should be no missing data at all. This option is only intended to catch the rare scenarios where one or two timesteps are missing
-
(flip_lat¶bool, default:False) –If True, flips the latitude dimension when reading weather data from the source * Should only be given if latitudes are given in descending order
-
(flip_lon¶bool, default:False) –If True, flips the longitude dimension when reading weather data from the source * Should only be given if longitudes are given in descending order
-
(time_offset_minutes¶numeric, default:None) –If not none, adds the specific offset in minutes to the timesteps read from the weather file
See Also
MerraSource SarahSource Era5Source
Methods:
-
from_pickle–Load an NCSource source from a pickle file
-
get–Retrieve a time series for a variable from the source's data library at the given location(s)
-
list_standard_variables–Prints the standard variable loaders available to this weather source
-
load–Load a variable into the source's data table
-
loc_to_index–Returns the closest X and Y indexes corresponding to a given location
-
sload–Load standard variables into the source's data library
-
to_pickle–Save the source as a pickle file, so it can be quickly reopened later
-
var_info–Prints more information about the given variable
Source code in reskit/weather/NCSource.py
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 | |
from_pickle
staticmethod
¶
from_pickle(path)
get
¶
get(
variable,
locations,
interpolation="near",
force_as_data_frame=False,
outside_okay=False,
_indices=None,
)
Retrieve a time series for a variable from the source's data library at the given location(s)
Can also use various interpolation schemes (e.g. near, bilinear, or cubic)
Returns:
-
If a single location is given: pandas.Series–- Indexes match to the source's time dimension
-
If multiple locations are given (or if `force_as_data_frame` is True): pandas.DataFrame–- Indexes match to the source's time dimension
- Columns match to the given order of locations
Source code in reskit/weather/NCSource.py
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 886 887 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 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 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 | |
list_standard_variables
¶
load
¶
load(
variable,
name=None,
height_idx=None,
processor=None,
overwrite=False,
)
Load a variable into the source's data table
Parameters:
-
(variable¶str) –The variable within the currated datasources to load * The variable must either be of dimension (time, lat, lon) or (time, height, lat, lon)
-
(name¶str, default:None) –The name to give this variable in the data library * If None, the name of the original variable is kept
-
(height_idx¶int; optional, default:None) –The height index to extract if the original variable has the height dimension
-
(processor¶func, default:None) –A function to process the loaded data before loading it into the the data library * This function must take a single matrix argument with dimensions (time, lat, lon), and must return a matrix of the same shape * Example:If the NC file has temperature in Kelvin and you need C: processor = lambda x: x+273.15
-
(overwrite¶bool, default:False) –If False, then this function will exit early if the desired variable name already exists within the data library. Otherwise, any pre-existing data is overwritten
Returns:
-
None–
See Also
sload( variable ) - For loading standard variables into the weather source using pre-configured calls to 'load'
Source code in reskit/weather/NCSource.py
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 | |
loc_to_index
¶
loc_to_index(loc, outside_okay=False, as_int=True)
Returns the closest X and Y indexes corresponding to a given location or set of locations
Parameters:
-
(loc¶Anything acceptable by geokit.LocationSet) –The location(s) to search for * A single tuple with (lon, lat) is acceptable, or a list of such tuples * A single point geometry (as long as it has an SRS), or a list of geometries is okay * geokit,Location, or geokit.LocationSet are best!
-
(outside_okay¶bool, default:False) –Determines if points which are outside the source's lat/lon grid are allowed * If True, points outside this space will return as None * If False, an error is raised
Returns:
-
If a single location is given: tuple–- Format: (yIndex, xIndex)
- y index can be accessed with '.yi'
- x index can be accessed with '.xi'
-
If multiple locations are given: list–- Format: [ (yIndex1, xIndex1), (yIndex2, xIndex2), ...]
- Order matches the given order of locations
Note:
The default form of this function (which is the one used here) is not very efficient, ultimately leading to much longer look-up than they otherwise need to be. When the weather source has grid cells on a regular lat/lon grid then a more efficient form of this function can be configured using the function generator "_loc_to_index_rect". In these instances, this is the recommended function to use.
For example, if the weather source uses a latitude spacing of 0.5, and a longitude spacing of 0.625, then the function generator can be used like:
> source.loc_to_index = source._loc_to_index_rect(lat_step=0.5, lon_step=0.625)
Source code in reskit/weather/NCSource.py
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 | |
sload
¶
sload(*variables)
Load standard variables into the source's data library
Parameters:
-
(*variables¶str, default:()) –The standard variables to read from the weather source
Returns:
-
None–
Raises:
-
RuntimeError–If the given standard variable name is not known to the weather source
Note:
The names of the standard variable do not refer to the names of the data within the source. Instead, they refer to common plain-english names which are translated to the source- specific names within the associated standard-loader function
You can see which standard loaders are are available for the weather source by seeing the class methods starting with the name "sload_"
Common variable names include:
elevated_wind_speed -> The wind speed at WIND_SPEED_HEIGHT_FOR_WIND_ENERGY
surface_wind_speed -> The wind speed at WIND_SPEED_HEIGHT_FOR_SOLAR_ENERGY
wind_speed_at_Xm -> The wind speed at X meters above the surface
elevated_wind_direction -> The wind direction at WIND_SPEED_HEIGHT_FOR_WIND_ENERGY
surface_wind_direction -> The wind direction at WIND_SPEED_HEIGHT_FOR_SOLAR_ENERGY
wind_direction_at_Xm -> The wind direction at X meters above the surface
surface_pressure -> The pressure at the surface
surface_air_temperature -> The air temperature at the surface
surface_dew_temperature -> The dew-point temperature at the surface
global_horizontal_irradiance -> The global horizontal irradiance at the surface
direct_normal_irradiance -> The direct normal irradiance at the surface
direct_horzontal_irradiance -> The direct irradiance at the surface on a horizontal plane
See Also
NCSource.load( variable, name, height_index, processor ) - For more configurable data loading into the weather source
Source code in reskit/weather/NCSource.py
to_pickle
¶
to_pickle(path)
Save the source as a pickle file, so it can be quickly reopened later
Parameters:
-
(path¶str) –The path to write the output file at
Returns:
-
None–
Source code in reskit/weather/NCSource.py
var_info
¶
var_info(var)
Prints more information about the given variable
Parameters:
-
(var¶str) –The variable to get more information about
Returns:
-
None–
Note:
You can access a list of all available variables by printing the member ".variables"