-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DM-13507: Add SHA1 hash interface to SkyMap. #13
Conversation
19a7f18
to
e1885f4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks okay to me although, given the discussion, I actually expected this to be using __hash__
to define uniqueness of skymaps, and possibly internally hash()
. Are you not doing this because you explicitly need SHA1 to work and skymaps are not readonly?
python/lsst/skymap/baseSkyMap.py
Outdated
self.config.patchBorder, | ||
self.config.tractOverlap, | ||
self.config.pixelScale, | ||
bytes(str(self.config.projection), encoding='latin1'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why latin1 here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These strings are required by the config to be one of a few 3-letter FITS WCS projection names, so I know latin1
is sufficient for representing - until FITS supports unicode in headers, that is :-)
That said, I don't actually know whether knowing it's sufficient means I should use it over something else. I suspect it just doesn't matter, but I'd love to get any feedback you have on that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect ascii for a projection code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turns out this doesn't work anyway, because bytes()
doesn't take an encoding
argument in Python 2 (because it's just str()
). I've switched to just using future.utils.tobytes
instead, which I think just uses latin1
under the hood.
|
Can't we still set |
Maybe the SHA1 calculation is too slow for us to reuse it for |
Yeah, I had thought through not using I also think that if I implement |
would it work to define |
Yeah, I think that's probably a good idea, and it'd be easy to implement |
Two new commits: SHA1 values are now computed on first use and then cached, and I've implemented |
python/lsst/skymap/baseSkyMap.py
Outdated
@@ -166,6 +170,18 @@ def __iter__(self): | |||
def __len__(self): | |||
return len(self._tractInfoList) | |||
|
|||
def __hash__(self): | |||
return hash(self._sha1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and below shouldn't it be getSha1()
that is called. Otherwise how do you know it's been cached?
tests/helper/skyMapTestCase.py
Outdated
for tractOverlap in (0.0, 0.01, 0.1): # degrees | ||
config = self.getConfig() | ||
config.tractOverlap = tractOverlap | ||
skyMap = self.getSkyMap(config) | ||
for tractInfo in skyMap: | ||
self.assertAlmostEqual(tractInfo.getTractOverlap().asDegrees(), tractOverlap) | ||
self.assertEqual(len(skyMap), self._NumTracts) | ||
self.assertNotEqual(skyMap.getSha1(), defaultSkyMap.getSha1()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For at least some of these tests, can we now switch them to using the __eq__
implementation?
aa04d07
to
82f079b
Compare
This comes with a doc note that SkyMaps must be conceptually immutable, which all current classes already are.
67d631b
to
0b1f20d
Compare
No description provided.