Skip to content

Added write method to _Config class.#85

Open
krisvanneste wants to merge 5 commits intoSeismicSource:v2-rebase-mainfrom
krisvanneste:v2-write_config
Open

Added write method to _Config class.#85
krisvanneste wants to merge 5 commits intoSeismicSource:v2-rebase-mainfrom
krisvanneste:v2-write_config

Conversation

@krisvanneste
Copy link
Collaborator

Claudio,

I think it would be handy to save the configuration made in an interactive session, so I added a write method to the _Config class. Can you check it?

@krisvanneste
Copy link
Collaborator Author

Claudio,
I'm making a new notebook using one of the examples in sourcespec_testruns.
I'm using test_CDSA as an example.
First, I updated sourcespec.conf to sourcespec2.
I then read the configuration file interactively, along with the trace data, quakeml data and inventory. However, when I start the inversion, this results in the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[13], line 2
      1 config.options.outdir = None
----> 2 result = ssp_run(st, inventory, event, picks)

File E:\Home\_kris\Python\cloned_repos\sourcespec2\sourcespec2\source_spec.py:110, in ssp_run(st, inventory, ssp_event, picks, allow_exit)
    108 print('Augmenting event')
    109 augment_event(ssp_event)
--> 110 print(ssp_event.hypocenter.vp)
    111 augment_traces(st, inventory, ssp_event, picks)
    113 # Deconvolve, filter, cut traces:

AttributeError: 'SSPHypocenter' object has no attribute 'vp'

Investigating this issue, I discover that this is because vp_source and similar parameters are strings, which results in a silent error in the _hypo_vel function.
It turns out I should have ran a validation of the config object after reading the file.
However, when I do this, I get a new error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[4], line 2
      1 cfg_file = os.path.join(run_folder, 'source_spec.conf')
----> 2 config.read(cfg_file)
      3 config.running_from_command_line = False

File E:\Home\_kris\Python\cloned_repos\sourcespec2\sourcespec2\setup\config.py:638, in _Config.read(self, config_file)
    636 config_obj = read_config_file(config_file)
    637 self.update(config_obj.dict())
--> 638 self.validate()

File E:\Home\_kris\Python\cloned_repos\sourcespec2\sourcespec2\setup\config.py:365, in _Config.validate(self)
    363     for entry in [e for e in test if not test[e]]:
    364         msg += f'\nInvalid value for "{entry}": "{config_obj[entry]}"'
--> 365     raise ValueError(msg)
    366 if not test:
    367     raise ValueError('No configuration value present!')

ValueError: 
Invalid value for "mis_oriented_channels": "Z, 1, 2"
Invalid value for "epi_dist_ranges": "0.0, 300.0"
Invalid value for "spectral_sn_freq_range": "0.1, 2.0"
Invalid value for "t_star_min_max": "0.0, 0.1"
Invalid value for "Er_freq_range": "noise, noise"

I don't understand this one. The values for these parameters seem to be in agreement with the specs.
Any ideas?

Here is the configuration file:
source_spec.conf.txt

@krisvanneste
Copy link
Collaborator Author

OK, I solved it by splitting strings containing lists into string lists before validating.
Maybe I'm missing something, but this should probably be done in setup.configobj_helpers.read_config_file.

@claudiodsf
Copy link
Member

Thanks Kris, I fixed a problem which prevented running tests on pull requests against v2 and force-pushed.

Will come back later today, when the tests are done (and hopefully pass) 😉

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.

2 participants