SCECcode / pycsep

Tools to help earthquake forecast model developers build and evaluate their forecasts
https://docs.cseptesting.org
BSD 3-Clause "New" or "Revised" License
47 stars 22 forks source link

Error loading historical catalog #223

Closed allenos-usgs closed 1 year ago

allenos-usgs commented 1 year ago

I've been having problems loading in a csv catalog that goes back to the year 1700.

I've been loading it in like so: image

Then I get the following traceback: image

I think I've traced the issue to this function in time_utils.py, which seems to have a baseline of 1970: image

Because if I trim my test catalog so that it starts in 1970 instead of 1700, then it's able to be loaded in no problem. And if I go back to using the entire catalog, but in the function I change 1970 to 1700, then I get the following: image

It loads in the entire catalog, but now it seems to think it starts in 1970 and ends ~270 years in the future. Any help with getting it to read in the entire catalog with the correct years would be much appreciated!

Thanks, Andrea

wsavran commented 1 year ago

thanks @allenos-usgs. I'll look into this next week and see what the issue is loading historical catalogs.

wsavran commented 1 year ago

@allenos-usgs can you upload the catalog that you are having this problem with. @pabloitu tested this out inline and the epoch times just returned negative numbers. this was done in-line, so it might have something to do with the reader. in the mean time I will create a test catalog and try and reproduce.

allenos-usgs commented 1 year ago

Sure thing, here's the catalog. csep_test_cat2.csv

pabloitu commented 1 year ago

Hi @allenos-usgs Sorry for the delay. I've checked the issue and can't reproduce the error in the latest version or the pycsep conda version.

image

The issue has to do with windows handling datetimes different than osx or unix (e.g. https://github.com/python/cpython/issues/82414) , which does not support negative timestamps.

We need to set up a bypass in our csep time functions for windows users. Thank you for catching this error!

p.s. In the meantime, I'm attaching your catalog in JSON version csep_test_cat2.zip, which has the timestamps instead of datetimes. It can be loaded as

import csep
catalog = csep.core.catalogs.CSEPCatalog.load_json('csep_test_cat2.json')
allenos-usgs commented 1 year ago

Hi @pabloitu , thanks for looking into it. I tried to work with the JSON version of the catalog that you sent, but I seem to be having a similar sort of problem when I try to load the catalog. Here's the traceback: image

Perhaps the same sort of windows issue?

pabloitu commented 1 year ago

yes, was the same bug :(! but fixed it in #230 , we need a short review and try to commit to main as quick as possible.

fabiolsilva commented 1 year ago

This should now be fixed, with latest merge of #230 into the main branch.