dartwrf.obs package

Submodules

dartwrf.obs.calculate_obs_locations module

The functions in here create obs_seq.in files. These are the template files defining obs locations and metadata according to which observations are generated and subsequently assimilated.

dartwrf.obs.calculate_obs_locations.evenly_on_grid(f_geo_em_nature: str, km_between_obs, skip_border_km=0)

Observations spread evenly over domain

skip_border_km : no observations within this distance to the border

Returns

tuple of (lat, lon) coordinates of observed gridpoints in degrees

dartwrf.obs.calculate_obs_locations.square_array_from_domaincenter(n_obs, distance_between_obs_km)

Create equally spaced grid for satellite observations every 4 km e.g. ny,nx = 10 -> obs locations are from -5 to +5 times dy in south_north direction and from -5 to +5 times dx in west_east direction

Returns

tuple of (lat, lon) coordinates

dartwrf.obs.create_obsseq_in module

The functions in here create obs_seq.in files. These are the template files defining obs locations and metadata according to which observations are generated and subsequently assimilated.

dartwrf.obs.create_obsseq_in.create_obs_seq_in(cfg: Config, output_path='./obs_seq.in')

Create obs_seq.in with multiple obs types in one file

Parameters:
  • time_dt (dt.datetime) – time of observation

  • list_obscfg (list of dict) – configuration for observation types

Note

list_obscfg must have these keys:
  • n_obs (int) : number of observations (must be a square of an integer: 4, 9, 1000, …)

  • obs_locations (str or tuple) in [‘square_array_from_domaincenter’, ‘square_array_evenly_on_grid’, ]

    or list of (lat, lon) coordinate tuples, in degrees north/east

  • error_generate (np.array)

  • error_assimilate (np.array or False) : False -> parameterized

  • cov_loc_radius_km (float)

dartwrf.obs.create_obsseq_in.degr_to_rad(degr)

Convert to DART convention (radians) 2*pi = 360 degrees

Parameters:

degr (float) – degrees east of Greenwich

Returns

float

dartwrf.obs.create_obsseq_in.get_dart_date(time_dt)

Convert datetime.datetime into DART time format

Assumes that input is UTC!

Returns

str, str

dartwrf.obs.create_obsseq_in.preamble(n_obs_3d_total, list_kinds, obs_kind_nrs)

Writes the header of an obs_seq.out file

dartwrf.obs.create_obsseq_in.round_to_day(dtobj)

Overwrite hours, minutes, seconds to 0 :param dtobj: :type dtobj: dt.datetime

dartwrf.obs.create_obsseq_in.write_sat_angle_appendix(sat_channel, lat0, lon0, time_dt)

Writes metadata str for an observation inside obs_seq.out

Parameters:
  • sat_channel (int or False) – False if not a satellite observation

  • lat0 (float) – latitude of point on earth

  • lon0 (float) – longitude of point on earth

  • time_dt (dt.datetime) – time of observation

Returns:

str

dartwrf.obs.create_obsseq_in.write_section(obs, last=False)

Returns the str of one observation inside an obs_seq.out file

Parameters:
  • obs (object) –

  • last (bool) – True if this is the last observation in the obs_seq file

Returns:

str

dartwrf.obs.create_obsseq_out module

dartwrf.obs.create_obsseq_out.generate_new_obsseq_out(cfg: Config)

Generate an obs_seq.out file from obs_seq.in Expects an existing nature file in the cluster.dart_rundir.

Note

Combining precomputed FO with regular observations is not supported!

Parameters:
  • time (datetime) – time of the observations

  • nproc (int, optional) – number of cores for call to ./perfect_model_obs

Returns:

obs_seq.out representation

Return type:

obsseq.ObsSeq

dartwrf.obs.create_obsseq_out.prepare_nature_dart(cfg: Config)

Prepares DART nature (wrfout_d01) if available

Parameters:

time (dt.datetime) – Time at which observations will be made

dartwrf.obs.create_obsseq_out.run_perfect_model_obs(cfg: Config)

Run the ./perfect_model_obs program

Parameters:

nproc (int) – number of processors to use

Returns:

None, creates obs_seq.out

dartwrf.obs.error_models module

dartwrf.obs.error_models.calc_obserr_WV(channel, Hx_nature, Hx_prior)

Calculate parametrized error (for assimilation)

Parameters:
  • channel (str) – satellite channel

  • Hx_nature (np.array) – H(x_nature) with dimension (observations)

  • Hx_prior (np.array) – H(x_prior) with dimension (ensemble_members, observations)

Returns

np.array Observation error std-deviation with dimension (observations)

dartwrf.obs.obsseq module

Read, modify and save DART obs_seq.out/obs_seq.final files in DART format.

Examples

Load an obs seq file with >>> from dartwrf.obs.obsseq import ObsSeq >>> osf = ObsSeq(‘path/to/obs_seq.final’)

osf.df is a pandas.DataFrame with all observations as rows. Its keys are: e.g. ‘observations’, ‘truth’, ‘prior ensemble mean’, ‘prior ensemble spread’, ‘Quality Control’, ‘obdef’, ‘loc3d’, ‘kind’, ‘metadata’, ‘time’, ‘variance’

To get arrays of prior and posterior use >>> osf.df.get_prior_Hx() >>> osf.df.get_posterior_Hx()

After modifying the contents, write them in DART format >>> osf.to_dart(‘path/to/obs_seq.final’)

Note

Can not create obs_seq from scratch, since it does not know which metadata is necessary for each observation type

class dartwrf.obs.obsseq.ObsRecord(*args: Any, **kwargs: Any)

Bases: DataFrame

Basically a pd.DataFrame with additional methods

get_lon_lat()

Retrieve longitude and latitude of observations

Returns:

pd.DataFrame (n_obs, 2)

get_model_grid_indices(wrf_file_with_grid)

Retrieve the grid indices closest to the observations

Note

Only the horizontal grid is considered

Parameters:

wrf_file_with_grid (str) – path to wrf file with grid information

Returns:

i, j

Return type:

pd.DataFrame (n_obs, 2) columns

get_posterior_Hx()

Retrieve H(x_posterior) for all ensemble members

Returns:

np.array (n_obs, ensemble_size)

get_prior_Hx()

Retrieve H(x_prior) for all ensemble members

Returns:

np.array (n_obs, ensemble_size)

get_truth_Hx()

Retrieve H(x_truth)

Returns:

np.array (n_obs,)

superob(window_km)

Create super-observations (averaged observations)

Note

This routine discards observations (round off) e.g. 31 obs with 5 obs-window => obs #31 is not processed.

Metadata is copied from the first observation in a superob-box

The location (loc3d) of new observation is taken from the center observation

TODO: allow different obs types (KIND)

Parameters:

window_km (numeric) – horizontal window edge length includes obs on edge 25x25 km with 5 km obs density = average 5 x 5 observations

Returns:

ObsRecord

class dartwrf.obs.obsseq.ObsSeq(filepath)

Bases: object

Read, manipulate, save obs_seq.out / final files

append_obsseq(list_of_obsseq)

Append a list of ObsSeq objects

Parameters:

list_of_obsseq (list of ObsSeq()) –

Example

Combine two ObsSeq() objects >>> oso1 = ObsSeq(‘path/to/obs_seq.out1’) >>> oso2 = ObsSeq(‘path/to/obs_seq.out2’) >>> oso_combi = oso1.append_obsseq([oso2,])

Returns:

ObsSeq() with combined data

plot(f_out='./map_obs_superobs.png')
remove_obs_of_type(kind_str=False, kind=False)

Remove all observations of a certain type

Parameters:
  • kind_str (str) – observation type as string

  • kind (int) – observation type as integer

Returns:

self

to_dart(f)

Write to obs_seq.out file in DART format

Parameters:

f (str) – path of file to write

to_pandas()

Create pd.DataFrame with rows=observations

Module contents