Skip to content

fix: enable proper running of backward dispersion models#82

Open
AlFontal wants to merge 4 commits intorich-iannone:mainfrom
AlFontal:fix-backward-dispersion
Open

fix: enable proper running of backward dispersion models#82
AlFontal wants to merge 4 commits intorich-iannone:mainfrom
AlFontal:fix-backward-dispersion

Conversation

@AlFontal
Copy link

@AlFontal AlFontal commented Aug 17, 2023

This addresses #81, and also could be considered to address #66.

Basically, there were 2 really small errors that made the logic of running backwards dispersion models not work.

For starters, the run_model function has a hardcoded 'forward' parameter, so no matter the direction specified in add_dispersion_params, the hysplit_dispersion function always received 'forward' as the parameter. This is fixed
in commit caead2f.

Second, the add_dispersion_params function has no duration parameter. The value of duration that is passed onto hysplit_dispersion is computed by the difference in hours between start_time and end_time:

duration <- as.numeric(difftime(model$end_time, model$start_time, units = "hours"))

In a backwards model, the end_time is before the start_time, so this variable takes negative values.

When writing the CONTROL file, however, there is an ifelse clause that prepends a '-' to the duration value. In the case of an already negative value, this writes a line with --duration, leading to a faulty CONTROL file that HYSPLIT doesn't accept and it just doesn't run. Removing the ifelse clause seems to work and is what I did in d4ca419.

It would be also nice to add some examples on how to run backward dispersion models, as there is none as of now.

I think that without this PR, a hacky way of running backward dispersion models is to simply use an end_time that is earlier than the start_time by as many hours as is desired, and then simply input forward in the direction parameter. This will write a negative duration value to the CONTROL file and HYSPLIT will read it and run it in backward mode anyway.

I am rather unfamiliar on R package development as I am mainly a python developer, so I am pretty sure this PR might need several extra steps to make it workable.

The duration is computed as the difference between the start and end
times. If the start time is after the end time, the duration is already
negative, so we don't need to prepend a "-" to it or we have a double
negative before the duration value and HYSPLIT crashes.
@AlFontal AlFontal marked this pull request as ready for review August 17, 2023 10:08
@AlFontal AlFontal changed the title fix: remove hardcoded direction param in run_model fix: enable proper running of backward dispersion models Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant