Skip to content

Commit 1d13ef2

Browse files
committed
Update README and improve code formatting in data model
- Clarified README to specify the contents of the low-volume data folder. - Enhanced formatting in data_model.py for better readability. - Added detailed docstrings for RelativeHumidity and DewPoint classes in merra.py, including references.
1 parent e6be3d6 commit 1d13ef2

File tree

3 files changed

+47
-20
lines changed

3 files changed

+47
-20
lines changed

nsrdb/data_model/data/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# NSRDB Supporting Data
2-
This folder holds some low-volume data to support the NSRDB data model.
3-
All of the real full-volume source data is stored on HPC in /projects/pxs/.
4-
The data saved here is just metadata and other minor supplemental information.
2+
This folder holds some low-volume data to support the NSRDB data model. The
3+
txt files contain climatological correction factors for alpha and aod which
4+
are used to correct for systemic biases in MERRA2 data.

nsrdb/data_model/data_model.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class DataModel:
7070
CACHE_DIR = '/projects/pxs/reference_grids/_nn_query_cache'
7171

7272
# source files for weight factors
73+
7374
WEIGHTS: ClassVar = {
7475
'aod': os.path.join(
7576
DATADIR, 'Monthly_pixel_correction_MERRA2_AOD.txt'
@@ -230,8 +231,9 @@ def _parse_nsrdb_grid(
230231
self._nsrdb_grid = clean_meta(pd.read_csv(inp, index_col=0))
231232
else:
232233
raise TypeError(
233-
'Expected csv grid file or DataFrame but '
234-
'received: {}'.format(inp)
234+
'Expected csv grid file or DataFrame but received: {}'.format(
235+
inp
236+
)
235237
)
236238

237239
# check requirements
@@ -473,7 +475,7 @@ def get_cloud_nn(fp_cloud, cloud_kwargs, nsrdb_grid, dist_lim=1.0):
473475
try:
474476
grid = cloud_obj_single.grid
475477
except Exception as e:
476-
msg = 'Exception building cloud NN ' 'tree for {}: {}'.format(
478+
msg = 'Exception building cloud NN tree for {}: {}'.format(
477479
cloud_obj_single, e
478480
)
479481
logger.error(msg)
@@ -1244,12 +1246,11 @@ def _process_clouds(self, cloud_vars, dist_lim=1.0, max_workers=None):
12441246
cloud_data[var] = self.scale_data(var, arr)
12451247

12461248
logger.info(
1247-
'Finished extracting cloud data ' 'and writing to NSRDB arrays.'
1249+
'Finished extracting cloud data and writing to NSRDB arrays.'
12481250
)
12491251
mem = psutil.virtual_memory()
12501252
logger.info(
1251-
'Current memory usage is '
1252-
'{:.3f} GB out of {:.3f} GB total.'.format(
1253+
'Current memory usage is {:.3f} GB out of {:.3f} GB total.'.format(
12531254
mem.used / 1e9, mem.total / 1e9
12541255
)
12551256
)
@@ -1412,8 +1413,9 @@ def _interpolate(self, var):
14121413

14131414
# run spatial interpolation
14141415
logger.debug(
1415-
'Performing spatial interpolation on "{}" ' 'with shape {}'.format(
1416-
var, data.shape
1416+
'Performing spatial interpolation on "{}" with method "{}", '
1417+
'metric "{}", and with shape {}'.format(
1418+
var, var_obj.spatial_method, var_obj.NN_METHOD, data.shape
14171419
)
14181420
)
14191421
data = spatial_interp(
@@ -1893,7 +1895,7 @@ def run_single(
18931895
data = method(var, **kwargs)
18941896
except Exception as e:
18951897
logger.exception(
1896-
'Processing method "DataModel.{}()" failed for ' '"{}"'.format(
1898+
'Processing method "DataModel.{}()" failed for "{}"'.format(
18971899
method.__name__, var
18981900
)
18991901
)
@@ -2141,8 +2143,9 @@ def run_multiple(
21412143
)
21422144
else:
21432145
raise TypeError(
2144-
'Expected csv grid file or DataFrame but '
2145-
'received: {}'.format(nsrdb_grid)
2146+
'Expected csv grid file or DataFrame but received: {}'.format(
2147+
nsrdb_grid
2148+
)
21462149
)
21472150

21482151
logger.debug(

nsrdb/data_model/merra.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,10 @@ def grid(self):
277277
with NSRDBfs(self.file) as f:
278278
lon2d, lat2d = np.meshgrid(f['lon'][:], f['lat'][:])
279279

280-
self._grid = pd.DataFrame(
281-
{'longitude': lon2d.ravel(), 'latitude': lat2d.ravel()}
282-
)
280+
self._grid = pd.DataFrame({
281+
'longitude': lon2d.ravel(),
282+
'latitude': lat2d.ravel(),
283+
})
283284

284285
# merra grid has some bad values around 0 lat/lon
285286
# quick fix is to set to zero
@@ -310,7 +311,21 @@ def grid(self):
310311

311312

312313
class RelativeHumidity(BaseDerivedVar):
313-
"""Class to derive the relative humidity from other MERRA2 vars."""
314+
"""Class to derive the relative humidity from other MERRA2 vars. This is
315+
derived as the ratio of mixing ratio to saturation mixing ratio, times 100.
316+
Intermediate calculations are done to get saturation vapor pressure,
317+
mixing ratio, and saturation mixing ratio. Saturation vapor pressure is
318+
calculated using the Tetens formula. Mixing ratio is calculated from
319+
specific humidity. Saturation mixing ratio is calculated from saturation
320+
vapor pressure.
321+
322+
References
323+
----------
324+
.. https://www.conservationphysics.org/atmcalc/atmoclc2.pdf
325+
.. http://snowball.millersville.edu/~adecaria/ESCI241/esci241_lesson06_humidity.pdf
326+
.. https://www.weather.gov/media/epz/wxcalc/mixingRatio.pdf
327+
328+
"""
314329

315330
DEPENDENCIES = ('air_temperature', 'specific_humidity', 'surface_pressure')
316331

@@ -383,7 +398,16 @@ def derive(air_temperature, specific_humidity, surface_pressure):
383398

384399

385400
class DewPoint(BaseDerivedVar):
386-
"""Class to derive the dew point from other MERRA2 vars."""
401+
"""Class to derive the dew point from other MERRA2 vars. The dew point is
402+
derived from air temperature, specific humidity, and surface pressure.
403+
Relative humidity is first derived from these variables, then the dew
404+
point is calculated from temperature and relative humidity using the
405+
Magnus formula.
406+
407+
References
408+
----------
409+
.. https://journals.ametsoc.org/view/journals/bams/86/2/bams-86-2-225.xml?tab_body=pdf
410+
"""
387411

388412
DEPENDENCIES = ('air_temperature', 'specific_humidity', 'surface_pressure')
389413

@@ -406,7 +430,7 @@ def derive(air_temperature, specific_humidity, surface_pressure):
406430
Dew point in Celsius.
407431
"""
408432
logger.info(
409-
'Deriving Dew Point from temperature, ' 'humidity, and pressure'
433+
'Deriving Dew Point from temperature, humidity, and pressure'
410434
)
411435

412436
# ensure that Temperature is in C (scale from Kelvin if not)

0 commit comments

Comments
 (0)